RandFunm¶
Solver¶
-
template<typename MatType, int Flags, typename RandomEngine>
class RandFunm : public mocca::internal::Solver<RandFunm<MatType, Flags, RandomEngine>>¶ A solver for calculating a matrix function \(f(\gamma \mathbf{A})\) using a random set of rows and columns of the matrix. Any matrix function is supported as long as it can be represented as a power series:
\[ f(\gamma \mathbf{A}) = \sum_{k = 0}^\infty{c_k (\gamma \mathbf{A})^k} \]After initializing the solver, call the
funm()
method to calculate the desired matrix function. You can use either the built-in functions (mittag_leffler
,expm
andinverse
) or provide a function object that receive the value \( k \) and returns the coefficient \( c_k \).If you only need the diagonal of the matrix function, you call the
funm_diag()
method instead. Likewise, providing a vector to thefunm()
method will compute the action of the matrix function over this vector. Both routines are more efficient than computing the full matrix function and then extract its diagonal or multiplying by the target vector.Template Parameters:
Flags
- Additional flags for the solver. See MonteCarloFlags for more information.RandomEngine
- Type of the Random Number Generator
Public Functions
-
inline explicit RandFunm(RandFunmOptions param = RandFunmOptions())¶
Initialize a RandFunm solver with the parameters
param
.Complexity: Constant
- Parameters:
param – [in] parameters of the solver (see RandFunmOptions for all the available parameters)
-
inline explicit RandFunm(MatType &A, RandFunmOptions param = RandFunmOptions())¶
Initialize a RandFunm solver with the input matrix
A
and parametersparam
for further computing the matrix function \(f(\gamma \mathbf{A})\).Complexity: Constant
- Parameters:
A – [in] input matrix
param – [in] parameters of the solver (see RandFunmOptions for all the available parameters)
-
inline void set_param(RandFunmOptions param)¶
Set the parameters of the RandFunm solver.
Complexity: Constant
- Parameters:
param – [in] parameters of the solver (see RandFunmOptions for all the available parameters)
-
inline void set_matrix(MatType &A)¶
Initialize the RandFunm solver with the matrix
A
for further computing the matrix function \(f(\gamma \mathbf{A})\).- Parameters:
A – [in] input matrix Complexity: Constant
-
template<typename Func>
inline evaluator<internal::MatFuncFull> funm(Func func, value_type gamma)¶ Calculates the matrix function \(f(\gamma \mathbf{A})\).
- Parameters:
func – [in]
expm
,mittag_leffler(alpha)
,inverse
or a functor that receives a valuek
and returns the coefficient \( c_k\)result – [out] result matrix (dense)
gamma – [in] scale parameter
-
template<typename Func, internal::TypeLayout L>
inline evaluator<sparse_vec_ref, internal::MatFuncAction> funm(Func func, value_type gamma, SparseVector<value_type> &v)¶ Calculates the action of the matrix function \(f(\gamma \mathbf{A})\) over the vector \( \vec{v} \).
- Parameters:
func – [in]
expm
,mittag_leffler(alpha)
,inverse
or a functor that receives a valuek
and returns the coefficient \( c_k\)v – [in] input vector (dense or sparse)
result – [out] result vector (dense)
gamma – [in] scale parameter
-
template<typename Func>
inline evaluator<internal::MatFuncDiag> funm_diag(Func func, value_type gamma)¶ Calculates the diagonal of the matrix function \(f(\gamma \mathbf{A})\).
- Parameters:
func – [in]
expm
,mittag_leffler(alpha)
,inverse
or a functor that receives a valuek
and returns the coefficient \( c_k\)result – [out] diagonal of the matrix function stored as a dense vector
gamma – [in] scale parameter
-
template<typename Func, internal::TypeLayout L>
inline value_type funm_single(Func func, index_t idx, value_type gamma, Vector<value_type, L> &v)¶ Calculates a single entry of \(f(\gamma \mathbf{A})v\).
- Parameters:
func – [in]
expm
,mittag_leffler(alpha)
,inverse
or a functor that receives a valuek
and returns the coefficient \( c_k\)idx – [in] index of the entry of the solution to be calculated
v – [in] input vector
gamma – [in] scale parameter
- Returns:
the entry
i
of \(f(\gamma \mathbf{A})v\)
Options¶
-
struct RandFunmOptions¶
Options for the RandFunm solver.
Public Members
-
int max_num_terms = 100¶
Maximum number of terms in the Neumann Series.
-
double weight_cutoff = 1E-3¶
Weight tolerance. The Neumann series will be truncated when the weight of the random walk is less than this value
-
uint64_t seed = PCG32_DEFAULT_SEED¶
Indicate the random seed for the random number generator (PCG64).
-
uint64_t stream = PCG32_DEFAULT_STREAM¶
Indicate the random stream of the random number generator (PCG64).
-
int max_num_terms = 100¶