Nifty solver
Project description
nifty-solve
Fit very flexible linear models using Fourier bases without ever constructing the design matrix.
Install
uv add nifty-solve
If you plan to use JAX operators, you will need to use:
uv add nifty-solve[jax]
If that fails:
uv add "git+https://github.com/andycasey/nifty-solve"
Examples
1D real-valued signal with unknown uncertainties
import numpy as np
import matplotlib.pyplot as plt
from nifty_solve.operators import Finufft1DRealOperator
np.random.seed(1)
N = 128 # number of data points
K = 5 # number of Fourier modes
# Generate data
t = np.random.uniform(size=N)
y = np.random.uniform(size=3) @ np.array([t**2, t, np.ones(N)]) + np.random.normal(size=N) * 0.02
# Create a linear operator and solve the system
A = Finufft1DRealOperator(t, n_modes=K)
θ = A / y
# Make a plot
ti = np.linspace(0, 1, 1000)
Ai = Finufft1DRealOperator(ti, n_modes=K)
# Make a plot
fig, ax = plt.subplots()
ax.scatter(t, y, c="k")
ax.plot(ti, Ai @ θ)
ax.set_xlabel("t")
ax.set_ylabel("y")
[!TIP] The
A / yis just syntactic sugar for finding the least-squares solution:from scipy.sparse.linalg import lsqr θ_1 = A / y θ_2, *extras = lsqr(A, y) assert np.allclose(θ_1, θ_2)
1D real-valued signal with uncertainties
import numpy as np
import matplotlib.pyplot as plt
from nifty_solve.operators import Finufft1DRealOperator
from pylops import Diagonal
np.random.seed(1)
N = 128 # number of data points
K = 5 # number of Fourier modes
# Generate data
t = np.random.uniform(size=N)
y_true = np.random.uniform(size=3) @ np.array([t**2, t, np.ones(N)])
y_err = 0.05 + np.abs(np.random.normal(size=N) * 0.02)
Y = y_true + y_err * np.random.normal(size=N)
C_inv = Diagonal(y_err**-2)
# Create a linear operator and solve the system
A = Finufft1DRealOperator(t, n_modes=K)
θ = (A.T @ C_inv @ A) / (A.T @ C_inv @ Y)
# Make a plot
ti = np.linspace(0, 1, 1000)
Ai = Finufft1DRealOperator(ti, n_modes=K)
# Make a plot
fig, ax = plt.subplots()
ax.errorbar(t, Y, yerr=y_err, c="k", fmt="o")
ax.plot(ti, Ai @ θ)
ax.set_xlabel("t")
ax.set_ylabel("y")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nifty_solve-0.1.0.tar.gz.
File metadata
- Download URL: nifty_solve-0.1.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bdc5915afa053e0b1b6d431bf32db3c9095f287c31c3efc5e3407bf6a79821e6
|
|
| MD5 |
929587b1af04c920ce21758f2f8b0834
|
|
| BLAKE2b-256 |
bc885dac503efc3a5f93728308610ff82375a2a3321085e60e675439d526fd3c
|
Provenance
The following attestation bundles were made for nifty_solve-0.1.0.tar.gz:
Publisher:
publish.yml on andycasey/nifty-solve
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nifty_solve-0.1.0.tar.gz -
Subject digest:
bdc5915afa053e0b1b6d431bf32db3c9095f287c31c3efc5e3407bf6a79821e6 - Sigstore transparency entry: 229315503
- Sigstore integration time:
-
Permalink:
andycasey/nifty-solve@a93e0739f723c2f6ea38015ce86adb6bf2513035 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/andycasey
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a93e0739f723c2f6ea38015ce86adb6bf2513035 -
Trigger Event:
push
-
Statement type:
File details
Details for the file nifty_solve-0.1.0-py3-none-any.whl.
File metadata
- Download URL: nifty_solve-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe2c3edb96fef2c705bc9883102d49cb5512e837cfce109f3e470d6b9630a7e0
|
|
| MD5 |
88614ededaf97d6a158297a549fc13d5
|
|
| BLAKE2b-256 |
ba31f8dc66c0da26ecd4b81d9bc101671ab05941b752d84fb6f7417260533cd1
|
Provenance
The following attestation bundles were made for nifty_solve-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on andycasey/nifty-solve
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nifty_solve-0.1.0-py3-none-any.whl -
Subject digest:
fe2c3edb96fef2c705bc9883102d49cb5512e837cfce109f3e470d6b9630a7e0 - Sigstore transparency entry: 229315504
- Sigstore integration time:
-
Permalink:
andycasey/nifty-solve@a93e0739f723c2f6ea38015ce86adb6bf2513035 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/andycasey
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a93e0739f723c2f6ea38015ce86adb6bf2513035 -
Trigger Event:
push
-
Statement type: