MADNESS 0.10.1
madness::LowRankFunction< T, NDIM, LDIM > Class Template Reference

LowRankFunction represents a hi-dimensional (NDIM) function as a sum of products of low-dimensional (LDIM) functions. More...

#include <lowrankfunction.h>

Inheritance diagram for madness::LowRankFunction< T, NDIM, LDIM >:
Collaboration diagram for madness::LowRankFunction< T, NDIM, LDIM >:

Public Member Functions

 LowRankFunction ()=default
 LowRankFunction (const LowRankFunction &other)
 shallow copy ctor
 LowRankFunction (std::vector< Function< T, LDIM > > g, std::vector< Function< T, LDIM > > h, double tol)
void cloud_load (World &world, const Cloud &cloud, Recordlist< Cloud::keyT > &recordlist)
 customized function to load this from the cloud
Recordlist< Cloud::keyT > cloud_store (World &world, Cloud &cloud) const
 customized function to store this to the cloud
std::vector< Function< T, LDIM > > get_functions (const particle< LDIM > &p) const
std::vector< Function< T, LDIM > > get_g () const
std::vector< Function< T, LDIM > > get_h () const
double l2error (const LRFunctorBase< T, NDIM > &lrfunctor1) const
 compute the l2 error |functor - \sum_i g_ih_i|_2
double l2error_pythagoras (double f_norm_sq) const
TensorTypeData< T >::scalar_type norm2 () const
 l2 norm
T operator() (const Vector< double, NDIM > &r) const
 function evaluation
template<typename Q>
LowRankFunction operator* (const Q a) const
 scale by a scalar
LowRankFunction operator* (const T a) const
 out-of-place scale by a scalar (no type conversion)
LowRankFunction & operator*= (const T a)
 in-place scale by a scalar (no type conversion)
LowRankFunction operator+ (const LowRankFunction &b) const
 addition
LowRankFunction & operator+= (const LowRankFunction &b)
 in-place addition
LowRankFunction operator- (const LowRankFunction &b) const
 subtraction
LowRankFunction & operator-= (const LowRankFunction &b)
 in-place subtraction
LowRankFunction & operator= (const LowRankFunction &f)
void optimize (const LRFunctorBase< T, NDIM > &lrfunctor1, const long nopt=1)
 optimize the lrf using the lrfunctor
void print_size (std::string msg="") const
Tensor< long > rank () const
Function< T, NDIM > reconstruct () const
 f(1,2) = \sum_i g_i(1) h_i(2)
void remove_linear_dependencies (double tol=-1.0)
void reorthonormalize ()
template<typename Archive>
void serialize (const Archive &ar)
 serialize to an archive (e.g. cloud or file)
double size () const
 return the size in GByte
World & world () const

Static Public Member Functions

static std::tuple< std::vector< Function< T, LDIM > >, Tensor< T >, Tensor< T > > rr_cholesky_matrix_and_reorder (const std::vector< Function< T, LDIM > > &v, Tensor< T > ovlp, const double tol)

Public Attributes

bool do_print =false
std::vector< Function< T, LDIM > > g
std::vector< Function< T, LDIM > > h
const particle< LDIM > p1 =particle<LDIM>::particle1()
const particle< LDIM > p2 =particle<LDIM>::particle2()
double rank_revealing_tol =1.e-8

Private Member Functions

std::vector< Function< T, LDIM > > orthonormalize (const std::vector< Function< T, LDIM > > &g) const
 orthonormalize the argument vector via rank-revealing Cholesky

Friends

LowRankFunction copy (const LowRankFunction &other)
 deep copy
hashT hash_value (const LowRankFunction< T, NDIM > &f)
LowRankFunction operator* (const T a, const LowRankFunction &other)
 multiplication with a scalar

Detailed Description

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
class madness::LowRankFunction< T, NDIM, LDIM >

LowRankFunction represents a hi-dimensional (NDIM) function as a sum of products of low-dimensional (LDIM) functions.

a LowRankFunction can be created from a hi-dim function directly, or from a composite like f(1,2) phi(1) psi(2), where f(1,2) is a two-particle function (e.g. a Slater function) the representation is canonical: f(1,2) = \sum_i g_i(1) h_i(2) for the time being we don't require g or h to be orthogonal or normalized

Constructor & Destructor Documentation

◆ LowRankFunction() [1/3]

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
madness::LowRankFunction< T, NDIM, LDIM >::LowRankFunction ( )
default

◆ LowRankFunction() [2/3]

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
madness::LowRankFunction< T, NDIM, LDIM >::LowRankFunction ( std::vector< Function< T, LDIM > > g,
std::vector< Function< T, LDIM > > h,
double tol )
inline

◆ LowRankFunction() [3/3]

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
madness::LowRankFunction< T, NDIM, LDIM >::LowRankFunction ( const LowRankFunction< T, NDIM, LDIM > & other)
inline

shallow copy ctor

References LowRankFunction(), g, h, and rank_revealing_tol.

Member Function Documentation

◆ cloud_load()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
void madness::LowRankFunction< T, NDIM, LDIM >::cloud_load ( World & world,
const Cloud & cloud,
Recordlist< Cloud::keyT > & recordlist )
inline

customized function to load this from the cloud

Parameters
[in,out]recordlistcontaining the keys of the member variables -> will be reduced by the keys which are used

References madness::Cloud::forward_load(), g, h, rank_revealing_tol, and world().

◆ cloud_store()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
Recordlist< Cloud::keyT > madness::LowRankFunction< T, NDIM, LDIM >::cloud_store ( World & world,
Cloud & cloud ) const
inline

customized function to store this to the cloud

will store g and h elements individually

References g, h, rank_revealing_tol, madness::Cloud::store(), and world().

◆ get_functions()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
std::vector< Function< T, LDIM > > madness::LowRankFunction< T, NDIM, LDIM >::get_functions ( const particle< LDIM > & p) const
inline

References g, h, MADNESS_CHECK, and p().

◆ get_g()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
std::vector< Function< T, LDIM > > madness::LowRankFunction< T, NDIM, LDIM >::get_g ( ) const
inline

◆ get_h()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
std::vector< Function< T, LDIM > > madness::LowRankFunction< T, NDIM, LDIM >::get_h ( ) const
inline

◆ l2error()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
double madness::LowRankFunction< T, NDIM, LDIM >::l2error ( const LRFunctorBase< T, NDIM > & lrfunctor1) const
inline

compute the l2 error |functor - \sum_i g_ih_i|_2

\int (f(1,2) - gh(1,2))^2 = \int f(1,2)^2 - 2\int f(1,2) gh(1,2) + \int gh(1,2)^2 since we are subtracting large numbers the numerics are sensitive, and NaN may be returned..

References madness::arg(), do_print, madness::timer::do_print, madness::error(), g, h, inner(), madness::inner(), matrix_inner(), madness::LRFunctorBase< T, NDIM, LDIM >::norm2(), p1, p2, print(), rank(), madness::timer::tag(), and world().

◆ l2error_pythagoras()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
double madness::LowRankFunction< T, NDIM, LDIM >::l2error_pythagoras ( double f_norm_sq) const
inline

Cheap relative L2 error via Pythagoras (canonical form only).

When h is orthonormal AND g is the reprojection of h (g_k = <f(r1,r2) | h_k(r2)>_{r2}), the following identity holds: ||f - sum_k g_k h_k||^2 = ||f||^2 - sum_k ||g_k||^2 (cross and self terms collapse to the same sum_k ||g_k||^2). No functor applications are needed — only norms of the stored g.

Parameters
[in]f_norm_sqprecomputed ||f||^2 (typically lrfunctor.norm2()^2)
Precondition
the LRF is in canonical form and g holds the reprojected factors.

References madness::arg(), g, MADNESS_CHECK_THROW, and madness::norm2s().

Referenced by madness::LowRankFunctionFactory< T, NDIM, LDIM >::project_stable().

◆ norm2()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
TensorTypeData< T >::scalar_type madness::LowRankFunction< T, NDIM, LDIM >::norm2 ( ) const
inline

l2 norm

References g, h, matrix_inner(), and world().

◆ operator()()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
T madness::LowRankFunction< T, NDIM, LDIM >::operator() ( const Vector< double, NDIM > & r) const
inline

function evaluation

References g, and h.

◆ operator*() [1/2]

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
template<typename Q>
LowRankFunction madness::LowRankFunction< T, NDIM, LDIM >::operator* ( const Q a) const
inline

scale by a scalar

References LowRankFunction(), a, g, h, NDIM, Q(), and rank_revealing_tol.

◆ operator*() [2/2]

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
LowRankFunction madness::LowRankFunction< T, NDIM, LDIM >::operator* ( const T a) const
inline

out-of-place scale by a scalar (no type conversion)

References LowRankFunction(), a, g, h, and rank_revealing_tol.

◆ operator*=()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
LowRankFunction & madness::LowRankFunction< T, NDIM, LDIM >::operator*= ( const T a)
inline

in-place scale by a scalar (no type conversion)

References LowRankFunction(), a, and g.

◆ operator+()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
LowRankFunction madness::LowRankFunction< T, NDIM, LDIM >::operator+ ( const LowRankFunction< T, NDIM, LDIM > & b) const
inline

addition

References LowRankFunction(), b, and copy().

◆ operator+=()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
LowRankFunction & madness::LowRankFunction< T, NDIM, LDIM >::operator+= ( const LowRankFunction< T, NDIM, LDIM > & b)
inline

in-place addition

References LowRankFunction(), madness::append(), b, copy(), g, and h.

◆ operator-()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
LowRankFunction madness::LowRankFunction< T, NDIM, LDIM >::operator- ( const LowRankFunction< T, NDIM, LDIM > & b) const
inline

subtraction

References LowRankFunction(), b, and copy().

◆ operator-=()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
LowRankFunction & madness::LowRankFunction< T, NDIM, LDIM >::operator-= ( const LowRankFunction< T, NDIM, LDIM > & b)
inline

in-place subtraction

References LowRankFunction(), madness::append(), b, copy(), g, and h.

◆ operator=()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
LowRankFunction & madness::LowRankFunction< T, NDIM, LDIM >::operator= ( const LowRankFunction< T, NDIM, LDIM > & f)
inline

◆ optimize()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
void madness::LowRankFunction< T, NDIM, LDIM >::optimize ( const LRFunctorBase< T, NDIM > & lrfunctor1,
const long nopt = 1 )
inline

optimize the lrf using the lrfunctor

Parameters
[in]noptnumber of iterations (wrt to Alg. 4.3 in Halko)

References do_print, madness::timer::do_print, g, h, inner(), orthonormalize(), p1, p2, madness::timer::tag(), truncate(), and world().

Referenced by madness::CCPairFunction< T, NDIM >::op_dec_to_dec().

◆ orthonormalize()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
std::vector< Function< T, LDIM > > madness::LowRankFunction< T, NDIM, LDIM >::orthonormalize ( const std::vector< Function< T, LDIM > > & g) const
inlineprivate

orthonormalize the argument vector via rank-revealing Cholesky

References g, g2(), madness::FunctionDefaults< NDIM >::get_thresh(), matrix_inner(), madness::orthonormalize_rrcd(), rank_revealing_tol, and truncate().

◆ print_size()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
void madness::LowRankFunction< T, NDIM, LDIM >::print_size ( std::string msg = "") const
inline

References g, print(), rank(), size(), and world().

◆ rank()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
Tensor< long > madness::LowRankFunction< T, NDIM, LDIM >::rank ( ) const
inline

References g, h, and MADNESS_ASSERT.

Referenced by l2error(), print_size(), and rr_cholesky_matrix_and_reorder().

◆ reconstruct()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
Function< T, NDIM > madness::LowRankFunction< T, NDIM, LDIM >::reconstruct ( ) const
inline

f(1,2) = \sum_i g_i(1) h_i(2)

References g, h, madness::hartree_product(), and MADNESS_ASSERT.

Referenced by test_recursive_apply().

◆ remove_linear_dependencies()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
void madness::LowRankFunction< T, NDIM, LDIM >::remove_linear_dependencies ( double tol = -1.0)
inline

remove linear dependencies in g and h; result stays in canonical form f(1,2) = \sum_i g_i(1) h_i(2) {g} and {h} are not necessarily orthogonal, but they are linearly independent

References g, h, inner(), matrix_inner(), rank_revealing_tol, rr_cholesky_matrix_and_reorder(), transform(), and world().

Referenced by reorthonormalize().

◆ reorthonormalize()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
void madness::LowRankFunction< T, NDIM, LDIM >::reorthonormalize ( )
inline

◆ rr_cholesky_matrix_and_reorder()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
std::tuple< std::vector< Function< T, LDIM > >, Tensor< T >, Tensor< T > > madness::LowRankFunction< T, NDIM, LDIM >::rr_cholesky_matrix_and_reorder ( const std::vector< Function< T, LDIM > > & v,
Tensor< T > ovlp,
const double tol )
inlinestatic

perform RRCD on the overlap matrix of the functions, reorder the functions according to the pivoting, and return the upper triangular matrix from the Cholesky decomposition note: the rr_cholesky is more efficient than a full SVD for removing linear dependencies, but it does not give an orthonormal basis, so an additional orthonormalization step is needed if orthogonality is desired. To orthonormalize: auto [pv, X] = rr_cholesky_matrix_and_reorder(v,ovlp,tol); v_ortho=transform(world,pv,X); // v_ortho_i = sum_j v_j U_{ji}^(-1)

Parameters
[in]vthe input functions
[in]ovlpthe overlap matrix of the input functions, will be destroyed in-place by the rr_cholesky
[in]tolthe tolerance for linear dependence in the rr_cholesky
Returns
a tuple containing pv: reordered original, linearly-independent functions, X: the (r,r) transformation matrix from pv to orthonormalized functions: v_ortho_i = v_p X_pi = pv_j X_ji X_inv: its (r,p) "inverse" from original functions to orthonormalized functions: v_p = v_ortho_i X_inv_ip note that X is not the inverse of X_inv, that would be X_full but v_p(x) = pv_i(x) X_ij X_inv_jp is numerically the same

References madness::_(), copy(), madness::BaseTensor::dim(), madness::inverse(), rank(), madness::rr_cholesky(), and v.

Referenced by madness::LowRankFunctionFactory< T, NDIM, LDIM >::project_from_Y_stable(), madness::LowRankFunctionFactory< T, NDIM, LDIM >::project_stable(), and remove_linear_dependencies().

◆ serialize()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
template<typename Archive>
void madness::LowRankFunction< T, NDIM, LDIM >::serialize ( const Archive & ar)
inline

serialize to an archive (e.g. cloud or file)

References e(), g, h, MADNESS_EXCEPTION, and rank_revealing_tol.

◆ size()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
double madness::LowRankFunction< T, NDIM, LDIM >::size ( ) const
inline

return the size in GByte

References g, madness::get_size(), h, and world().

Referenced by print_size().

◆ world()

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
World & madness::LowRankFunction< T, NDIM, LDIM >::world ( ) const
inline

◆ copy

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
LowRankFunction copy ( const LowRankFunction< T, NDIM, LDIM > & other)
friend

deep copy

References LowRankFunction(), madness::copy(), g, h, and rank_revealing_tol.

◆ hash_value

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
hashT hash_value ( const LowRankFunction< T, NDIM > & f)
friend

◆ operator*

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
LowRankFunction operator* ( const T a,
const LowRankFunction< T, NDIM, LDIM > & other )
friend

multiplication with a scalar

References LowRankFunction(), and a.

Member Data Documentation

◆ do_print

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
bool madness::LowRankFunction< T, NDIM, LDIM >::do_print =false

Referenced by l2error(), operator=(), and optimize().

◆ g

◆ h

◆ p1

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
const particle<LDIM> madness::LowRankFunction< T, NDIM, LDIM >::p1 =particle<LDIM>::particle1()

Referenced by l2error(), and optimize().

◆ p2

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
const particle<LDIM> madness::LowRankFunction< T, NDIM, LDIM >::p2 =particle<LDIM>::particle2()

Referenced by l2error(), and optimize().

◆ rank_revealing_tol

template<typename T, std::size_t NDIM, std::size_t LDIM = NDIM/2>
double madness::LowRankFunction< T, NDIM, LDIM >::rank_revealing_tol =1.e-8

The documentation for this class was generated from the following file: