Skip to content

Commit

Permalink
Testvalue (#208)
Browse files Browse the repository at this point in the history
* minor reformatting

* require MeasureBase 0.10

* fix OrthoLebesgue

* IfElse

* bump version
  • Loading branch information
cscherrer authored Jun 15, 2022
1 parent ee201c9 commit 8055b52
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MeasureTheory"
uuid = "eadaa1a4-d27c-401d-8699-e962e1bbc33b"
authors = ["Chad Scherrer <[email protected]> and contributors"]
version = "0.16.2"
version = "0.16.3"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down Expand Up @@ -57,7 +57,7 @@ LogExpFunctions = "0.3.3"
MLStyle = "0.4"
MacroTools = "0.5"
MappedArrays = "0.4"
MeasureBase = "0.9"
MeasureBase = "0.10"
NamedTupleTools = "0.13, 0.14"
NestedTuples = "0.3"
PositiveFactorizations = "0.2"
Expand Down
14 changes: 13 additions & 1 deletion src/combinators/affine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,20 @@ struct OrthoLebesgue{N,T} <: PrimitiveMeasure
OrthoLebesgue(nt::NamedTuple{N,T}) where {N,T} = new{N,T}(nt)
end

params(d::OrthoLebesgue) = getfield(d, :par)

Base.getproperty(d::OrthoLebesgue, s::Symbol) = getproperty(params(d), s)
Base.propertynames(d::OrthoLebesgue) = propertynames(params(d))

testvalue(d::OrthoLebesgue{(:μ, :σ)}) = d.μ
testvalue(d::OrthoLebesgue{(:μ, :λ)}) = d.μ
testvalue(d::OrthoLebesgue{(:μ,)}) = d.μ

testvalue(d::OrthoLebesgue{(:σ,)}) = zeros(size(d.σ, 1))
testvalue(d::OrthoLebesgue{(:λ,)}) = zeros(size(d.λ, 2))

function insupport(d::OrthoLebesgue, x)
f = AffineTransform(d.par)
f = AffineTransform(params(d))
finv = inverse(f)
z = finv(x)
f(z) x
Expand Down
20 changes: 13 additions & 7 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ using FillArrays
using MeasureTheory
using MeasureBase.Interface
using MeasureTheory: kernel

using Aqua
using IfElse
Aqua.test_all(MeasureTheory; ambiguities = false, unbound_args = false)

function draw2(μ)
Expand Down Expand Up @@ -611,10 +611,16 @@ end
@testset "IfElseMeasure" begin
p = rand()
x = randn()
@test logdensityof(MeasureTheory.IfElse.ifelse(Bernoulli(p), Normal(), Normal()), x)
logdensityof(Normal(), x)
@test logdensityof(
MeasureTheory.IfElse.ifelse(Bernoulli(p), Normal(2, 3), Normal()),
x,
) logdensityof(p * Normal(2, 3) + (1 - p) * Normal(), x)

@test let
a = logdensityof(IfElse.ifelse(Bernoulli(p), Normal(), Normal()), x)
b = logdensityof(Normal(), x)
a b
end

@test let
a = logdensityof(IfElse.ifelse(Bernoulli(p), Normal(2, 3), Normal()), x)
b = logdensityof(p * Normal(2, 3) + (1 - p) * Normal(), x)
a b
end
end

2 comments on commit 8055b52

@cscherrer
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

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/62430

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:

git tag -a v0.16.3 -m "<description of version>" 8055b523ae9e9680629bb36d959e74dd81695af4
git push origin v0.16.3

Please sign in to comment.