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>
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>
source§impl<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);
source§impl<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§
source§impl<A: Clone + NdFloat, R: Clone + Rng> Clone for TruncatedEig<A, R>
impl<A: Clone + NdFloat, R: Clone + Rng> Clone for TruncatedEig<A, R>
source§fn clone(&self) -> TruncatedEig<A, R>
fn clone(&self) -> TruncatedEig<A, R>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<A: NdFloat + Sum, R: Rng> IntoIterator for TruncatedEig<A, R>
impl<A: NdFloat + Sum, R: Rng> IntoIterator for TruncatedEig<A, R>
Auto Trait Implementations§
impl<A, R> Freeze for TruncatedEig<A, R>where
R: Freeze,
impl<A, R> RefUnwindSafe for TruncatedEig<A, R>where
R: RefUnwindSafe,
A: 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
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
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)
clone_to_uninit
)