scipy.linalg.expm does not give the expected result
See original GitHub issueHi all,
I have the following example and it gives the correct results when my matrix elements are not integers, however it does not work when they are integers:
Reproducing code example:
import numpy as np
import scipy
Q = np.array([[-500,500,0,0],[0,-550,360,190],[0,630,-630,0],[0,0,0,0]]) # Rate Matrix
pi = scipy.linalg.expm(Q*10)
np.sum(pi,axis=1)
array([-0.63612061, -0.2620967 , -0.53480159, 1. ])
But it works for the following case:
Q = np.array([[-500,500,0,0],[0,-550,360,190],[0,630,-630,0],[0,0,0,0]]) # Rate Matrix
pi = scipy.linalg.expm(Q*10.5)
np.sum(pi,axis=1)
array([1., 1., 1., 1.])
Error message:
I do not get any error but the results are wrong.
Scipy/Numpy/Python version information:
scipy.__version__
'1.1.0'
Does anyone know why this is the case and why I am getting this error?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
scipy.linalg.expm — SciPy v1.9.3 Manual
Implements the algorithm given in [1], which is essentially a Pade approximation with a variable order that is decided based on the array...
Read more >Difference between scipy.linalg.expm versus hand-coded one
we see that the result is basically the same, so i think it's safe to use scipy.linalg.expm for matrix exponentiation.
Read more >linalg/_expm_frechet.py · alkaline-ml/scipy - Gemfury
Disabling may give a performance gain, but may result in problems (crashes, ... M[3:, 3:] = A >>> expm_M = scipy.linalg.expm(M) >>> np.allclose(expm_A, ......
Read more >scipy.optimize.minimize fails to converge but result is OK
However, the result matches reasonably closely the expected result ... L = jax.scipy.linalg.expm(C) @ L0 return ssr + jnp.linalg.norm(x - x ...
Read more >Multistate Analysis with Infinite Mixtures of Markov Chains ...
In this appendix, we provide further details on the discrete- time model. ... 1998], our compound process does not: By construction, the.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Thanks for reporting the problem. This looks like a bug.
The
expmcode computes several even matrix powers of the inputAwhile maintaining the data type ofA.Q*10is an integer array, and the values in it are large enough that the values in the matrix powerA**6overflow (using 64 bit integers). Once that happens, the result of the computation is garbage.The work-around (as you discovered) is to be sure that the input array is floating point.
Strange. I can’t replicate it on
1.2.0.dev0+c79b48d. Must have installed from one of my branches.