Struct linfa_linalg::lobpcg::TruncatedSvd
source · pub struct TruncatedSvd<A: NdFloat, R: Rng> { /* private fields */ }
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§
source§impl<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
source§impl<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§
Auto Trait Implementations§
impl<A, R> Freeze for TruncatedSvd<A, R>where
R: Freeze,
impl<A, R> RefUnwindSafe for TruncatedSvd<A, R>where
R: RefUnwindSafe,
A: 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
R: UnwindSafe,
A: RefUnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)