A library for working with phylogenetic and population genetic data.
v0.32.0
binomial.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_UTILS_MATH_BINOMIAL_H_
2 #define GENESIS_UTILS_MATH_BINOMIAL_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2023 Lucas Czech
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lczech@carnegiescience.edu>
23  Department of Plant Biology, Carnegie Institution For Science
24  260 Panama Street, Stanford, CA 94305, USA
25 */
26 
34 #include <cmath>
35 #include <cstdint>
36 
37 namespace genesis {
38 namespace utils {
39 
40 // =================================================================================================
41 // Binomial Functions
42 // =================================================================================================
43 
52 double log_factorial( size_t n );
53 
60 size_t binomial_coefficient_int( size_t n, size_t k );
61 
71 double log_binomial_coefficient( size_t n, size_t k );
72 
99 inline double binomial_coefficient( size_t n, size_t k )
100 {
101  return std::exp( log_binomial_coefficient( n, k ));
102 }
103 
109 double log_binomial_distribution( size_t k, size_t n, double p );
110 
121 inline double binomial_distribution( size_t k, size_t n, double p )
122 {
123  return std::exp( log_binomial_distribution( k, n, p ));
124 }
125 
126 } // namespace utils
127 } // namespace genesis
128 
129 #endif // include guard
genesis::utils::log_binomial_coefficient
double log_binomial_coefficient(size_t n, size_t k)
Compute the logarithm (base e) of the binomial coefficient, that is n choose k, for two integer numbe...
Definition: binomial.cpp:497
genesis::utils::log_factorial
double log_factorial(size_t n)
Return the logarithm (base e) of the factorial of n, that is log(n!).
Definition: binomial.cpp:445
genesis::utils::log_binomial_distribution
double log_binomial_distribution(size_t k, size_t n, double p)
Compute the logarithm (base e) of the probability mass function for a binomial distribution.
Definition: binomial.cpp:519
genesis::utils::binomial_coefficient_int
size_t binomial_coefficient_int(size_t n, size_t k)
Compute the binomial coefficient, that is n choose k, for two integer numbers.
Definition: binomial.cpp:458
genesis::utils::binomial_distribution
double binomial_distribution(size_t k, size_t n, double p)
Compute the probability mass function for a binomial distribution.
Definition: binomial.hpp:121
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
genesis::utils::binomial_coefficient
double binomial_coefficient(size_t n, size_t k)
Compute the binomial coefficient, that is n choose k, for two integer numbers, for large numbers.
Definition: binomial.hpp:99