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>

source

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 decomposed
  • order: whether to return large or small (close to zero) singular values
  • rng: random number generator
source§

impl<A: NdFloat + Sum, R: Rng> TruncatedSvd<A, R>

source

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.

source

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

source

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§

source§

impl<A: Clone + NdFloat, R: Clone + Rng> Clone for TruncatedSvd<A, R>

source§

fn clone(&self) -> TruncatedSvd<A, R>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<A: Debug + NdFloat, R: Debug + Rng> Debug for TruncatedSvd<A, R>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<A, R> Freeze for TruncatedSvd<A, R>
where R: Freeze,

§

impl<A, R> RefUnwindSafe for TruncatedSvd<A, R>

§

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>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V