-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathparam.h
More file actions
221 lines (181 loc) · 5.83 KB
/
param.h
File metadata and controls
221 lines (181 loc) · 5.83 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
* param.h
* Selection_Recombination
*
* Created by Joshua Schraiber on 5/7/13.
* Copyright 2013 UC Berkeley. All rights reserved.
*
*/
#pragma once
#include <vector>
#include "settings.h"
#include "path.h"
class MbRandom;
class path;
class settings;
class popsize;
class wfSamplePath;
class param {
public:
param(MbRandom* r) {curVal = 0; oldVal = 0; tuning = 1; random = r; numProp = 0; numTunings = 0; numAccept = 0; minTuning = 0;};
param(double x, MbRandom* r) {curVal = x; random = r; oldVal = x; tuning = 1; numTunings = 0; numProp = 0; numAccept = 0; minTuning = 0;}
~param() {};
virtual double propose() = 0; //return proposal ratio!
virtual double prior() = 0; //return prior ratio!
virtual void updateTuning();
void increaseProp() {numProp += 1;};
void increaseAccept() {numAccept += 1;};
virtual void reset() {curVal = oldVal;};
double get() {return curVal;};
double getOld() {return oldVal;};
double getTuning() {return tuning;};
void setOld(double v) {oldVal = v;};
void setNew(double v) {oldVal = curVal; curVal = v;};
protected:
double curVal;
double oldVal;
double tuning;
double minTuning;
int numProp;
int numAccept;
int numTunings;
MbRandom* random;
//draw a reflected uniform RV
//centered at x, of width w, but constrained to be between low and high
double reflectedUniform(double x, double w, double low, double high);
};
class param_gamma: public param {
public:
param_gamma(double x, MbRandom* r): param(x, r) {scaling = 10.0; tuning=10.0; minTuning=0.0;};
double propose();
double prior();
private:
double scaling;
};
class param_h: public param {
public:
param_h(double x, MbRandom* r): param(x, r) {scaling = 0.5; tuning=0.5; minTuning=0.0;};
double propose();
double prior();
private:
double scaling;
};
class param_F: public param {
public:
param_F(double x, MbRandom* r): param(x, r) {tuning = 0.5; minTuning = 0.0;};
double propose();
double prior();
};
class param_path: public param {
public:
//param_path(path* p, param_gamma* al1, param_gamma* al2, MbRandom* r): param(r) {curPath = p; minUpdate = 10; fracOfPath = 10; min_dt = .001; grid = 10; a1 = al1; a2 = al2;};
param_path(path* p, param_gamma* al1, param_gamma* al2, MbRandom* r, settings& s): param(r) {curPath = p; minUpdate = s.getMinUpdate(); fracOfPath = s.getFracOfPath(); min_dt = s.get_dt(); grid = s.get_grid(); fOrigin = acos(1.0-2.0*s.get_fOrigin()); a1 = al1; a2 = al2;};
~param_path() {delete curPath; delete newPath; delete oldPath;};
double propose();
double proposeAlleleAge(double newAge, double oldAge);
double proposeStart(double newStart);
double proposeEnd(double newEnd);
double propose(double x0, double xt, double t0, double t, std::vector<double> time_vec, int start_index, int end_index);
double proposeAgePath(double x0,double xt,double t0,double t, std::vector<double> time_vec, int end_index);
double prior() {return 0;};
void updateTuning() {};
void reset();
path* get_path() {return curPath;};
private:
int minUpdate;
int fracOfPath;
double min_dt;
double grid;
double fOrigin;
path* curPath;
path* newPath;
path* oldPath;
param_gamma* a1;
param_gamma* a2;
std::vector<double> make_time_vector(double newAge, int end_index, popsize* rho);
};
//NB: even though it says "freq", this really the transformed frequency
class start_freq: public param {
public:
start_freq(double x, MbRandom* r, param_path* p): param(x, r) {curParamPath = p; minTuning=0.0;};
double propose();
double prior();
void reset();
private:
param_path* curParamPath;
};
class end_freq: public param {
public:
//SEE ABOVE!
end_freq(double x, MbRandom* r, param_path* p): param(x, r) {curParamPath = p; minTuning=3.14/500.;};
double propose();
double prior();
void reset();
private:
param_path* curParamPath;
};
//if sample times are uncertain
class sample_time: public param {
public:
sample_time(double x, double anc, double rec, int ss, int sc, MbRandom* r): param(x, r) {
oldest = anc;
youngest = rec;
sample_size = ss;
sample_count = sc;
tuning = (youngest-oldest)/2.0;
cur_idx = -1;
old_idx = -1;
};
double get_ss() {return sample_size;};
double get_sc() {return sample_count;};
double get_oldest() {return oldest;};
double get_youngest() {return youngest;};
int get_oldest_idx() {return oldest_idx;};
int get_youngest_idx() {return youngest_idx;};
int get_idx() {return cur_idx;};
void set_oldest_idx(int i) {oldest_idx = i;};
void set_youngest_idx(int i) {youngest_idx = i;};
void set_idx(int i) {old_idx = cur_idx; cur_idx = i;}; //keeps time the same, but changes the idx
void reset_idx() {cur_idx = old_idx;};
void reset();
double propose();
double prior();
void updateTuning();
void set_path(param_path* p) {curParamPath = p;};
bool operator<(sample_time& t2) { return (curVal < t2.get()); };
private:
//boundaries
double oldest;
double youngest;
//index of most ancient time, most recent time, current value
int oldest_idx;
int youngest_idx;
int cur_idx;
int old_idx;
//sample relevant information
int sample_count;
int sample_size;
param_path* curParamPath;
};
//for learning the per-base-pair recombination rate
class param_rho: public param {
param_rho(double x, MbRandom* r): param(x, r) {};
double propose();
double prior();
};
//for learning the age of the allele
class param_age: public param {
public:
param_age(double x, MbRandom* r, param_path* p, double min_dt, double grid): param(x, r) {
curParamPath = p;
popSize = ((wfSamplePath*)(p->get_path()))->get_pop();
tuning = .2;
minTuning = min_dt*10;
};
double propose();
double prior();
void reset();
private:
param_path* curParamPath;
popsize* popSize;
};