Difference between revisions of "830 - Haplotyper::SampleHaplotypes()"
From Genome Analysis Wiki
Jump to navigationJump to searchLine 1: | Line 1: | ||
<source lang="cpp"> | <source lang="cpp"> | ||
− | float Haplotyper::SampleHaplotypes(float * vector, int & first, int & second) | + | float Haplotyper::SampleHaplotypes(float * vector, int & first, int & second, Random & rand) |
{ | { | ||
− | |||
− | |||
− | |||
float sum = 0.0; | float sum = 0.0; | ||
+ | float *probability = vector; | ||
// Calculate sum over all states | // Calculate sum over all states | ||
Line 21: | Line 19: | ||
sum = 0.0; | sum = 0.0; | ||
− | for (probability = | + | for (probability = vector, first = 0; first < states; first++) |
{ | { | ||
for (second = 0; second <= first; second++) | for (second = 0; second <= first; second++) |
Latest revision as of 14:10, 2 October 2013
float Haplotyper::SampleHaplotypes(float * vector, int & first, int & second, Random & rand)
{
float sum = 0.0;
float *probability = vector;
// Calculate sum over all states
for (int i = 0; i < states; i++)
for (int j = 0; j <= i; j++)
{
sum += *probability;
probability++;
}
// Sample number and select state
float choice = rand->Uniform(0, sum);
sum = 0.0;
for (probability = vector, first = 0; first < states; first++)
{
for (second = 0; second <= first; second++)
{
sum += *probability;
probability++;
if (sum >= choice) break;
}
if (second <= first) break;
}
if (rand->Binary()) SWAP(first, second);
}