bnmf-algs
|
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... | |
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.
Scalar | Type of the matrix entries that will be sampled. |
|
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.
X | Matrix \(X\) that will be used during sampling. |
|
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.
curr_step | Current step of the sampling computation. |
prev_val | Previously sampled value to modify in-place. |