arm61 / uravu

A straightforward Bayesian data fitting library
https://uravu.readthedocs.io/
MIT License
25 stars 3 forks source link

LinAlgError thrown when passing certain functions into relationship #23

Closed ff995 closed 3 years ago

ff995 commented 4 years ago

Hello

Sorry to bother you again. But when working with certain functions and arrays, the relationship object throws a LinAlgError citing a singular matrix. Do you know which factors may cause this? It seems to occur during line 59 of code within Relationship:

if ordinate_error is not None: potential_y.append(Distribution(stats.norm.rvs(loc=y, scale=ordinate_error[i], size=5000))) I have attached instances where the object works and when it throws an error.

image image image

arm61 commented 4 years ago

This is a good point that I should add some documentation or a helpful error message about! So it is because the uncertainty (dy) in this example code has 0 values, so when the kernel density approximation is performed to get a description of the data likelihood form it sees a delta-function and returns a singular matrix.

TLDR; your uncertainty has 0 values which uravu considers physically unrealistic.

I am gonna leave the issue open so that I can add some documentation and an error message.

arm61 commented 4 years ago

Thanks for using uravu though!

ff995 commented 4 years ago

Thank you for responding. I have changed the value of dy to that used in the working example, but I still get the same error. I think in the 0*y case, dy is an array of zeroes. image image

arm61 commented 4 years ago

You still have a 0 value in the dy value, because x[0] = 0, y[0] = 4 * x[0] = 0, and dy[0] = y[0] * 0.2 = 0. Does that make sense?

If you are interested in contributing a page for the documentation, or adding an error message related to this issue please feel free to open a pull request 😄

ff995 commented 4 years ago

Ah yes it works fine now, my apologies for misunderstanding you and thanks for your help.

arm61 commented 4 years ago

Awesome! Thanks for using uravu, if you have any other comments/issues please get in touch!

arm61 commented 3 years ago

Added a nice error message in 450c6dc644687ebd6247fa27894a017b75984b53.