Skip to content

Commit

Permalink
Relax orthogonal (#53)
Browse files Browse the repository at this point in the history
* Relax to Abstract

* Bump Project

* Update docstring
  • Loading branch information
AlexRobson authored Jul 28, 2022
1 parent 0d59a83 commit 3ff6a53
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ParameterHandling"
uuid = "2412ca09-6db7-441c-8e3a-88d5709968c5"
authors = ["Invenia Technical Computing Corporation"]
version = "0.4.2"
version = "0.4.3"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
14 changes: 7 additions & 7 deletions src/parameters_matrix.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
"""
nearest_orthogonal_matrix(X::StridedMatrix)
nearest_orthogonal_matrix(X::AbstractMatrix{<:Union{Real,Complex}})
Project `X` onto the closest orthogonal matrix in Frobenius norm.
Originally used in varz: https://github.com/wesselb/varz/blob/master/varz/vars.py#L446
"""
@inline function nearest_orthogonal_matrix(X::StridedMatrix{<:Union{Real,Complex}})
@inline function nearest_orthogonal_matrix(X::AbstractMatrix{<:Union{Real,Complex}})
# Inlining necessary for type inference for some reason.
U, _, V = svd(X)
return U * V'
end

"""
orthogonal(X::StridedMatrix{<:Real})
orthogonal(X::AbstractMatrix{<:Real})
Produce a parameter whose `value` is constrained to be an orthogonal matrix. The argument `X` need not
be orthogonal.
Expand All @@ -22,9 +22,9 @@ Frobenius norm) and is overparametrised as a consequence.
Originally used in varz: https://github.com/wesselb/varz/blob/master/varz/vars.py#L446
"""
orthogonal(X::StridedMatrix{<:Real}) = Orthogonal(X)
orthogonal(X::AbstractMatrix{<:Real}) = Orthogonal(X)

struct Orthogonal{TX<:StridedMatrix{<:Real}} <: AbstractParameter
struct Orthogonal{TX<:AbstractMatrix{<:Real}} <: AbstractParameter
X::TX
end

Expand All @@ -39,14 +39,14 @@ function flatten(::Type{T}, X::Orthogonal) where {T<:Real}
end

"""
positive_definite(X::StridedMatrix{<:Real})
positive_definite(X::AbstractMatrix{<:Real})
Produce a parameter whose `value` is constrained to be a positive-definite matrix. The argument `X` needs to
be a positive-definite matrix (see https://en.wikipedia.org/wiki/Definite_matrix).
The unconstrained parameter is a `LowerTriangular` matrix, stored as a vector.
"""
function positive_definite(X::StridedMatrix{<:Real})
function positive_definite(X::AbstractMatrix{<:Real})
isposdef(X) || throw(ArgumentError("X is not positive-definite"))
return PositiveDefinite(tril_to_vec(cholesky(X).L))
end
Expand Down

2 comments on commit 3ff6a53

@AlexRobson
Copy link
Contributor 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/65163

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.4.3 -m "<description of version>" 3ff6a53722c6f0e130fcb62625108b6098cd4499
git push origin v0.4.3

Please sign in to comment.