1 #ifndef GENESIS_POPULATION_FUNCTION_FST_POOL_KARLSSON_H_
2 #define GENESIS_POPULATION_FUNCTION_FST_POOL_KARLSSON_H_
49 namespace population {
107 void reset_()
override
113 void process_( SampleCounts
const& p1, SampleCounts
const& p2 )
override
118 sum_nk_ += nkdk.first;
119 sum_dk_ += nkdk.second;
122 double get_result_()
const override
124 return static_cast<double>( sum_nk_ ) /
static_cast<double>( sum_dk_ );
141 std::pair<SortedSampleCounts, SortedSampleCounts>
const& sample_counts
166 sample_counts.first[0].base == sample_counts.second[0].base &&
167 sample_counts.first[1].base == sample_counts.second[1].base &&
168 sample_counts.first[2].base == sample_counts.second[2].base &&
169 sample_counts.first[3].base == sample_counts.second[3].base
175 auto const a_1 =
static_cast<double>( sample_counts.first[0].count );
176 auto const b_1 =
static_cast<double>( sample_counts.first[1].count );
177 auto const n_1 = a_1 + b_1;
178 auto const a_2 =
static_cast<double>( sample_counts.second[0].count );
179 auto const b_2 =
static_cast<double>( sample_counts.second[1].count );
180 auto const n_2 = a_2 + b_2;
183 if( n_1 <= 1.0 || n_2 <= 1.0 ) {
188 assert( a_1 <= n_1 );
189 assert( a_2 <= n_2 );
192 double const h1 = ( a_1 * b_1 ) / ( n_1 * ( n_1 - 1.0 ));
193 double const h2 = ( a_2 * b_2 ) / ( n_2 * ( n_2 - 1.0 ));
196 double const sqr =
squared(( a_1 / n_1 ) - ( a_2 / n_2 ));
197 double const sub = ( h1 / n_1 + h2 / n_2 );
198 double const nk = sqr - sub;
199 double const dk = nk + h1 + h2;
219 #endif // include guard