Struct linfa_linalg::lobpcg::TruncatedSvd
source · [−]Expand description
Truncated singular value decomposition
Wraps the LOBPCG algorithm and provides convenient builder-pattern access to parameter like maximal iteration, precision and constrain matrix.
Implementations
sourceimpl<A: NdFloat + Sum, R: Rng> TruncatedSvd<A, R>
impl<A: NdFloat + Sum, R: Rng> TruncatedSvd<A, R>
sourcepub fn new_with_rng(
problem: Array2<A>,
order: Order,
rng: R
) -> TruncatedSvd<A, R>
pub fn new_with_rng(
problem: Array2<A>,
order: Order,
rng: R
) -> TruncatedSvd<A, R>
Create a new truncated SVD problem
Parameters
problem
: rectangular matrix which is decomposedorder
: whether to return large or small (close to zero) singular valuesrng
: random number generator
sourceimpl<A: NdFloat + Sum, R: Rng> TruncatedSvd<A, R>
impl<A: NdFloat + Sum, R: Rng> TruncatedSvd<A, R>
sourcepub fn precision(self, precision: f32) -> Self
pub fn precision(self, precision: f32) -> Self
Set the required precision of the solution
The precision is, in the context of SVD, the square-root precision of the underlying eigenproblem solution. The eigenproblem-precision is used to check the L2 error of each eigenvector and stops its optimization when the required precision is reached.
sourcepub fn maxiter(self, maxiter: usize) -> Self
pub fn maxiter(self, maxiter: usize) -> Self
Set the maximal number of iterations
The LOBPCG is an iterative approach to eigenproblems and stops when this maximum number of iterations are reached
sourcepub fn decompose(self, num: usize) -> Result<TruncatedSvdResult<A>>
pub fn decompose(self, num: usize) -> Result<TruncatedSvdResult<A>>
Calculate the singular value decomposition
Parameters
num
: number of singular-value/vector pairs, ordered by magnitude
Example
use ndarray::{arr1, Array2};
use linfa_linalg::{Order, lobpcg::TruncatedSvd};
use rand::SeedableRng;
use rand_xoshiro::Xoshiro256Plus;
let diag = arr1(&[1., 2., 3., 4., 5.]);
let a = Array2::from_diag(&diag);
let eig = TruncatedSvd::new_with_rng(a, Order::Largest, Xoshiro256Plus::seed_from_u64(42))
.precision(1e-4)
.maxiter(500);
let res = eig.decompose(3);
Trait Implementations
sourceimpl<A: Clone + NdFloat, R: Clone + Rng> Clone for TruncatedSvd<A, R>
impl<A: Clone + NdFloat, R: Clone + Rng> Clone for TruncatedSvd<A, R>
sourcefn clone(&self) -> TruncatedSvd<A, R>
fn clone(&self) -> TruncatedSvd<A, R>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
Auto Trait Implementations
impl<A, R> RefUnwindSafe for TruncatedSvd<A, R> where
A: RefUnwindSafe,
R: RefUnwindSafe,
impl<A, R> Send for TruncatedSvd<A, R> where
R: Send,
impl<A, R> Sync for TruncatedSvd<A, R> where
R: Sync,
impl<A, R> Unpin for TruncatedSvd<A, R> where
R: Unpin,
impl<A, R> UnwindSafe for TruncatedSvd<A, R> where
A: RefUnwindSafe,
R: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more