fabian-sp / GGLasso

A Python package for General Graphical Lasso computation
MIT License
30 stars 14 forks source link

Parameter search over a single parameter in GGL/FGL results in error #46

Closed ikarmann closed 4 months ago

ikarmann commented 5 months ago

I was trying to make parameter search over lambda1 keeping lambda2 constant. However this results in indexing error since the internal variable L2 becomes an 1-dimensional array. I solved the problem by adding np.expand_dims if L2 is 1d. Maybe this could be incorporated in the code.

Tx

fabian-sp commented 5 months ago

Hi, thanks for reporting the bug. Could you post a short snippet of what produced the error, and the changes you made to fix it?

ikarmann commented 5 months ago

Hello!

I tried running

glasso.model_selection(modelselect_params={'lambda1_range':np.logspace(0,-2,20), 'lambda2_range':[1e-8]}, method='eBIC')

and got an indexing error from line

grid1 = L1.shape[0]; grid2 = L2.shape[1]

in the function grid_search as L2 becomes 1-dimensional.

As a solution I added the lines

if len(L1.shape) == 1: L1 = np.expand_dims(L1, 1) if len(L2.shape) == 1: L2 = np.expand_dims(L2, 1)

before that.

Additionally, newer versions of numpy have deprecated the np.int and np.float aliases, so I had to remove those from the assert statements.

Thank you and congrats for the insightful developments in graphical lasso.

fabian-sp commented 5 months ago

thanks, I will look into it.

Two remarks:

ikarmann commented 5 months ago

I just realized that removing the .squeeze() from the lambda_grid is a more reasonable solution.