Closed calvinmccarter closed 2 years ago
Hi @calvinmccarter - I am not able to reproduce the flattened output issue on my machine (see below). Can you please pull the latest repo and try again? Please use fixed matrices X/Y or provide a random seed. Thanks for pointing this out.
Code:
torch.manual_seed(191)
Y = torch.eye(5) + torch.normal(0, 0.1, size=(5, 5))
X = torch.eye(5) + torch.normal(0, 0.1, size=(5, 5))
def myfun(B):
obj = torch.sum((Y - X @ B) ** 2)
return obj
B_init = torch.eye(5)
res = tm.minimize(
myfun,
B_init,
method="cg",
max_iter=10,
disp=3,
)
print(res.x.numpy())
Output:
initial fval: 0.3555
iter 1 - fval: 0.0245
iter 2 - fval: 0.0025
iter 3 - fval: 0.0002
iter 4 - fval: 0.0000
iter 5 - fval: 0.0000
Optimization terminated successfully.
Current function value: 0.000000
Iterations: 5
Function evaluations: 11
[[ 0.7799 -0.114 0.0043 -0.1361 -0.0143]
[-0.0608 0.8359 0.1543 0.1881 0.0663]
[-0.0425 -0.0986 0.8894 -0.0299 0.0949]
[-0.1785 -0.0352 -0.0761 1.0242 -0.0109]
[-0.0007 0.0523 -0.1453 0.0983 1.0643]]
Updating from 8c5da1c7 to latest fixed this -- thanks so much!
In the following optimization over a 5x5 matrix, we see that CG works, but it produces a flattened version of the correct result:
produces: