mojolearn.Cholesky#
- class mojolearn.Cholesky(jitter=None)[source]#
Bases:
NumericModeMixinCholesky factorization
A + jitter * I = L @ L.Tof a symmetric positive-definite matrix, then solves.fitfactors a given float32 matrix once;solveanswersA X = Bfrom the factor andlogdet_gives the log-determinant. A failed factorization is not an exception: checkinfo_(0 means success); a failed factor’ssolveandlogdet_refuse. The factor can be saved withsaveand loaded withload, including on a CPU-only install, wherefitandsolvealso run.- Parameters:
jitter (float or None, default None) – Ridge added to the diagonal before factoring. None uses the profile’s fixed ridge (see
profile_jitter); 0.0 adds none. Any other value is refused, because the identical mode fixes the ridge to those two values. A non-number raisesTypeError.- Variables:
L_ (mojolearn.Array, shape (n, n), float32) – Lower-triangular factor, strict upper triangle zero. Meaningful only when
info_ == 0.info_ (int) – LAPACK-style status: 0 for a complete factor;
k > 0means the leading minor of order k is not positive definite andL_is partial.nb_ (int) – Panel width used by the factorization.
logdet_ (float) –
log |A + jitter * I|. RaisesValueErrorafter a failed fit.jitter_ (float) – The ridge that was added.
n_ (int) – Matrix size.
Notes
A non-square
Aor a right-hand side whose row count is not n raisesValueError; non-finite or non-symmetric matrices are refused before any work.Examples
>>> import numpy as np, mojolearn >>> rng = np.random.default_rng(0) >>> M = rng.random((64, 64), dtype=np.float32) >>> A = (M @ M.T + 64 * np.eye(64, dtype=np.float32)).astype(np.float32) >>> chol = mojolearn.Cholesky(jitter=0.0).fit(A) >>> x = np.asarray(chol.solve(np.ones(64, dtype=np.float32)))
Methods
fit(A)Factor
A + jitter * I; returns self.get_params([deep])load(path)Load a factor written by
save.numeric_mode_used()The numeric mode this estimator runs in.
The profile's fixed ridge, used when
jitter=None.save(path)Write the factor to
pathas an .npz file.set_params(**params)Set constructor parameters.
solve(B)Solve
A X = Bfrom the factor.Accelerator API of the loaded binary, read back from it; "cpu" on a CPU-only install.
Attributes
log |A + jitter * I|; raisesValueErrorafter a failed fit.- vendor_used()[source]#
Accelerator API of the loaded binary, read back from it; “cpu” on a CPU-only install.
- fit(A)[source]#
Factor
A + jitter * I; returns self.Ais a square 2-D float32 matrix, otherwiseValueError. A failed factorization setsinfo_ != 0instead of raising.
- property logdet_#
log |A + jitter * I|; raisesValueErrorafter a failed fit.
- solve(B)[source]#
Solve
A X = Bfrom the factor.- Parameters:
B (float32 array, shape (n,) or (n, nrhs))
- Returns:
X (float32 array, the shape of
B)- Raises:
ValueError – Before
fit, or whenBhas the wrong row count or no columns. Solving against a failed factor is also refused.