bnmf-algs
Public Member Functions | List of all members
bnmf_algs::details::SampleOnesReplaceComputer< Scalar > Class Template Reference

Computer type that will compute the next sample from a given matrix with replacement when its operator() is invoked. More...

#include <sampling.hpp>

Public Member Functions

 SampleOnesReplaceComputer (const matrix_t< Scalar > &X)
 Construct a new SampleOnesComputer. More...
 
void operator() (size_t curr_step, std::pair< int, int > &prev_val)
 Function call operator that will compute the next sample in-place. More...
 

Detailed Description

template<typename Scalar>
class bnmf_algs::details::SampleOnesReplaceComputer< Scalar >

Computer type that will compute the next sample from a given matrix with replacement when its operator() is invoked.

SampleOnesNoReplaceComputer will generate the next std::pair<int, int> value from the previous value passed to its operator(). This operation is performed in-place.

When computing the next sample, a simple inverse CDF sampling technique is used. Given matrix is thought of as a single dimensional array and its entries are considered as values of a probability mass function. Cumulative distribution of PMF is calculated in the constructor. At each call to operator(), index of the sample is found using binary search.

Template Parameters
ScalarType of the matrix entries that will be sampled.

Constructor & Destructor Documentation

template<typename Scalar >
bnmf_algs::details::SampleOnesReplaceComputer< Scalar >::SampleOnesReplaceComputer ( const matrix_t< Scalar > &  X)
inlineexplicit

Construct a new SampleOnesComputer.

This method constructs the data structures to use during sampling procedure. In particular, a cumulative probability array is calculated in linear time.

Parameters
XMatrix \(X\) that will be used during sampling.
Remarks
Time complexity is \(O(N)\) where \(N\) is the number of entries of matrix parameter X.

Member Function Documentation

template<typename Scalar >
void bnmf_algs::details::SampleOnesReplaceComputer< Scalar >::operator() ( size_t  curr_step,
std::pair< int, int > &  prev_val 
)
inline

Function call operator that will compute the next sample in-place.

After this function exits, the object referenced by prev_val will be modified to store the next sample. To read a general description of sampling procedure, refer to class documentation.

Note that SampleOnesComputer object satisfies the bnmf_algs::util::Generator and bnmf_algs::util::ComputationIterator Computer interface. Hence, a sequence of samples may be generated efficiently by using this Computer with bnmf_algs::util::Generator or bnmf_algs::util::ComputationIterator.

Parameters
curr_stepCurrent step of the sampling computation.
prev_valPreviously sampled value to modify in-place.
Remarks
Time complexity is \(O(N)\) where \(N\) is the number of entries of matrix parameter X.

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