KJB
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
prob_distribution.h
Go to the documentation of this file.
1 /* ======================================================================== *
2  | |
3  | Copyright (c) 2007-2010, by members of University of Arizona Computer |
4  | Vision group (the authors) including |
5  | Kobus Barnard, Kyle Simek, Ernesto Brau. |
6  | |
7  | For use outside the University of Arizona Computer Vision group please |
8  | contact Kobus Barnard. |
9  | |
10  * ======================================================================== */
11 
12 /* $Id: prob_distribution.h 18558 2015-02-13 21:13:12Z jguan1 $ */
13 
14 #ifndef PROB_DISTRIBUTION_H_INCLUDED
15 #define PROB_DISTRIBUTION_H_INCLUDED
16 
34 #include <boost/version.hpp>
35 #include <boost/math/distributions.hpp>
36 #include <boost/math/distributions/inverse_gamma.hpp>
37 #include <boost/math/distributions/negative_binomial.hpp>
38 #include <map>
39 #include <cmath>
40 #include <vector>
41 #include "prob_cpp/prob_util.h"
42 #include "m_cpp/m_vector.h"
43 #include "m_cpp/m_vector_d.h"
44 #include "m_cpp/m_matrix.h"
45 #include "n_cpp/n_cholesky.h"
46 #include "l_cpp/l_exception.h"
47 #include "l_cpp/l_std_parallel.h"
48 
49 #include "g/g_area.h"
50 #include "g_cpp/g_quaternion.h"
51 
52 namespace kjb{
53 
54 /*============================================================================
55  These distributions are part of the boost-math library, defined in
56  boost/math/distributions.hpp. See boost's documentation for details.
57  They are typdef'd to match the naming scheme of the KJB
58  ----------------------------------------------------------------------------*/
59 
60 typedef boost::math::bernoulli Bernoulli_distribution;
61 typedef boost::math::beta_distribution<> Beta_distribution;
62 typedef boost::math::binomial Binomial_distribution;
63 typedef boost::math::chi_squared Chi_square_distribution;
64 typedef boost::math::exponential Exponential_distribution;
65 typedef boost::math::gamma_distribution<> Gamma_distribution;
66 typedef boost::math::normal Gaussian_distribution;
67 typedef boost::math::laplace Laplace_distribution;
68 typedef boost::math::normal Normal_distribution;
69 typedef boost::math::poisson Poisson_distribution;
70 typedef boost::math::uniform Uniform_distribution;
71 typedef boost::math::inverse_gamma_distribution<> Inverse_gamma_distribution;
72 
73 // standard normal distribution
75 
76 #if BOOST_VERSION >= 104600
77 typedef boost::math::geometric_distribution<double> Geometric_distribution;
78 #else
79 class Geometric_distribution : public boost::math::negative_binomial
80 {
81 public:
83  boost::math::negative_binomial(1, p)
84  { }
85 };
86 #endif
87 
88 /* \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ */
90 {
91 public:
92  Beta_binomial_distribution(size_t n_, double alpha_, double beta_) :
93  n(n_), alpha(alpha_), beta(beta_)
94  { }
95 
96  double n, alpha, beta;
97 };
98 
99 /* \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ */
100 
108 template<class Distribution>
110 {
111  typedef double type;
112 };
113 
114 /*============================================================================
115  The following are univariate distributions that are not present in the
116  boost library.
117  ----------------------------------------------------------------------------*/
118 
130 template<class T = int>
132 {
134  typedef std::pair<const T*, double> Cdf_pair;
135  typedef typename std::map<T, double>::value_type Map_pair;
136 
137 public:
140  db(),
141  cdf_(),
142  total_weight_(0)
143  {}
144 
151  Categorical_distribution(const std::vector<double>& ps, const T& t1 = T(1));
152 
159  Categorical_distribution(const Vector& ps, const T& = T(1));
160 
168  (
169  const std::vector<T>& values,
170  const std::vector<double>& probabilities
171  );
172 
182  /*template <class Value_iterator, class Prob_iterator>
183  Categorical_distribution
184  (
185  Value_iterator values_begin,
186  Value_iterator values_end,
187  Prob_iterator probabilities_begin
188  );*/
189 
197  Categorical_distribution(const std::map<T, double>& d) : db(d)
198  {
199  init_cdf_();
200  }
201 
208  Categorical_distribution(const std::map<T, size_t>& m)
209  {
210  for(typename std::map<T,size_t>::const_iterator it = m.begin();
211  it != m.end(); ++it)
212  {
213  db[it->first] = static_cast<double>(it->second);
214  }
215  init_cdf_();
216  }
217 
229  Categorical_distribution(const T& min, const T& max, const T& step);
230 
239  Categorical_distribution(const T& x1, const T& x2, double p1, double p2)
240  {
241  db[x1] = p1;
242  db[x2] = p2;
243  init_cdf_();
244  }
245 
248  db(cd.db)
249  {
250  init_cdf_();
251  }
252 
255  {
256  if(this != &cd)
257  {
258  db = cd.db;
259  init_cdf_();
260  }
261 
262  return *this;
263  }
264 
278  const std::map<T, double>& log_map
279  )
280  {
281  typedef typename std::map<T, double>::value_type Pair;
283 
284  result.db = log_map;
285 
286  // get the sum of the log-weights, without leaving log space, which mitigates precision loss
287  // when weights are very small.
288 
289  std::vector<double> log_probs;
290  log_probs.reserve(log_map.size());
291 
292  typedef typename std::map<T,double>::const_iterator iterator;
293  for(iterator it = log_map.begin(); it != log_map.end(); ++it)
294  {
295  log_probs.push_back(it->second);
296  }
297 
298  double log_total = kjb::log_sum(log_probs.begin(), log_probs.end());
299 
300  // normalize by subtracting log-total. then exponentiate to get out of log-space
301  for(iterator it = result.db.begin(); it != result.db.end(); ++it)
302  it->second = exp(it->second - log_total);
303 
304  // TODO: init_cdf_ re-normalizes here; would be nice to factor the normalization
305  // bits out of init_cdf_. Note: we can't avoid normalizing above, because if we don't
306  // we risk losing precision when exponentiating.
307  result.init_cdf_();
308  return result;
309  }
310 
316  size_t size() const
317  {
318  return db.size();
319  }
320 
328  void erase(const T& key)
329  {
330  size_t count = db.erase(key);
331  if(count == 0)
332  KJB_THROW_2(Illegal_argument, "Key not found");
333  init_cdf_();
334  }
335 
341  void remove(const T& key)
342  {
343  erase(key);
344  }
345 
354  void insert (const T& key, double weight = 1.0)
355  {
356  size_t count = db.count(key);
357  if(count > 0)
358  KJB_THROW_2(Illegal_argument, "Key collision");
359 
360  const T* stored_key = &db.insert(std::make_pair(key, weight)).first->first;
361 
362  if(cdf_.empty())
363  total_weight_ = weight;
364  else
365  total_weight_ += weight;
366 
367  cdf_.push_back(Cdf_pair(stored_key, total_weight_));
368  }
369 
375  void add(const T& key, double weight = 1.0)
376  {
377  insert(key, weight);
378  }
379 
381  {}
382 
383  // friends functions; these need to be friends because they
384  // access the private parts
385  template<class U>
386  friend double pdf(const Categorical_distribution<U>& dist, const U& x);
387 
388  template<class U>
389  friend double cdf(const Categorical_distribution<U>& dist, const U& x);
390 
391  template<class U>
392  friend U sample(const Categorical_distribution<U>& dist);
393 
394 private:
395 
396  void init_cdf_()
397  {
398  using namespace boost;
399 
400  cdf_.resize(db.size());
401  if(cdf_.size() == 0) return;
402 
403  //typedef typename std::map<T, double>::const_iterator Const_iterator;
404 
405  // copy into cdf
406  kjb_parallel_std::transform(
407  db.begin(),
408  db.end(),
409  cdf_.begin(),
410  make_cdf_pair()
411  );
412 
413  // convert pdf values into cdf values
414  kjb_parallel_std::partial_sum(
415  cdf_.begin(),
416  cdf_.end(),
417  cdf_.begin(),
418  partial_sum_second<Cdf_pair>()
419  );
420 
421  total_weight_ = cdf_.back().second;
422 
423  // ensure that at least one element had significant mass,
424  // so we can normalize the masses
425  if(total_weight_ < FLT_EPSILON)
426  {
427  KJB_THROW_2(Illegal_argument, "Items have zero probability mass.");
428  }
429 
430 
431  // normalize to 1.0
432  // update: we now store CDF unnormalized, to make dynamic
433  // adding of elements easier.
434 // kjb_parallel_std::for_each(
435 // cdf_.begin(),
436 // cdf_.end(),
437 // multiply_second_by_scalar<Cdf_pair>(1.0/total_weight_)
438 // );
439 
440  // update: we now store elements unnormalized, to make dynamic
441  // adding of elements easier.
442 // // normalize pdf map to 1.0
443 // kjb_parallel_std::for_each(
444 // db.begin(),
445 // db.end(),
446 // multiply_second_by_scalar<Map_pair>(1.0/cdf_.back().second)
447 // );
448  }
449 
450 
451  // utility functors
452  struct make_cdf_pair : public std::unary_function<Cdf_pair, const Map_pair&>
453  {
454  Cdf_pair operator()(const Map_pair& pair) const
455  {
456  return std::make_pair(&pair.first, pair.second);
457  }
458  };
459 
460  struct cdf_pair_less_than_scalar
461  {
462  bool operator()(const Cdf_pair& op1, double op2) const
463  {
464  return op1.second < op2;
465  }
466  };
467 
468  struct cdf_key_less_than_scalar
469  {
470  bool operator()(const Cdf_pair& op1, const T& op2) const
471  {
472  return op1.first < op2;
473  }
474  };
475 
476  template <class U>
477  struct multiply_second_by_scalar
478  {
479  multiply_second_by_scalar(double scalar) :
480  scalar_(scalar)
481  { }
482 
483  void operator()(U& in) const
484  {
485  in.second *= scalar_;
486  }
487  double scalar_;
488  };
489 
490 
491  template <class U>
492  struct partial_sum_second : public std::binary_function<U, const U&, const U&>
493  {
494  U operator()(const U& op1, const U& op2)
495  {
496  U result = op2;
497  result.second += op1.second;
498  return result;
499  }
500  };
501 private:
502  std::map<T, double> db;
503  std::vector<Cdf_pair> cdf_;
504  double total_weight_;
505 };
506 
507 /* non-inline member functions */
508 
509 /* \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ */
510 
511 template<class T>
513 (
514  const std::vector<double>& ps,
515  const T& t1
516 )
517 {
518  for(std::size_t i = 0; i < ps.size(); i++)
519  {
520  db[static_cast<T>(i + t1)] = ps[i];
521  }
522  init_cdf_();
523 }
524 
525 /* \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ */
526 
527 template<class T>
529 (
530  const Vector& ps,
531  const T& t1
532 )
533 {
534  for(int i = 0; i < ps.get_length(); i++)
535  {
536  db[static_cast<T>(i + t1)] = ps[i];
537  }
538  init_cdf_();
539 }
540 
541 
542 /* \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ */
543 
544 template <class T>
546 (
547  const std::vector<T>& values,
548  const std::vector<double>& probabilities)
549 {
550  for(std::size_t i = 0; i < probabilities.size(); i++)
551  {
552  db[values[i]] = probabilities[i];
553  }
554  init_cdf_();
555 }
556 
557 /* \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ */
558 
559 /*template <class T>
560 template <class Value_iterator, class Prob_iterator>
561 Categorical_distribution<T>::Categorical_distribution
562 (
563  Value_iterator values_begin,
564  Value_iterator values_end,
565  Prob_iterator probabilities_begin)
566 {
567  Prob_iterator prob_it = probabilities_begin;
568  for(Value_iterator it = values_begin; it != values_end; ++it, ++prob_it)
569  {
570  db[*it] = *prob_it;
571  }
572  init_cdf_();
573 }*/
574 
575 /* \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ */
576 
577 template<class T>
579 (
580  const T& min,
581  const T& max,
582  const T& step
583 )
584 {
585  double p = 1.0 / static_cast<int>((max - min + 1) / step);
586  for(T x = min; x <= max; x += step)
587  {
588  db[x] = p;
589  }
590  init_cdf_();
591 }
592 
593 
597 template<class T>
599 {
600  typedef T type;
601 };
602 
603 /*============================================================================
604  The following are multivariate distributions that are not present in the
605  boost library.
606  ----------------------------------------------------------------------------*/
607 
608 // forward declarations -- ignore
610 template<class T, class G, class F> class Conditional_distribution;
613 
620 {
621 public:
622 
630  mean(d, 0.0),
631  cov_mat(create_identity_matrix(d)),
632  type(INDEPENDENT),
633  abs_det(1.0),
634  log_abs_det(0.0)
635  {}
636 
645  MV_gaussian_distribution(const Vector& mu, const Matrix& sigma) :
646  mean(mu),
647  cov_mat(sigma),
648  type(NORMAL),
649  abs_det(-1.0),
650  log_abs_det(-std::numeric_limits<double>::max())
651  {
652  IFT(mean.get_length() == cov_mat.get_num_rows()
653  && cov_mat.get_num_rows() == cov_mat.get_num_cols(),
655  "Mean vector dimension must equal covariance matrix's"
656  "number of rows and columns.");
657  }
658 
666  MV_gaussian_distribution(const Vector& mu, const Vector& sigma_diag) :
667  mean(mu),
668  cov_mat(create_diagonal_matrix(sigma_diag)),
669  type(INDEPENDENT),
670  abs_det(-1.0),
671  log_abs_det(-std::numeric_limits<double>::max())
672  {
673  IFT(mean.get_length() == cov_mat.get_num_rows(), Dimension_mismatch,
674  "Mean vector dimension must equal covariance matrix's"
675  "number of rows and columns.");
676  }
677 
681  const Vector& get_mean() const
682  {
683  return mean;
684  }
685 
690  {
691  return cov_mat;
692  }
693 
697  void set_mean(const Vector& m)
698  {
699  IFT(cov_mat.get_num_rows() == m.get_length(), Illegal_argument,
700  "mean vector must have same size as covariance matrix.");
701 
702  mean = m;
703  }
704 
709  {
710  IFT(S.get_num_rows() == mean.get_length(), Illegal_argument,
711  "mean vector must have same size as covariance matrix.");
712 
713  type = NORMAL;
714 
715  cov_mat = S;
716  cov_inv.resize(0, 0);
717  cov_chol.resize(0, 0);
718  abs_det = -1;
719  log_abs_det = -std::numeric_limits<double>::max();
720  }
721 
725  void set_covariance_matrix(const Matrix& S, const Vector& m)
726  {
728  "mean vector must have same size as covariance matrix.");
729 
730  type = NORMAL;
731 
732  mean = m;
733  cov_mat = S;
734  cov_inv.resize(0, 0);
735  cov_chol.resize(0, 0);
736  abs_det = -1;
737  log_abs_det = -std::numeric_limits<double>::max();
738  }
739 
743  int get_dimension() const
744  {
745  return mean.get_length();
746  }
747 
752  MV_gaussian_conditional_distribution conditional(int i) const;
753 
754 private:
758  void update_cov_inv() const
759  {
760  if(cov_inv.get_num_rows() == 0)
761  {
762  cov_inv = matrix_inverse(cov_mat);
763  }
764  }
765 
769  void update_cov_chol() const
770  {
771  if(cov_chol.get_num_rows() == 0)
772  {
773  cov_chol = cholesky_decomposition(cov_mat);
774  }
775  }
776 
780  void update_abs_det() const
781  {
782  if(abs_det == -1.0)
783  {
784  abs_det = cov_mat.abs_of_determinant();
785  }
786  }
787 
791  void update_log_abs_det() const;
792 
793  friend double pdf(const MV_gaussian_distribution&, const Vector&);
794 
795  friend double log_pdf(const MV_gaussian_distribution&, const Vector&);
796 
797  friend Vector sample(const MV_gaussian_distribution&);
798 
799 private:
800  Vector mean;
801  Matrix cov_mat;
802  int type;
803  mutable Matrix cov_inv;
804  mutable Matrix cov_chol;
805  mutable double abs_det;
806  mutable double log_abs_det;
807 
808  const static int NORMAL = 0;
809  const static int INDEPENDENT = 1;
810 };
811 
812 //We should also be able to call it normal distribution
814 
818 template<>
820 {
821  typedef Vector type;
822 };
823 
828 {
829 public:
831  dist_(0, 1)
832  {}
833 
834  Log_normal_distribution(double mu, double sigma) :
835  dist_(mu, sigma)
836  {}
837 
838  friend double pdf(const Log_normal_distribution&, double);
839 
840  friend double cdf(const Log_normal_distribution&, double);
841 
842  friend double sample(const Log_normal_distribution&);
843 private:
844  Normal_distribution dist_;
845 };
846 
847 template<>
849 {
850  typedef double type;
851 };
852 
853 
854 /*============================================================================
855  The following are other distributions (e.g., mixture).
856  ============================================================================*/
857 
866 template<class Distribution>
868 {
869 private:
870  // a convenient typedef
871  typedef typename Distribution_traits<Distribution>::type type;
872 
873 public:
874 
884  (
885  const std::vector<Distribution>& distributions,
886  const std::vector<double>& coefficients
887  ) :
888  dists(distributions), coeffs(coefficients)
889  {}
890 
898  Mixture_distribution(const std::vector<Distribution>& distributions) :
899  dists(distributions), coeffs(1.0, distributions.size(), 1.0)
900  {}
901 
910  (
911  const Distribution& dist1,
912  const Distribution& dist2,
913  double pi1
914  ) :
915  coeffs(1, 2, pi1, 1 - pi1)
916  {
917  dists.push_back(dist1);
918  dists.push_back(dist2);
919  }
920 
921  // friends functions; these need to be friends because they access
922  // the private parts (lol)
923  template<class Dist>
924  friend
925  double pdf
926  (
928  const typename Distribution_traits<Mixture_distribution<Dist> >::type& x
929  );
930 
931  template<class Dist>
932  friend
933  double cdf
934  (
936  const typename Distribution_traits<Mixture_distribution<Dist> >::type& x
937  );
938 
939  template<class Dist>
940  friend
943 
944 private:
945  std::vector<Distribution> dists;
947 };
948 
953 template<class Distribution>
955 {
957 };
958 
959 /* /////////////////////////////////////////////////////////////////////////// */
960 
965 template <size_t D>
967 {
968 public:
970 };
971 
975 template<size_t D>
977 {
978  typedef typename kjb::Vector_d<D> type;
979 };
980 
981 /* /////////////////////////////////////////////////////////////////////////// */
982 
983 template <size_t D>
985 {
986 public:
992  mu_(mean.normalized()),
993  kappa_(kappa)
994  {}
995 
996  const kjb::Vector_d<D>& mu() const { return mu_; }
997 
998  double kappa() const { return kappa_; }
999 
1000 private:
1001  kjb::Vector_d<D> mu_;
1002  double kappa_;
1003 }; // Von_mises_fisher_distribution
1004 
1008 template<size_t D>
1010 {
1011  typedef typename kjb::Vector_d<D> type;
1012 };
1013 
1014 /* \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ \/ */
1015 
1017 {
1018 public:
1019  typedef std::vector<std::vector<size_t> > Type;
1020 
1021 public:
1022  Chinese_restaurant_process(double concentration, size_t nc) :
1023  theta_(concentration), nc_(nc)
1024  {}
1025 
1026  double concentration() const { return theta_; }
1027  size_t num_customers() const { return nc_; }
1028 
1029 private:
1030  double theta_;
1031  double nc_;
1032 };
1033 
1034 template<>
1036 {
1038 };
1039 
1040 // useful typedef
1042 
1043 } //namespace kjb
1044 
1045 
1046 #endif /*PROB_DISTRIBUTION_H_INCLUDED */
1047 
Represents the dependence between X and Y in p(x | y), where (x,y) is a multivariate normal...
Definition: prob_conditional_distribution.h:246
Categorical_distribution< T > & operator=(const Categorical_distribution< T > &cd)
Assignment: needed to make sure init_cdf_ gets called.
Definition: prob_distribution.h:254
Matrix cholesky_decomposition(const Matrix &M)
Definition: n_cholesky.h:35
Definition for the Matrix class, a thin wrapper on the KJB Matrix struct and its related functionalit...
Int_matrix::Value_type max(const Int_matrix &mat)
Return the maximum value in this matrix.
Definition: l_int_matrix.h:1397
const kjb::Vector_d< D > & mu() const
Definition: prob_distribution.h:996
boost::math::bernoulli Bernoulli_distribution
Definition: prob_distribution.h:60
boost::math::chi_squared Chi_square_distribution
Definition: prob_distribution.h:63
const Matrix & get_covariance_matrix() const
Gets the covariance matrix of this distribution.
Definition: prob_distribution.h:689
double kappa() const
Definition: prob_distribution.h:998
std::vector< std::vector< size_t > > Type
Definition: prob_distribution.h:1019
MV_gaussian_distribution MV_normal_distribution
Definition: prob_distribution.h:813
Von_mises_fisher_distribution(const kjb::Vector_d< D > &mean, double kappa)
Definition: prob_distribution.h:991
int get_length() const
Return the length of the vector.
Definition: m_vector.h:501
Object thrown when an argument is of the wrong size or dimensions.
Definition: l_exception.h:426
double type
Definition: prob_distribution.h:850
int get_num_rows() const
Return the number of rows in the matrix.
Definition: m_matrix.h:543
This class implements a mixture distribution. In other words, it is the sum of a finite number of fra...
Definition: prob_distribution.h:867
boost::math::inverse_gamma_distribution Inverse_gamma_distribution
Definition: prob_distribution.h:71
Mixture_distribution(const std::vector< Distribution > &distributions)
Constructs a mixture distribution with equal mixing coefficients.
Definition: prob_distribution.h:898
double concentration() const
Definition: prob_distribution.h:1026
Int_matrix create_diagonal_matrix(const Int_matrix::Vec_type &diagonal)
Construct a one-row matrix by deep-copying a vector.
Definition: l_int_matrix.cpp:118
kjb::Vector_d< D > type
Definition: prob_distribution.h:1011
boost::math::poisson Poisson_distribution
Definition: prob_distribution.h:69
Log-normal distribution.
Definition: prob_distribution.h:827
boost::math::normal Gaussian_distribution
Definition: prob_distribution.h:66
Definition: prob_distribution.h:984
Uniform_sphere_distribution()
Definition: prob_distribution.h:969
This class implements vectors, in the linear-algebra sense, with real-valued elements.
Definition: m_vector.h:87
void add(const T &key, double weight=1.0)
Definition: prob_distribution.h:375
size_t size() const
Size of this distribution.
Definition: prob_distribution.h:316
Value_type mean(Iterator begin, Iterator end, const Value_type &)
Definition: prob_stat.h:56
Chinese_restaurant_process Crp
Definition: prob_distribution.h:1041
void set_covariance_matrix(const Matrix &S, const Vector &m)
Gets the covariance matrix of this distribution.
Definition: prob_distribution.h:725
~Categorical_distribution()
Definition: prob_distribution.h:380
A categorical distribution.
Definition: prob_distribution.h:131
double beta
Definition: prob_distribution.h:96
#define IFT(a, ex, msg)
Definition: l_exception.h:101
boost::math::laplace Laplace_distribution
Definition: prob_distribution.h:67
x1
Definition: APPgetLargeConnectedEdges.m:122
double dist(const pt a, const pt b)
compute approx. Great Circle distance between two UTM points
Definition: layer.cpp:45
Categorical_distribution(const std::map< T, size_t > &m)
Constructs an empirical distribution from a map of vals to counts.
Definition: prob_distribution.h:208
void set_covariance_matrix(const Matrix &S)
Gets the covariance matrix of this distribution.
Definition: prob_distribution.h:708
Matrix matrix_inverse(const Matrix &op1)
Invert this matrix.
Definition: m_matrix.cpp:730
MV_gaussian_distribution(const Vector &mu, const Matrix &sigma)
Constructs a multivariate Gaussian with a mean of mu and a covariance matrix of sigma. sigma must be positive-definite.
Definition: prob_distribution.h:645
Definition: prob_distribution.h:966
double n
Definition: prob_distribution.h:96
void insert(const T &key, double weight=1.0)
Definition: prob_distribution.h:354
int get_dimension() const
Gets the dimension of this distribution.
Definition: prob_distribution.h:743
Log_normal_distribution(double mu, double sigma)
Definition: prob_distribution.h:834
boost::math::beta_distribution Beta_distribution
Definition: prob_distribution.h:61
MV_normal_conditional_distribution MV_gaussian_conditional_distribution
Definition: prob_conditional_distribution.h:323
boost::math::exponential Exponential_distribution
Definition: prob_distribution.h:64
double type
Definition: prob_distribution.h:111
A conditional distribution.
Definition: prob_conditional_distribution.h:62
x
Definition: APPgetLargeConnectedEdges.m:100
Generic traits struct for all distributions.
Definition: prob_distribution.h:109
static Categorical_distribution< T > construct_from_log_map(const std::map< T, double > &log_map)
Definition: prob_distribution.h:277
const Gaussian_distribution STD_NORMAL
Definition: prob_distribution.cpp:12
double log_pdf(const MV_gaussian_distribution &P, const Vector &x)
Computes the log PDF a multivariate normal distribution at x.
Definition: prob_pdf.cpp:64
Multivariate Gaussian (normal) distribution.
Definition: prob_distribution.h:619
friend double cdf(const Categorical_distribution< U > &dist, const U &x)
Definition: prob_distribution.h:79
Matrix create_identity_matrix(int rank)
Construct an identity matrix of specified rank.
Definition: m_matrix.h:1795
Log_normal_distribution()
Definition: prob_distribution.h:830
boost::math::binomial Binomial_distribution
Definition: prob_distribution.h:62
#define KJB_THROW_2(ex, msg)
Definition: l_exception.h:48
count
Definition: APPgetLargeConnectedEdges.m:71
Chinese_restaurant_process::Type type
Definition: prob_distribution.h:1037
x2
Definition: APPgetLargeConnectedEdges.m:123
Various utility functions for probabiliity-related stuff.
Matrix & resize(int new_rows, int new_cols, Value_type pad=Value_type(0))
Resize this matrix, retaining previous values. Space is reused if possible. Otherwise requires a new ...
Definition: m_matrix.cpp:457
Beta_binomial_distribution(size_t n_, double alpha_, double beta_)
Definition: prob_distribution.h:92
Int_matrix::Value_type min(const Int_matrix &mat)
Return the minimum value in this matrix.
Definition: l_int_matrix.h:1385
boost::math::normal Normal_distribution
Definition: prob_distribution.h:68
Distribution_traits< Distribution >::type type
Definition: prob_distribution.h:956
Object thrown when an argument to a function is not acceptable.
Definition: l_exception.h:377
void erase(const T &key)
Definition: prob_distribution.h:328
Definition: g_quaternion.h:37
size_t num_customers() const
Definition: prob_distribution.h:1027
Categorical_distribution(const T &x1, const T &x2, double p1, double p2)
Creates a two-element categorical distribution.
Definition: prob_distribution.h:239
get the indices of edges in each direction for i
Definition: APPgetLargeConnectedEdges.m:48
Categorical_distribution(const std::map< T, double > &d)
Constructs a categorical distribution over a set of values.
Definition: prob_distribution.h:197
Geometric_distribution(double p)
Definition: prob_distribution.h:82
friend U sample(const Categorical_distribution< U > &dist)
This class implements matrices, in the linear-algebra sense, with real-valued elements.
Definition: m_matrix.h:94
const Vector & get_mean() const
Gets the mean of this distribution.
Definition: prob_distribution.h:681
boost::math::uniform Uniform_distribution
Definition: prob_distribution.h:70
for m
Definition: APPgetLargeConnectedEdges.m:64
D
Definition: APPgetLargeConnectedEdges.m:106
double log_sum(double n1, double n2)
Definition: prob_util.h:66
Support for error handling exception classes in libKJB.
Definition: prob_distribution.h:89
double alpha
Definition: prob_distribution.h:96
Categorical_distribution()
Construct an empty distribution.
Definition: prob_distribution.h:139
void set_mean(const Vector &m)
Gets the mean of this distribution.
Definition: prob_distribution.h:697
boost::math::gamma_distribution Gamma_distribution
Definition: prob_distribution.h:65
Definition for the Vector class, a thin wrapper on the KJB Vector struct and its related functionalit...
Vector type
Definition: prob_distribution.h:821
friend double pdf(const Categorical_distribution< U > &dist, const U &x)
MV_gaussian_distribution(int d)
Constructs a d-dimensinoal multivariate Gaussian with a mean of zero and a covariance matrix of ident...
Definition: prob_distribution.h:629
MV_gaussian_distribution(const Vector &mu, const Vector &sigma_diag)
Constructs a multivariate Gaussian with a mean of mu and a covariance matrix diag(sigma_diag).
Definition: prob_distribution.h:666
Definition: prob_distribution.h:1016
kjb::Vector_d< D > type
Definition: prob_distribution.h:978
Chinese_restaurant_process(double concentration, size_t nc)
Definition: prob_distribution.h:1022
Categorical_distribution(const Categorical_distribution< T > &cd)
Copy-ctor: needed to make sure init_cdf_ gets called.
Definition: prob_distribution.h:247