]> git.donarmstrong.com Git - rsem.git/blob - simul.h
Added posterior standard deviation of counts as output if either '--calc-pme' or...
[rsem.git] / simul.h
1 #ifndef SIMUL_H_
2 #define SIMUL_H_
3
4 #include<cassert>
5
6 #include "boost/random.hpp"
7
8 class simul {
9 public:
10
11         simul(unsigned int seed) : rg(boost::mt19937(seed)) {
12         }
13
14         // interval : [,)
15         // random number should be in [0, arr[len - 1])
16         // If by chance arr[len - 1] == 0.0, one possibility is to sample uniformly from 0 ... len - 1
17         int sample(double* arr, int len) {
18           int l, r, mid;
19           double prb = random() * arr[len - 1];
20
21
22           l = 0; r = len - 1;
23           while (l <= r) {
24             mid = (l + r) / 2;
25             if (arr[mid] <= prb) l = mid + 1;
26             else r = mid - 1;
27           }
28
29           if (l >= len) { printf("%d %lf %lf\n", len, arr[len - 1], prb); }
30           assert(l < len);
31
32           return l;
33         }
34
35         double random() { return rg(); };
36
37 private:
38         boost::uniform_01<boost::mt19937> rg;
39 };
40
41 #endif /* SIMUL_H_ */
42