Python port of the MATLAB package manopt, for manifold optimization using Theano for automatic differentiation.
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.
Thanks :)
In [1]: import autograd.numpy as np
In [2]: from pymanopt.manifolds import Stiefel
...: from pymanopt import Problem
...: from pymanopt.solvers import SteepestDescent
...:
In [3]: # (1) Instantiate a manifold
...: manifold = Stiefel(5, 2)
...:
...: # (2) Define the cost function (here using autograd.numpy)
...: def cost(X): return np.sum(X)
...:
...: problem = Problem(manifold=manifold, cost=cost)
...:
...: # (3) Instantiate a Pymanopt solver
...: solver = SteepestDescent()
...:
...: # let Pymanopt do the rest
...: Xopt = solver.solve(problem)
...: print(Xopt)
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.
Thanks :)
Hi, I am just getting started with pymanopt ! If possible,can anyone tell me what "verbosity" parameter means in the initialization of "Problem"?
hi, I'm trying to use pymanopt, but when i pip install the package it somehow doesn't install the optimizers - i can do import pymanopt.manifolds, but not import pymanopt.optimizers. any idea what's going on? if i try to pip install directly from github, it fails with the message
WARNING: Built wheel for pymanopt is invalid: Metadata 1.2 mandates PEP 440 version, but 'dev' is not
Failed to build pymanopt
ERROR: Could not build wheels for pymanopt, which is required to install pyproject.toml-based project
pip install --no-use-pep517 git+https://github.com/pymanopt/pymanopt
. That skips the metadata checks. The issue is in fact that on our master branch the version is always dev
. We only substitute a proper version number when we're building release packages