File: getRandomWeights.cpp

package info (click to toggle)
fastml 3.11-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,772 kB
  • sloc: cpp: 48,522; perl: 3,588; ansic: 819; makefile: 386; python: 83; sh: 55
file content (53 lines) | stat: -rw-r--r-- 1,464 bytes parent folder | download | duplicates (10)
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;
		}
	}
}