How to set gradients on product manifolds ? (PyManopt)

46 views
Skip to first unread message

Yacin Zriwil

unread,
Mar 2, 2024, 5:55:43 PMMar 2
to Manopt
Hello,

I'm working on an optimization problem using PyManopt, where the admissible space consists of a product of three manifolds, two of which are linear space and one of them is a custom manifold. Notably, the three matrices involved have distinct sizes: N x N, N x N, and N x M. I have a couple of questions:

1. Explicit Gradient Specification:
To solve my problem, I want to explicitly specify the gradient. Here is my code : 

@pymanopt.function.numpy(manifold)
def cost(Q, T, B):
    return np.linalg.norm(Y - Q@T@Q.T@X - B@U, 'fro')**2

@pymanopt.function.numpy(manifold)
def gradient(Q, T, B):
    C  = X.T @ Q @ T.T    
    minusYplusBU = -Y + B@U
    grad_B = 2 * (minusYplusBU + Q @ T @ Q.T @ X ) @ U.T
    grad_Q = 2 * ( (minusYplusBU) @ C + X @ (minusYplusBU.T + C) @ T )
    grad_T = 2 * ( Q.T @ minusYplusBU + T @ Q.T @ X ) @ X.T @ Q
    print(f"In gradients : size(grad_B) = {grad_B.shape} \t size(grad_Q) = {grad_Q.shape} \t size(grad_T) = {grad_T.shape}")
   
    return np.array([grad_Q, grad_T, grad_B])

problem = Problem(manifold=manifold, cost=cost, euclidean_gradient = gradient)


Here is the error occurred : "ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 2 dimensions. The detected shape was (3, 20) + inhomogeneous part."

Can you help me understand this error ?

2. Gradient selection:
Is it possible to set a riemannian gradient for a variable and an euclidean gradient for another variable ?

Appreciate your valuable assistance,

Thank you. 


Nicolas Boumal

unread,
Mar 3, 2024, 6:37:00 AMMar 3
to Manopt
Hello,
For technical questions related to PyManopt, I suggest you post to the pymanopt github issues. (You may get a reply here too, but this forum is more geared toward the Matlab version and toward math questions related to optimization on manifolds).

Yacin Zriwil

unread,
Mar 3, 2024, 6:45:07 AMMar 3
to Manopt
Thanks for the quick response. I'll check out the PyManopt GitHub. Have a great Sunday!
Reply all
Reply to author
Forward
0 new messages