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

[Docs] Example in readme is giving NotPSDError #99

Open
jakee417 opened this issue Aug 25, 2024 · 1 comment
Open

[Docs] Example in readme is giving NotPSDError #99

jakee417 opened this issue Aug 25, 2024 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@jakee417
Copy link

📚 Documentation/Examples

** Is documentation wrong? **

In readme example for LinearOperator: https://github.com/cornellius-gp/linear_operator?tab=readme-ov-file#with-linearoperator

from linear_operator.operators import DiagLinearOperator, LowRankRootLinearOperator
# C = torch.randn(1000, 20)
# d = torch.randn(1000)
# b = torch.randn(1000)
A = LowRankRootLinearOperator(C) + DiagLinearOperator(d)  # represents C C^T + diag(d)
torch.linalg.solve(A, b)  # computes A^{-1} b efficiently!

will give

NotPSDError: Matrix not positive definite after repeatedly adding jitter up to 1.0e-06.

** Think you know how to fix the docs? ** (If so, we'd love a pull request from you!)

from linear_operator.operators import DiagLinearOperator, LowRankRootLinearOperator
C = torch.randn(1000, 20)
d = torch.ones(1000) * 1e-9
b = torch.randn(1000)
A = LowRankRootLinearOperator(C) + DiagLinearOperator(d)
torch.linalg.solve(A, b)

should solve the issue

(Link to LinearOperator documentation)

@jakee417 jakee417 added the documentation Improvements or additions to documentation label Aug 25, 2024
@Balandat
Copy link
Collaborator

Balandat commented Sep 1, 2024

Hmm yeah d should just not be sampled from a normal distribution - you'll end up adding negative values to the diagonal. Something like d = 1e-9 + torch.rand(1000) should be safe.

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

No branches or pull requests

2 participants