Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
40 lines (32 sloc) 1.17 KB
import theano.tensor as T
import theano.compile.sharedvalue as S
import numpy as np
from pymanopt import Problem
from pymanopt.manifolds import Euclidean
from pymanopt.solvers import TrustRegions
if __name__ == "__main__":
# Cost function is the squared reconstruction error
wT = T.matrix()
yT = S.shared(np.random.randn(1, 1))
XT = S.shared(np.random.randn(1, 1))
cost = T.sum((**2)
# A solver that involves the hessian
solver = TrustRegions()
# R^3
manifold = Euclidean(3, 1)
# Create the problem with extra cost function arguments
problem = Problem(manifold=manifold, cost=cost, arg=wT, verbosity=0)
# Solve 5 instances of the same type of problem for different data input
for k in range(0, 5):
# Generate random data
X = np.random.randn(3, 200)
Y = np.random.randn(1, 200)
wopt = solver.solve(problem)
print('Run {}'.format(k+1))
print('Weights found by pymanopt (top) / '
'closed form solution (bottom)')