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.