1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
// $Id: getRandomWeights.cpp 962 2006-11-07 15:13:34Z privmane $
#include "getRandomWeights.h"
#include "talRandom.h"
void swapRand(Vdouble& weights) {
int j;
int i = talRandom::giveIntRandomNumberBetweenZeroAndEntry(weights.size());
do {
j = talRandom::giveIntRandomNumberBetweenZeroAndEntry(weights.size());
} while ( weights[j] <= 0 );
weights[i]++;
weights[j]--;
}
void getRandomWeights::randomWeights(Vdouble& weights,
const MDOUBLE expectedNumberOfSwapsPerPosition) {
// note that some positions will change more than once, and some won't.
// thus the second argument is an average of sites swaped
int i;
const double DefaultWeight = 1;
for (i=0; i< weights.size(); ++i) weights[i] = DefaultWeight;
for ( i = 0 ; i < expectedNumberOfSwapsPerPosition*weights.size() ; ++i ) {
swapRand(weights);
}
}
void getRandomWeights::standardBPWeights(Vdouble& weights) {
int i;
for (i=0; i< weights.size(); ++i) weights[i] = 0.0;
for (i=0; i< weights.size(); ++i) {
int k = talRandom::giveIntRandomNumberBetweenZeroAndEntry(weights.size());
weights[k]++;
}
}
#define MIN_WEIGHT (0.00001)
void getRandomWeights::randomWeightsGamma(Vdouble& weights,
const MDOUBLE temperature) {
int i;
const double oneOverT = 1.0/temperature;
for (i=0; i< weights.size(); ++i) {
weights[i] = talRandom::SampleGamma(oneOverT,oneOverT);
if (weights[i]<MIN_WEIGHT) {
weights[i] = MIN_WEIGHT;
}
}
}
|