| 
    AIToolbox
    
   A library that offers tools for AI problem solving. 
   | 
 
 
 
 
Go to the documentation of this file.    1 #ifndef AI_TOOLBOX_UTILS_PROBABILITY_HEADER_FILE 
    2 #define AI_TOOLBOX_UTILS_PROBABILITY_HEADER_FILE 
   40         for (
size_t i = 0; i < size; ++i) {
 
   41             const double value = 
static_cast<double>(in[i]);
 
   42             if (value < 0.0) 
return false;
 
   76     bool isProbability(
const size_t rows, 
const size_t cols, 
const T & in) {
 
   77         for (
size_t row = 0; row < rows; ++row)
 
  108     template <
typename T>
 
  109     bool isProbability(
const size_t depth, 
const size_t rows, 
const size_t cols, 
const T & in) {
 
  110         for (
size_t d = 0; d < depth; ++d)
 
  187     template <
typename T, 
typename G>
 
  191         for ( 
size_t i = 0; i < d; ++i ) {
 
  192             if ( in[i] > p ) 
return i;
 
  220     template <
typename G>
 
  224         for ( SparseMatrix2D::ConstRowXpr::InnerIterator i(in, 0); ; ++i ) {
 
  225             if ( i.value() > p ) 
return i.col();
 
  249     template <
typename G>
 
  251         std::gamma_distribution<double> dista(a, 1.0);
 
  252         std::gamma_distribution<double> distb(b, 1.0);
 
  253         const auto X = dista(generator);
 
  254         const auto Y = distb(generator);
 
  269     template <
typename TIn, 
typename G>
 
  289     template <
typename TIn, 
typename TOut, 
typename G>
 
  291         assert(params.size() == out.size());
 
  294         for (
size_t i = 0; i < static_cast<size_t>(params.size()); ++i) {
 
  295             std::gamma_distribution<double> dist(params[i], 1.0);
 
  296             out[i] = dist(generator);
 
  315     template <
typename G>
 
  318         double * bData = b.data();
 
  335         for ( 
size_t s = 0; s < S-1; ++s )
 
  339         std::sort(bData, bData + S - 1);
 
  343         double helper1 = bData[0], helper2;
 
  344         for ( 
size_t s = 1; s < S - 1; ++s ) {
 
  350         bData[S-1] = 1.0 - helper1;
 
  370         const auto size = lhs.size();
 
  371         for (
auto i = 0; i < size; ++i)
 
  385         return (v.array() * v.array().log()).sum();
 
  396         double entropy = 0.0;
 
  397         for (
auto i = 0; i < v.size(); ++i)
 
  398             entropy += v[i] * std::log2(v[i]);
 
  452             template <
typename G>
 
  454                 const auto x = sampleDistribution_(generator);
 
  456                 const auto y = x - i;
 
  458                 if (y < prob_[i]) 
return i;
 
  464             std::vector<size_t> alias_;
 
  465             mutable std::uniform_real_distribution<double> sampleDistribution_;