-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpop.h
66 lines (56 loc) · 1.66 KB
/
pop.h
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
// pop.h
#ifndef POP_H
#define POP_H
#include "node.h"
#include <map>
using std::map;
class Population
{
private:
vector<Node> pop;
Parameters par;
map<vector<int>, int> prob_counts;
public:
/* It's a good idea to NOT create a new Population
object every iteration cycle but to
renew the Population object instad while keeping prob_counts.
New population should be created with Parameters::Npop
rather than actual population size. It is relevant
for bottleneck scenario. */
// === Constructors ===
explicit Population(const Parameters& p, const string& fname = "");
// === Functionality ===
// returns fitness of the population
void rand_pop();
double fitness() const;
int pick_parent() const;
void next_gen();
void evolve(int N);
const Node& rand_node() const;
void take_sample();
void resize(int N);
int seg_sites(int n = 0) const;
double Tajima(int n = 0) const;
// === Printing an returning members ===
// returns Population
const vector<Node>& show() const { return pop; }
int get_Npop() const { return pop.size(); }
// prints all Nodes in Population
void print(const string& msg = "Population") const;
void write(const string& fname = "pop.txt") const;
void read(const string& fname);
void print_prob_counts(const string& msg = "Probability counts") const;
void write_prob_counts(const string& fname = "prob_counts.txt") const;
};
class PopStat {
private:
int epoch;
int epoch_len;
vector<double> mean_fitness;
public:
explicit PopStat(const Parameters& par);
void write(const Population& pop, int itr) const;
void update(const Population& pop, int gen, int itr);
void reset() { epoch = 0; }
};
#endif