Skip to content
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

Documentation and Convenience wrappers #5

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@ A Julia library to handle projections on manifolds. This is useful for minimizin

Currently, the sphere `{x ∈ K^n, ||x|| = r}` and the Stiefel manifold `{X ∈ K^{n × m}, X'*X = I}` as well as independent copies of these manifolds are supported.

The projections implemented are retract and project_tangent (both are also available inplace `!`).
```
retract(M::Manifold, x) = retract!(M, copy(x))
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to say how retract is implemented to the user. Maybe just say (after the "example" section) how to define a new manifold, which would function as an API documentation? Taking for instance the example of the "partial sphere" you had.

```
retracts the given point `x` back onto the Manifold `M`.
```
project_tangent(M::Manifold, g, x) = project_tangent!(M, copy(g), x)
```
Projects the given vector `g` into the tangent space on the Manifold `M` around the point `x`.
`x` is assumed to lie on the manifold. This is not checked!

To combine Manifolds one can use `PowerManifold` and `ProductManifold`.
The constructor of `PowerManifold` takes the exponentiated manifold `M`, the dimensions of this manifold `inner_dims` and the exponents `outer_dims`.
The constructor of `ProductManifold` takes the two manifolds `m1` and `m2` and their respective dimensions `dims1` and `dims2` as arguments.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd rather not document those yet, as they have a pretty crappy interface. Let those who want it use it in wait of a better code.

Example usage:

```julia
Expand Down
18 changes: 18 additions & 0 deletions src/ManifoldProjections.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,20 @@ abstract type Manifold
end

# fallback for out-of-place ops
"Returns a point that corresponds to the retraction of the given point `x` back onto the Manifold `M`"
retract(M::Manifold, x) = retract!(M, copy(x))
"Retracts a given point `x` back onto the Manifold `M`"
function retract!(M::Manifold, x) end
Copy link
Collaborator

Choose a reason for hiding this comment

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

IMO this type of comment is just noise: it doesn't tell you anything that you wouldn't get by reading the function name. Adding more comments is great when a code is finalized and won't change for ten years. I doubt this is the case with this library, so any comment means giving a false sense of a mature library, and means having to maintain it when we change things around.

"""
Returns the projection of the given vector `g` into the tangent space on the Manifold `M` around the point `x`.
`x` is assumed to lie on the manifold. This is not checked!
Copy link
Collaborator

Choose a reason for hiding this comment

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

"around the point x (assumed to lie on M)"

"""
project_tangent(M::Manifold, g, x) = project_tangent!(M, copy(g), x)
"""
Projects the given vector `g` into the tangent space on the Manifold `M` around the point `x`.
`x` is assumed to lie on the manifold. This is not checked!
"""
function project_tangent!(M::Manifold, g, x) end

# Fake objective function implementing a retraction
mutable struct ManifoldObjective{T<:NLSolversBase.AbstractObjective} <: NLSolversBase.AbstractObjective
Expand Down Expand Up @@ -115,6 +127,9 @@ struct PowerManifold<:Manifold
"Number of embedded manifolds"
outer_dims::Tuple
end
PowerManifold(m::Manifold, inner_dim::Int, outer_dim::Int) = ProductManifold(m, Tuple(inner_dim), Tuple(outer_dim))
PowerManifold(m::Manifold, inner_dim::Tuple, outer_dim::Int) = ProductManifold(m, inner_dim, Tuple(outer_dim))
PowerManifold(m::Manifold, inner_dim::Int, outer_dim::Tuple) = ProductManifold(m, Tuple(inner_dim), outer_dim)
function retract!(m::PowerManifold, x)
for i=1:prod(m.outer_dims) # TODO: use for i in LinearIndices(m.outer_dims)?
retract!(m.inner_manifold,get_inner(m, x, i))
Expand Down Expand Up @@ -145,6 +160,9 @@ struct ProductManifold<:Manifold
dims1::Tuple
dims2::Tuple
end
ProductManifold(m1::Manifold, m2::Manifold, dim1::Int, dim2::Int) = ProductManifold(m1, m2, Tuple(dim1), Tuple(dim2))
ProductManifold(m1::Manifold, m2::Manifold, dim1::Tuple, dim2::Int) = ProductManifold(m1, m2, dim1, Tuple(dim2))
ProductManifold(m1::Manifold, m2::Manifold, dim1::Int, dim2::Tuple) = ProductManifold(m1, m2, Tuple(dim1), dim2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd rather not have these for the same reason as above: this API is pretty bad anyway...

function retract!(m::ProductManifold, x)
retract!(m.m1, get_inner(m,x,1))
retract!(m.m2, get_inner(m,x,2))
Expand Down