-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
742 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
name = "MeasureBase" | ||
uuid = "fa1605e6-acd5-459c-a1e6-7e635759db14" | ||
authors = ["Chad Scherrer <[email protected]> and contributors"] | ||
version = "0.10.0" | ||
version = "0.11.0" | ||
|
||
[deps] | ||
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" | ||
ChangesOfVariables = "9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0" | ||
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" | ||
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9" | ||
DensityInterface = "b429d917-457f-4dbc-8f4c-0cc954292b1d" | ||
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b" | ||
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173" | ||
InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112" | ||
IrrationalConstants = "92d709cd-6900-40b7-9082-c6be49f344b6" | ||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" | ||
LogExpFunctions = "2ab3a3ac-af41-5b50-aa03-7779005ae688" | ||
|
@@ -24,11 +27,14 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" | |
Tricks = "410a4b4d-49e4-4fbc-ab6d-cb71b17b3775" | ||
|
||
[compat] | ||
ChainRulesCore = "1" | ||
ChangesOfVariables = "0.1.3" | ||
Compat = "3.35, 4" | ||
ConstructionBase = "1.3" | ||
DensityInterface = "0.4" | ||
FillArrays = "0.12, 0.13" | ||
IfElse = "0.1" | ||
InverseFunctions = "0.1.7" | ||
IrrationalConstants = "0.1" | ||
LogExpFunctions = "0.3" | ||
LogarithmicNumbers = "1" | ||
|
@@ -42,6 +48,7 @@ julia = "1.3" | |
|
||
[extras] | ||
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595" | ||
ChainRulesTestUtils = "cdddcdb0-9152-4a09-a978-84456f9df70a" | ||
|
||
[targets] | ||
test = ["Aqua"] | ||
test = ["Aqua", "ChainRulesTestUtils"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
""" | ||
MeasureBase.NoDOF{MU} | ||
Indicates that there is no way to compute degrees of freedom of a measure | ||
of type `MU` with the given information, e.g. because the DOF are not | ||
a global property of the measure. | ||
""" | ||
struct NoDOF{MU} end | ||
|
||
|
||
""" | ||
getdof(μ) | ||
Returns the effective number of degrees of freedom of variates of | ||
measure `μ`. | ||
The effective NDOF my differ from the length of the variates. For example, | ||
the effective NDOF for a Dirichlet distribution with variates of length `n` | ||
is `n - 1`. | ||
Also see [`check_dof`](@ref). | ||
""" | ||
function getdof end | ||
|
||
# Prevent infinite recursion: | ||
@inline _default_getdof(::Type{MU}, ::MU) where MU = NoDOF{MU} | ||
@inline _default_getdof(::Type{MU}, mu_base) where MU = getdof(mu_base) | ||
|
||
@inline getdof(μ::MU) where MU = _default_getdof(MU, basemeasure(μ)) | ||
|
||
|
||
""" | ||
MeasureBase.check_dof(ν, μ)::Nothing | ||
Check if `ν` and `μ` have the same effective number of degrees of freedom | ||
according to [`MeasureBase.getdof`](@ref). | ||
""" | ||
function check_dof end | ||
|
||
function check_dof(ν, μ) | ||
n_ν = getdof(ν) | ||
n_μ = getdof(μ) | ||
if n_ν != n_μ | ||
throw(ArgumentError("Measure ν of type $(nameof(typeof(ν))) has $(n_ν) DOF but μ of type $(nameof(typeof(μ))) has $(n_μ) DOF")) | ||
end | ||
return nothing | ||
end | ||
|
||
_check_dof_pullback(ΔΩ) = NoTangent(), NoTangent(), NoTangent() | ||
ChainRulesCore.rrule(::typeof(check_dof), ν, μ) = check_dof(ν, μ), _check_dof_pullback | ||
|
||
|
||
""" | ||
MeasureBase.NoVarCheck{MU,T} | ||
Indicates that there is no way to check of a values of type `T` are | ||
variate of measures of type `MU`. | ||
""" | ||
struct NoVarCheck{MU,T} end | ||
|
||
|
||
""" | ||
MeasureBase.checked_var(μ::MU, x::T)::T | ||
Return `x` if `x` is a valid variate of `μ`, throw an `ArgumentError` if not, | ||
return `NoVarCheck{MU,T}()` if not check can be performed. | ||
""" | ||
function checked_var end | ||
|
||
# Prevent infinite recursion: | ||
@propagate_inbounds _default_checked_var(::Type{MU}, ::MU, ::T) where {MU,T} = NoVarCheck{MU,T} | ||
@propagate_inbounds _default_checked_var(::Type{MU}, mu_base, x) where MU = checked_var(mu_base, x) | ||
|
||
@propagate_inbounds checked_var(mu::MU, x) where MU = _default_checked_var(MU, basemeasure(mu), x) | ||
|
||
_checked_var_pullback(ΔΩ) = NoTangent(), NoTangent(), ΔΩ | ||
ChainRulesCore.rrule(::typeof(checked_var), ν, x) = checked_var(ν, x), _checked_var_pullback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
""" | ||
inssupport(m, x) | ||
insupport(m) | ||
`insupport(m,x)` computes whether `x` is in the support of `m`. | ||
`insupport(m)` returns a function, and satisfies | ||
insupport(m)(x) == insupport(m, x) | ||
""" | ||
function insupport end | ||
|
||
|
||
""" | ||
MeasureBase.require_insupport(μ, x)::Nothing | ||
Checks if `x` is in the support of distribution/measure `μ`, throws an | ||
`ArgumentError` if not. | ||
""" | ||
function require_insupport end | ||
|
||
_require_insupport_pullback(ΔΩ) = NoTangent(), ZeroTangent() | ||
function ChainRulesCore.rrule(::typeof(require_insupport), μ, x) | ||
return require_insupport(μ, x), _require_insupport_pullback | ||
end | ||
|
||
function require_insupport(μ, x) | ||
if !insupport(μ, x) | ||
throw(ArgumentError("x is not within the support of μ")) | ||
end | ||
return nothing | ||
end |
Oops, something went wrong.
648376d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
648376d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/62671
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: