-
Notifications
You must be signed in to change notification settings - Fork 15
add PosDefCholeskyFactor #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
U[row, col] = x[index] | ||
index += 1 | ||
end | ||
if flag isa NoLogJac |
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.
You could avoid code duplication here by using transform_with(flag, ...)
. When flag::NoLogJac
, it is "summed" automatically as a no-op.
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.
transform_with
doesn't seem to work for scalar transforms with scalar args:
julia> TransformVariables.transform_with(TransformVariables.NoLogJac(), asℝ₊, 1.0)
ERROR: MethodError: no method matching transform_with(::TransformVariables.NoLogJac, ::TransformVariables.ShiftedExp{true,Float64}, ::Float64)
Closest candidates are:
transform_with(::TransformVariables.NoLogJac, ::TransformVariables.ScalarTransform, ::AbstractArray{T,1} where T<:Real) at /Users/simon/.julia/dev/TransformVariables/src/scalar.jl:15
transform_with(::TransformVariables.LogJac, ::TransformVariables.ScalarTransform, ::AbstractArray{T,1} where T<:Real) at /Users/simon/.julia/dev/TransformVariables/src/scalar.jl:18
transform_with(::TransformVariables.LogJacFlag, ::UnitVector, ::AbstractArray{T,1} where T<:Real) at /Users/simon/.julia/dev/TransformVariables/src/special_arrays.jl:45
...
Stacktrace:
[1] top-level scope at none:0
@test U <: UpperTriangular | ||
@test size(U) = (4,4) | ||
@test inverse(t,U) ≈ v | ||
end |
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.
Please
- also test for
U
being positive (semi) definite (eg just check the diagonal), - check the log jacobian using ForwardDiff (you find examples of this in the tests),
- test that the results are
@inferred
Happy to help if necessary.
Thanks for the PR, I am happy to merge after some minor changes. |
v = randn(d) | ||
U = transform(t, v) | ||
@test U isa UpperTriangular | ||
@test size(U) = (4,4) |
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.
You probably want a ==
here.
Actually, I've been rethinking this a bit. The problem I'm trying to solve is to get this to play nice with How would you feel about this returning a There is the question then of what the log-Jacobian term should be: i.e. should it be wrt to the uniform density on the cholesky factor itself (as it is now), or should it be wrt to the uniform on the upper triangular part of the "true" matrix (as this is how |
Both have their place, just do what you need --- the Stan manual has suggestions for both. But please start a new PR for the different functionality. |
Fixes #6.