import autograd.numpy as np from pymanopt.manifolds import Sphere from pymanopt import Problem from pymanopt.solvers import NelderMead n = 1000; m = 8 A = np.random.randn(m, n) P = np.eye(m) solver = NelderMead(maxiter = 1000) manifold = Sphere(m) ## spherical constraint def cost(X): return np.sum(X) problem = Problem( manifold = manifold, cost = cost, verbosity = 1 ) import time start = time.time() x = solver.solve(problem) end = time.time() print(end - start)
Can any one please help me use Pymanopt with Tensorflow code which uses placeholders (passing input X, y through feedict)?
import tensorflow as tf import numpy as np from pymanopt import Problem from pymanopt.solvers import SteepestDescent from pymanopt.manifolds import Euclidean, Product X = tf.placeholder( tf.float32, [ 3, 100 ] ) Y = tf.placeholder( tf.float32, [ 3, 1 ] ) w = tf.Variable(tf.zeros([3, 1])) b = tf.Variable(tf.zeros([1, 1])) cost = tf.reduce_mean(tf.square(Y - tf.matmul(tf.transpose(w), X) - b)) with tf.Session() as sess: sess.run(tf.global_variables_initializer()) solver = SteepestDescent() manifold = Product([Euclidean(3, 1), Euclidean(1, 1)]) Xt = np.random.randn(3, 100).astype('float32') Yt = (Xt[0:1, :] - 2*Xt[1:2, :] + np.random.randn(1, 100) + 5).astype('float32') problem = Problem( manifold = manifold, cost = cost, arg = [w, b], verbosity=1 ) solution = solver.solve( problem) print(solution)
If possible, can anyone help me work with this toy example. I want to know how to accomodate Xt and Yt which are inputs. Note that my computational graph is defined using placeholders.