Kernel Quantum Probability Library
The KQP library aims at providing tools for working with quantums probabilities
Data Structures | Public Types | Public Member Functions | Static Public Member Functions
kqp::SparseDense< Scalar > Class Template Reference

A feature matrix where vectors are in a dense subspace (in the canonical basis). More...

#include <sparse_dense.hpp>

Inheritance diagram for kqp::SparseDense< Scalar >:
kqp::FeatureMatrixBase< Scalar >

Data Structures

struct  Insert
 
struct  KeyComparator
 

Public Types

typedef SparseDense< Scalar > Self
 
typedef std::map< Index, Index > RowMap
 

Public Member Functions

 KQP_SCALAR_TYPEDEFS (Scalar)
 
 SparseDense (Index dimension)
 
 SparseDense (const Self &other)
 
 SparseDense (Index dimension, RowMap &&map, ScalarMatrix &&matrix)
 
 SparseDense (const Eigen::SparseMatrix< Scalar, Eigen::ColMajor > &mat, double threshold=epsilon())
 Creates from a sparse matrix.
 
 SparseDense (const Eigen::SparseMatrix< Scalar, Eigen::RowMajor > &mat, double threshold=epsilon())
 Creates from a sparse matrix.
 
 SparseDense (const ScalarMatrix &mat, double threshold=Eigen::NumTraits< Scalar >::epsilon())
 Construct from a dense matrix.
 
ScalarMatrix toDense () const
 Converts to a dense matrix (mostly used for debug)
 
Index denseDimension () const
 Get the dense dimension.
 
void cleanup (Real threshold=epsilon())
 Cleanup the near zero entries.
 
virtual Index size () const
 
Index dimension () const
 
void add (const FMatrixBase &_other, const std::vector< bool > *which=NULL) override
 
const ScalarMatrix & gramMatrix () const
 
template<class DerivedMatrix >
void inner (const Self &other, DerivedMatrix &result) const
 Computes the inner product with another matrix.
 
FMatrixBasePtr linearCombination (const ScalarAltMatrix &mA, Scalar alpha, const Self *mY, const ScalarAltMatrix *mB, Scalar beta) const
 
FMatrixBasePtr subset (const std::vector< bool >::const_iterator &begin, const std::vector< bool >::const_iterator &end) const override
 Reduces the feature matrix to a subset of its vectors.
 
virtual FMatrixBasePtr copy () const override
 
Selfoperator= (const Self &other)
 
virtual FMatrixBase & operator= (const FMatrixBase &_other) override
 
const std::map< Index, Index > & map () const
 Get the sparse to dense map.
 
const ScalarMatrix & getMatrix () const
 Get the dense matrix.
 
template<typename Archive >
void serialize (Archive &ar, const unsigned int)
 
- Public Member Functions inherited from kqp::FeatureMatrixBase< Scalar >
 KQP_SCALAR_TYPEDEFS (Scalar)
 
FMatrixPtr subset (const std::vector< bool > &list) const
 Reduces the feature matrix to a subset of its vectors.
 
virtual FMatrixBase & operator= (const FeatureMatrixBase< Scalar > &other)=0
 
template<typename T >
const T & as () const
 
template<typename T >
T & as ()
 
void add (const FMatrixCPtr &f, const std::vector< bool > *which=NULL)
 

Static Public Member Functions

static FMatrixPtr create (const ScalarMatrix &m)
 Creates from a matrix.
 
static FMatrixPtr create (const Eigen::SparseMatrix< Scalar, Eigen::ColMajor > &m, double threshold=epsilon())
 Creates from a matrix (from a column major sparse matrix)
 
static FMatrixPtr create (const Eigen::SparseMatrix< Scalar, Eigen::RowMajor > &m, double threshold=epsilon())
 Creates from a matrix (from a row major sparse matrix)
 

Detailed Description

template<typename Scalar>
class kqp::SparseDense< Scalar >

A feature matrix where vectors are in a dense subspace (in the canonical basis).

This class makes the hypothesis that vectors have only a few non null components (compared to the dimensionality of the space), and that those components are mostly the same.

In practice, the matrix is a map from a row index to a vector (along with a count of the number of zeros), where each vector has a size less or equal to the number of columns of the sparse matrix.

Constructor & Destructor Documentation

template<typename Scalar >
kqp::SparseDense< Scalar >::SparseDense ( const ScalarMatrix &  mat,
double  threshold = Eigen::NumTraits<Scalar>::epsilon() 
)
inline

Construct from a dense matrix.

Discard rows where entries are neglectable (see the class documentation).

Parameters
matThe matrix to copy
thresholdThe threshold for a value to be neglectable

Member Function Documentation

template<typename Scalar >
void kqp::SparseDense< Scalar >::add ( const FMatrixBase &  f,
const std::vector< bool > *  which = NULL 
)
inlineoverridevirtual

Add pre-images vectors

Implements kqp::FeatureMatrixBase< Scalar >.

template<typename Scalar >
void kqp::SparseDense< Scalar >::cleanup ( Real  threshold = epsilon())
inline

Cleanup the near zero entries.

An entry of a vector is considered as zero if its ratio to the maximum magnitude component of the vectors is above a given threshold. If a full row is considered as below zero, it is removed.

Parameters
thresholdThe threshold above which a value is considered as zero
template<typename Scalar >
virtual FMatrixBasePtr kqp::SparseDense< Scalar >::copy ( ) const
inlineoverridevirtual
template<typename Scalar >
virtual Index kqp::SparseDense< Scalar >::size ( ) const
inlinevirtual

Number of pre-image vectors

Implements kqp::FeatureMatrixBase< Scalar >.

template<typename Scalar >
FMatrixBasePtr kqp::SparseDense< Scalar >::subset ( const std::vector< bool >::const_iterator &  begin,
const std::vector< bool >::const_iterator &  end 
) const
inlineoverridevirtual

Reduces the feature matrix to a subset of its vectors.

The list of indices is supposed to be ordered.

Parameters
beginBeginning of the list of indices
endEnd of the list of indices

Implements kqp::FeatureMatrixBase< Scalar >.


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