Git Product home page Git Product logo

pyobs's People

Contributors

mbruno46 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

dalbandea

pyobs's Issues

Diagonalization with complex eigenvalues fails

Diagonalization using pyobs.linalg.eigLR fails when the eigenvalues/eigenvectors are complex. For example

mat = np.array([[0.0, -1], [1, 0.0]]) # eigenvalues are +- i
obs = pyobs.observable()
obs.create_from_cov('Ens', mat.flatten(), np.zeros(len(mat.flatten())))
obs = pyobs.reshape(obs, mat.shape)
eigv, legiv, reigv = pyobs.linalg.eigLR(obs) 

fails with the error

UFuncTypeError                            Traceback (most recent call last)
Cell In[41], line 1
----> 1 eigv, legiv, reigv = pyobs.linalg.eigLR(obs) 
      2 print(eigv)

File ~/pyenv/lib/python3.11/site-packages/pyobs/tensor/linalg.py:157, in eigLR(x)
    154                 gv[:, n] += tmp[m, n] / (l[n] - l[m]) * w[:, m]
    155     return gv
--> 157 gv = pyobs.gradient(gradv, x.mean)
    159 # d w_n = sum_{m \neq n} (v_m, dA^T w_n) / (l_n - l_m) v_m
    160 def gradw(y):

File ~/pyenv/lib/python3.11/site-packages/pyobs/core/gradient.py:36, in gradient.__init__(self, g, x0, gtype)
     33     self.grad = g
     34     return
---> 36 self.Na = numpy.size(g(x0))
     37 self.Ni = numpy.size(x0)
     38 self.gtype = gtype

File ~/pyenv/lib/python3.11/site-packages/pyobs/tensor/linalg.py:154, in eigLR.<locals>.gradv(y)
    152     for m in range(x.shape[1]):
    153         if n != m:
--> 154             gv[:, n] += tmp[m, n] / (l[n] - l[m]) * w[:, m]
    155 return gv

UFuncTypeError: Cannot cast ufunc 'add' output from dtype('complex128') to dtype('float64') with casting rule 'same_kind'

This can be fixed by e.g. defining gv = numpy.zeros(x.shape, dtype=numpy.complex128) instead, but in the subsequent calls to pyobs.gradient arrays of floats are explicitly used in the __init__ call.

How to work with generic matrix observables, which are bound to have complex eigenvalues?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.