Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 9 additions & 9 deletions meegkit/utils/covariances.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ def nonlinear_eigenspace(L, k, alpha=1):
import pymanopt
from pymanopt import Problem
from pymanopt.manifolds import Grassmann
from pymanopt.solvers import TrustRegions
from pymanopt.optimizers import TrustRegions

n = L.shape[0]
assert L.shape[1] == n, 'L must be square.'
Expand All @@ -454,26 +454,26 @@ def nonlinear_eigenspace(L, k, alpha=1):
manifold._dimension = 1 # hack

# A solver that involves the hessian (check if correct TODO)
solver = TrustRegions()
solver = TrustRegions(verbosity=0)

# Cost function evaluation
@pymanopt.function.Callable
@pymanopt.function.numpy(manifold)
def cost(X):
rhoX = np.sum(X ** 2, 1, keepdims=True) # diag(X*X')
val = 0.5 * np.trace(X.T @ (L * X)) + \
(alpha / 4) * (rhoX.T @ mldivide(L, rhoX))
return val

# Euclidean gradient evaluation
@pymanopt.function.Callable
@pymanopt.function.numpy(manifold)
def egrad(X):
rhoX = np.sum(X ** 2, 1, keepdims=True) # diag(X*X')
g = L @ X + alpha * np.diagflat(mldivide(L, rhoX)) @ X
return g

# Euclidean Hessian evaluation
# Note: Manopt automatically converts it to the Riemannian counterpart.
@pymanopt.function.Callable
@pymanopt.function.numpy(manifold)
def ehess(X, U):
rhoX = np.sum(X ** 2, 1, keepdims=True) # np.diag(X * X')
rhoXdot = 2 * np.sum(X.dot(U), 1)
Expand All @@ -493,8 +493,8 @@ def ehess(X, U):
# Call manoptsolve to automatically call an appropriate solver.
# Note: it calls the trust regions solver as we have all the required
# ingredients, namely, gradient and Hessian, information.
problem = Problem(manifold=manifold, cost=cost, egrad=egrad, ehess=ehess,
verbosity=0)
Xsol = solver.solve(problem, U0)
problem = Problem(manifold=manifold, cost=cost, euclidean_gradient=egrad,
euclidean_hessian=ehess)
Xsol = solver.run(problem, initial_point=U0)

return S0, Xsol
return S0, Xsol.point
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ all_files = 1
upload-dir = doc/_build/html

[options.extras_require]
extra = pymanopt @ git+https://github.com/pymanopt/pymanopt@master
extra = pymanopt