Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different result for pseudo-inverse matrix compared to Numpy #198

Open
elect86 opened this issue Jun 28, 2024 · 0 comments
Open

Different result for pseudo-inverse matrix compared to Numpy #198

elect86 opened this issue Jun 28, 2024 · 0 comments

Comments

@elect86
Copy link

elect86 commented Jun 28, 2024

I'm porting some code from Python to Kotlin and I'm using Ejml, specifically this

np.linalg.pinv(cell)

which "Compute the (Moore-Penrose) pseudo-inverse of a matrix." and where cell is a 3x3 float64 matrix

[[2.259825867767797, 0.0, 0.0],
[-1.1299129338838985, 1.9570656971336065, 0.0],
[0.0, 0.0, 3.5698785608749377]]

my float counterpart is

[0.44251198, -8.326673E-17, 0.0]
[0.25548452, 0.51096904, 0.0]
[0.0, 0.0, 0.28012156]

on Python I do get

[[4.42511972e-01 2.83417670e-17 0.00000000e+00],
[2.55484525e-01 5.10969050e-01 0.00000000e+00],
[0.00000000e+00 0.00000000e+00 2.80121574e-01]]

on Ejml, with SimpleMatrix::pseudoInverse

[0.44251198, -2.9802322E-8, 0.0]
[0.25548458, 0.5109691, 0.0]
[0.0, 0.0, 0.28012162]

You can see that there is just one problematic value, at [0, 1]

if I hardcode the float64 values of Python into Kotlin, I do get a closer value but still not quite the same

[0.44251198, -8.326673E-17, 0.0]
[0.25548452, 0.51096904, 0.0]
[0.0, 0.0, 0.28012156]

Any idea how I could improve this?

Python code is here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant