Struct linfa_linalg::lobpcg::TruncatedEig

source ·
pub struct TruncatedEig<A: NdFloat, R: Rng> {
    pub constraints: Option<Array2<A>>,
    /* private fields */
}
Expand description

Truncated eigenproblem solver

This struct wraps the LOBPCG algorithm and provides convenient builder-pattern access to parameter like maximal iteration, precision and constraint matrix. Furthermore it allows conversion into a iterative solver where each iteration step yields a new eigenvalue/vector pair.

§Example

use ndarray::{arr1, Array2};
use linfa_linalg::{Order, lobpcg::TruncatedEig};
use rand::SeedableRng;
use rand_xoshiro::Xoshiro256Plus;

let diag = arr1(&[1., 2., 3., 4., 5.]);
let a = Array2::from_diag(&diag);

let mut eig = TruncatedEig::new_with_rng(a, Order::Largest, Xoshiro256Plus::seed_from_u64(42))
   .precision(1e-5)
   .maxiter(500);

let res = eig.decompose(3);

Fields§

§constraints: Option<Array2<A>>

Implementations§

source§

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

source

pub fn new_with_rng( problem: Array2<A>, order: Order, rng: R, ) -> TruncatedEig<A, R>

Create a new truncated eigenproblem solver

§Properties
  • problem: problem matrix
  • order: ordering of the eigenvalues with Order
  • rng: random number generator
source§

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

source

pub fn precision(self, precision: f32) -> Self

Set desired precision

This argument specifies the desired precision, which is passed to the LOBPCG solver. It controls at which point the opimization of each eigenvalue is stopped. The precision is global and applied to all eigenvalues with respect to their L2 norm.

If the precision can’t be reached and the maximum number of iteration is reached, then an error is returned in LobpcgResult.

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 orthogonal_to(self, constraints: Array2<A>) -> Self

Construct a solution, which is orthogonal to this

If a number of eigenvectors are already known, then this function can be used to construct a orthogonal subspace. Also used with an iterative approach.

source

pub fn precondition_with(self, preconditioner: Array2<A>) -> Self

Apply a preconditioner

A preconditioning matrix can speed up the solving process by improving the spectral distribution of the eigenvalues. It requires prior knowledge of the problem.

source

pub fn decompose(&mut self, num: usize) -> LobpcgResult<A>

Calculate the eigenvalue decomposition

§Parameters
  • num: number of eigenvalues ordered by magnitude
§Example
use ndarray::{arr1, Array2};
use linfa_linalg::{Order, lobpcg::TruncatedEig};
use rand::SeedableRng;
use rand_xoshiro::Xoshiro256Plus;

let diag = arr1(&[1., 2., 3., 4., 5.]);
let a = Array2::from_diag(&diag);

let mut eig = TruncatedEig::new_with_rng(a, Order::Largest, Xoshiro256Plus::seed_from_u64(42))
   .precision(1e-5)
   .maxiter(500);

let res = eig.decompose(3);
source§

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

source

pub fn into_iter_step_size( self, step_size: usize, ) -> Result<TruncatedEigIterator<A, R>>

Trait Implementations§

source§

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

source§

fn clone(&self) -> TruncatedEig<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 TruncatedEig<A, R>

source§

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

Formats the value using the given formatter. Read more
source§

impl<A: NdFloat + Sum, R: Rng> IntoIterator for TruncatedEig<A, R>

source§

type Item = (ArrayBase<OwnedRepr<A>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<A>, Dim<[usize; 2]>>)

The type of the elements being iterated over.
source§

type IntoIter = TruncatedEigIterator<A, R>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> TruncatedEigIterator<A, R>

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

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

§

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

§

impl<A, R> Send for TruncatedEig<A, R>
where R: Send,

§

impl<A, R> Sync for TruncatedEig<A, R>
where R: Sync,

§

impl<A, R> Unpin for TruncatedEig<A, R>
where R: Unpin,

§

impl<A, R> UnwindSafe for TruncatedEig<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