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
sourceimpl<A: NdFloat + Sum, R: Rng> TruncatedEig<A, R>
impl<A: NdFloat + Sum, R: Rng> TruncatedEig<A, R>
sourcepub fn new_with_rng(
problem: Array2<A>,
order: Order,
rng: R
) -> TruncatedEig<A, R>
pub fn new_with_rng(
problem: Array2<A>,
order: Order,
rng: R
) -> TruncatedEig<A, R>
Create a new truncated eigenproblem solver
Properties
problem
: problem matrixorder
: ordering of the eigenvalues with Orderrng
: random number generator
sourceimpl<A: NdFloat + Sum, R: Rng> TruncatedEig<A, R>
impl<A: NdFloat + Sum, R: Rng> TruncatedEig<A, R>
sourcepub fn precision(self, precision: f32) -> Self
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.
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 orthogonal_to(self, constraints: Array2<A>) -> Self
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.
sourcepub fn precondition_with(self, preconditioner: Array2<A>) -> Self
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.
sourcepub fn decompose(&mut self, num: usize) -> LobpcgResult<A>
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);
sourceimpl<A: NdFloat + Sum, R: Rng> TruncatedEig<A, R>
impl<A: NdFloat + Sum, R: Rng> TruncatedEig<A, R>
pub fn into_iter_step_size(
self,
step_size: usize
) -> Result<TruncatedEigIterator<A, R>>
Trait Implementations
sourceimpl<A: Clone + NdFloat, R: Clone + Rng> Clone for TruncatedEig<A, R>
impl<A: Clone + NdFloat, R: Clone + Rng> Clone for TruncatedEig<A, R>
sourcefn clone(&self) -> TruncatedEig<A, R>
fn clone(&self) -> TruncatedEig<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
sourceimpl<A: NdFloat + Sum, R: Rng> IntoIterator for TruncatedEig<A, R>
impl<A: NdFloat + Sum, R: Rng> IntoIterator for TruncatedEig<A, R>
type Item = (ArrayBase<OwnedRepr<A>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<A>, Dim<[usize; 2]>>)
type Item = (ArrayBase<OwnedRepr<A>, Dim<[usize; 1]>>, ArrayBase<OwnedRepr<A>, Dim<[usize; 2]>>)
The type of the elements being iterated over.
type IntoIter = TruncatedEigIterator<A, R>
type IntoIter = TruncatedEigIterator<A, R>
Which kind of iterator are we turning this into?
sourcefn into_iter(self) -> TruncatedEigIterator<A, R>ⓘNotable traits for TruncatedEigIterator<A, R>impl<A: NdFloat + Sum, R: Rng> Iterator for TruncatedEigIterator<A, R> type Item = (Array1<A>, Array2<A>);
fn into_iter(self) -> TruncatedEigIterator<A, R>ⓘNotable traits for TruncatedEigIterator<A, R>impl<A: NdFloat + Sum, R: Rng> Iterator for TruncatedEigIterator<A, R> type Item = (Array1<A>, Array2<A>);
Creates an iterator from a value. Read more
Auto Trait Implementations
impl<A, R> RefUnwindSafe for TruncatedEig<A, R> where
A: RefUnwindSafe,
R: RefUnwindSafe,
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> 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