I have a set of matrices that represent networks, and a function that determines network prominence per row ( = network node ). The optimal value for each separate matrix depends on the values on the diagonal, and I can find the optimal diagonal for the whole set of matrices by maximising (or minimising) the total for the set (by adding the matrix-wise values together).
When I pass the diagonal to the group function, the values on the diagonal, passed as lmfit Parameters, don't change between iterations, I cannot figure out why.
I have tried to make a minimal representative example, which aims to find the best diagonal D for a matrix M so that M - (D*M) is minimal, by minimising this over a group of matrices. This is a very roundabout way of finding the identity matrix, but it represents how I pass on my parameters. I wanted to test whether the parameters were going to be passed on between different iterations here:
However, I get an error for this example saying:
File "/home/amwink/cloud/surfdrive/work/projects/epad/analyses/multipad/optimaldiagonal.py", line 36, in <module>
best_fit = minimize ( fcn = diagonal_all,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/amwink/software/python/conda/envs/network-analyses/lib/python3.11/site-packages/lmfit/minimizer.py", line 2601, in minimize
return fitter.minimize(method=method)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/amwink/software/python/conda/envs/network-analyses/lib/python3.11/site-packages/lmfit/minimizer.py", line 2345, in minimize
return function(**kwargs)
^^^^^^^^^^^^^^^^^^
File "/home/amwink/software/python/conda/envs/network-analyses/lib/python3.11/site-packages/lmfit/minimizer.py", line 1541, in least_squares
ret = least_squares(self.__residual, start_vals,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/amwink/software/python/conda/envs/network-analyses/lib/python3.11/site-packages/scipy/optimize/_lsq/least_squares.py", line 796, in least_squares
raise ValueError("`x0` must have at most 1 dimension.")
ValueError: `x0` must have at most 1 dimension.
I do not get this in my other program, even though the "group_optimal" function there also returns a scalar "group difference".
Does anyone know:
- if it is possible to pass on the diagonal in a matrix optimisation problem as Parameters?
- if it is a problem to pass a function to minimize() that returns a scalar?