mlpack
Public Member Functions | List of all members
mlpack::ann::BernoulliDistribution< DataType > Class Template Reference

Multiple independent Bernoulli distributions. More...

#include <bernoulli_distribution.hpp>

Public Member Functions

 BernoulliDistribution ()
 Default constructor, which creates a Bernoulli distribution with zero dimension.
 
 BernoulliDistribution (const DataType &param, const bool applyLogistic=true, const double eps=1e-10)
 Create multiple independent Bernoulli distributions whose p values are given by the param parameter. More...
 
double Probability (const DataType &observation) const
 Return the probabilities of the given matrix of observations. More...
 
double LogProbability (const DataType &observation) const
 Return the log probabilities of the given matrix of observations. More...
 
void LogProbBackward (const DataType &observation, DataType &output) const
 Stores the gradient of the log probabilities of the observations in the output matrix. More...
 
DataType Sample () const
 Return a matrix of randomly generated samples according to the probability distributions defined by this object. More...
 
const DataType & Probability () const
 Return the probability matrix.
 
DataType & Probability ()
 Return a modifiable copy of the probability matrix.
 
const DataType & Logits () const
 Return the logits matrix.
 
DataType & Logits ()
 Return a modifiable copy of the pre probability matrix.
 
template<typename Archive >
void serialize (Archive &ar, const uint32_t)
 Serialize the distribution.
 

Detailed Description

template<typename DataType = arma::mat>
class mlpack::ann::BernoulliDistribution< DataType >

Multiple independent Bernoulli distributions.

Bernoulli distribution is the discrete probability distribution of a random variable which takes the value 1 with probability p and the value 0 with probability q = 1 - p. In this implementation, the p values of the distributions are given by the param matrix.

Template Parameters
DataTypeType of the input data. (arma::colvec, arma::mat, arma::sp_mat or arma::cube).

Constructor & Destructor Documentation

◆ BernoulliDistribution()

template<typename DataType >
mlpack::ann::BernoulliDistribution< DataType >::BernoulliDistribution ( const DataType &  param,
const bool  applyLogistic = true,
const double  eps = 1e-10 
)

Create multiple independent Bernoulli distributions whose p values are given by the param parameter.

Thus, we create nofRows * nofColumns distributions. The shape of the matrix of distributions is the same as the shape of the param matrix as each element of the param matrix parameterizes one Bernoulli distribution. This is used in the ANN module to define distribution for each feature in each batch, where number of features becomes nofRows and batch size becomes nofColumns.

applyLogistic has to be true if all the elements of param matrix are not in the range [0, 1].

Parameters
paramThe matrix of probabilities or pre probabilities of the multiple distributions.
applyLogisticIf true, we apply Logistic function to the param matrix (pre probability) to get probability.
epsThe minimum value used for computing logarithms and denominators.

Member Function Documentation

◆ LogProbability()

template<typename DataType >
double mlpack::ann::BernoulliDistribution< DataType >::LogProbability ( const DataType &  observation) const

Return the log probabilities of the given matrix of observations.

Parameters
observationThe observation matrix.

◆ LogProbBackward()

template<typename DataType >
void mlpack::ann::BernoulliDistribution< DataType >::LogProbBackward ( const DataType &  observation,
DataType &  output 
) const

Stores the gradient of the log probabilities of the observations in the output matrix.

Parameters
observationThe observation matrix.
outputThe output matrix where the gradients are stored.

◆ Probability()

template<typename DataType = arma::mat>
double mlpack::ann::BernoulliDistribution< DataType >::Probability ( const DataType &  observation) const
inline

Return the probabilities of the given matrix of observations.

Parameters
observationThe observation matrix.

◆ Sample()

template<typename DataType >
DataType mlpack::ann::BernoulliDistribution< DataType >::Sample ( ) const

Return a matrix of randomly generated samples according to the probability distributions defined by this object.

Returns
Matrix(integer) of random samples from the multiple Bernoulli distributions.

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