Skip to content

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

simonbyrne
Copy link

Fixes #6.

U[row, col] = x[index]
index += 1
end
if flag isa NoLogJac
Copy link
Owner

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.

Copy link
Author

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
Copy link
Owner

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.

@tpapp
Copy link
Owner

tpapp commented Feb 1, 2019

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)
Copy link
Owner

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.

@simonbyrne
Copy link
Author

simonbyrne commented Feb 4, 2019

Actually, I've been rethinking this a bit. The problem I'm trying to solve is to get this to play nice with pdf(::InverseWishart, ...), and as the covariance term for MvNormal constructor.

How would you feel about this returning a Cholesky object instead of an UpperTriangular?

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 logpdf of the InveseWishart distribution is defined).

@tpapp
Copy link
Owner

tpapp commented Feb 5, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants