Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
29 lines (20 sloc) 830 Bytes
import autograd.numpy as np
from pymanopt import Problem
from pymanopt.solvers import SteepestDescent
from pymanopt.manifolds import Stiefel
import pprint
if __name__ == "__main__":
# Generate random data with highest variance in first 2 dimensions
X = np.diag([3, 2, 1]).dot(np.random.randn(3, 200))
# Cost function is the squared reconstruction error
def cost(w):
return np.sum(np.sum((X -,, X)))**2))
solver = SteepestDescent(logverbosity=2)
# Projection matrices onto a two dimensional subspace
manifold = Stiefel(3, 2)
# Solve the problem with pymanopt
problem = Problem(manifold=manifold, cost=cost, verbosity=0)
wopt, optlog = solver.solve(problem)
print('And here comes the optlog:\n\r')
pp = pprint.PrettyPrinter()