-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathModel.hpp
More file actions
95 lines (72 loc) · 2.69 KB
/
Model.hpp
File metadata and controls
95 lines (72 loc) · 2.69 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
#ifndef MODEL_HPP
#define MODEL_HPP
#include <map>
#include "Experiment.hpp"
#include "design.hpp"
#include "modelspec.hpp"
#include "spec_parser/expression/generate.hpp"
namespace STD {
const int EXPERIMENT_NUM_DIGITS = 4;
struct Model {
// TODO consider const
/** number of genes */
size_t G;
/** number of factors */
size_t T;
/** number of experiments */
size_t E;
/** number of spots */
size_t S;
ModelSpec model_spec;
Design::Design design;
std::string module_name;
using FuncType = std::function<double(const double *)>;
FuncType rate_fnc, odds_fnc;
std::vector<FuncType> rate_derivs, odds_derivs;
std::vector<Experiment> experiments;
Parameters parameters;
using Coefficients = std::vector<CoefficientPtr>;
Coefficients coeffs;
std::vector<CoefficientPtr>::iterator find_coefficient(
const Coefficient::Id &cid);
/** hidden contributions to the count data due to the different factors */
Matrix contributions_gene_type;
Vector contributions_gene;
Model(const std::vector<Counts> &data, size_t T, const Design::Design &design,
const ModelSpec &model_spec, const Parameters ¶meters,
bool initialize = true, bool construct_gp = true);
Model clone() const;
CoefficientPtr register_coefficient(
const std::unordered_map<std::string, ModelSpec::Variable> &variable_map,
std::string id, size_t experiment);
void add_covariates();
void construct_GPs();
void add_prior_coefficients();
void setZero();
std::pair<Matrix, Matrix> compute_mean_and_var(size_t e) const;
Model compute_gradient(double &score) const;
void center();
void register_gradient(size_t g, size_t e, size_t s, double total_rate,
double total_odds, Model &gradient, const Vector &rate,
const Vector &odds,
const std::vector<std::vector<double>> &rate_coeffs,
const std::vector<std::vector<double>> &odds_coeffs,
RNG &rng) const;
void coeff_debug_dump(const std::string &tag) const;
Vector vectorize() const;
void from_vector(const Vector &v);
void gradient_update(size_t num_iterations,
std::function<bool(const CoefficientPtr)> is_included);
size_t size() const;
size_t number_variable() const;
void store(const std::string &prefix, bool mean_and_var = false,
bool reorder = true) const;
void restore(const std::string &prefix);
void ensure_dimensions() const;
void update_contributions();
void add_experiment(const Counts &data);
};
std::ostream &operator<<(std::ostream &os, const Model &pfa);
Model operator+(const Model &a, const Model &b);
} // namespace STD
#endif