tsitsvero / hodgelaplacians

Hodge/Bochner Laplacians of simplicial complexes, their spectra, higher-order diffusion and random walks
MIT License
27 stars 6 forks source link

non deterministic #4

Closed poutine-dejeuner closed 2 years ago

poutine-dejeuner commented 3 years ago

The code returns different eigenvectors for each run, for example

complex = ((1,2),(2,3),(3,1))
hl=hodgelaplacians.HodgeLaplacians(complex,maxdimension=1)

vec = hl.getHodgeSpectrum(0,2)
print(vec)
vec = vec[1][1,:]

returns [ 0.18589262 -0.78148313 0.59559051] and on a second run [ 0.14594447 -0.7686914 0.62274693]

could this be due to the sparse scipy eigenvalues/vectors algorithm ?

tsitsvero commented 2 years ago

It could be a bit late, however as far as I understand it's because of badly chosen example of L (sorry for that). This Hodge Laplacian matrix has eigenvalues (0.0, 3.0, 3.0), so the largest eigenvalue has multiplicity of two and thus any linear combination of eigenvectors is also an eigenvector. Thus eigsh() just gets any single vector from subspace spanned by two vectors.

Probably would be nice just to add a parameter which eigenvalues to return like in eigsh documentation: ‘LM’ : Largest (in magnitude) eigenvalues. ‘SM’ : Smallest (in magnitude) eigenvalues. ‘LA’ : Largest (algebraic) eigenvalues. ‘SA’ : Smallest (algebraic) eigenvalues. ‘BE’ : Half (k/2) from each end of the spectrum.

could this be due to the sparse scipy eigenvalues/vectors algorithm ?

Randomness due to algorithm initialization also exists in some cases.