-
Notifications
You must be signed in to change notification settings - Fork 0
/
VirtualExperiment.h
135 lines (96 loc) · 3.79 KB
/
VirtualExperiment.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
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
#ifndef VIRTUAL_EXPERIMENT_H
#define VIRTUAL_EXPERIMENT_H
#include <stddef.h>
#include "cellml-api-cxx-support.hpp"
#include "IfaceCellML_APISPEC.hxx"
#include "CellMLBootstrap.hpp"
#include "CISBootstrap.hpp"
#include "AdvXMLParser.h"
#include "VariablesHolder.h"
#include <string>
#include <functional>
#include <algorithm>
extern int verbosity;
// DEBUG macro
//#define DEBUG_BUILD
// COMP_FUNC is a function object class for <= comparisons on doubles
#define COMP_FUNC std::less_equal<double>
class VirtualExperiment
{
public:
VirtualExperiment();
~VirtualExperiment();
// Load the CellML model and return if the load was successful
bool LoadModel(const std::string& model_name);
// Load the virtual experiment data from XML file and return a pointer to the constructed VE object (NULL ptr if error)
static VirtualExperiment *LoadExperiment(const AdvXMLParser::Element& elem);
// Load the CellML model parameters onto m_Model
void SetVariables(VariablesHolder& v);
// Set model constants with parameters stored in a VariablesHolder object
void SetParameters(VariablesHolder& v);
// Evaluate the parameter-configured CellML model fitness to the experimental data
double Evaluate();
// Check for invalid VE settings
bool isValid();
// Get CellML model name
std::string model() const { return m_strModelName; }
// Get CellML model component name
std::string getmodelnamefromCellML();
// Get target variable name
std::string variable() const { return m_Variable; }
void variable(std::string name) { m_Variable=name; }
// Get data size
int datasize() const;
int resultcol() const { return m_nResultColumn; }
void resultcol(int r) { m_nResultColumn=r; }
unsigned long maxtime() const { return m_MaxTime; }
void maxtime(unsigned long m) { m_MaxTime=m; }
double accuracy() const { return m_Accuracy; }
void accuracy(double a) { m_Accuracy=a; }
void Run();
private:
struct Runner
{
Runner(VirtualExperiment *p):pOwner(p) {}
double operator()(VariablesHolder& v);
VirtualExperiment *pOwner;
};
friend class Runner;
// Calculate the normalised Sum of Square Residuals (SSR) of the simulation against v-experimental data
double getSSRD(std::vector<std::pair<int,double> >& d);
std::string m_strModelName;
ObjRef<iface::cellml_api::Model> m_Model; // CellML model corresponding to this experiment
int m_nResultColumn; // indicator for the variable of interest
std::string m_Variable; // variable of interest in experiment
typedef std::map<std::wstring,double> PARAMS;
typedef std::pair<double,double> POINT;
typedef std::vector<POINT> TIMEPOINTS;
PARAMS m_Parameters; // parameters to be held constant in simulations of mathematical models
TIMEPOINTS m_Timepoints; // object for storing empirical data for model optimisation
double m_ReportStep;
unsigned long m_MaxTime; // maximum time limit (sec) given to the solver
double m_Accuracy;
bool b_Error; // error indicator
};
//Virtual experiment group handler
class VEGroup
{
private:
VEGroup();
~VEGroup();
public:
// get the singleton VE group object
static VEGroup& instance();
// Evaluate the set of parameters in characterising models as approximations of data in VEs
double Evaluate(VariablesHolder& v);
// Add a VE object onto experiments
void add(VirtualExperiment *p);
// Returns the number of VE objects.
int getExperimentCount();
// Print summary
void print_summary();
protected:
typedef std::vector<VirtualExperiment *> VE;
VE experiments; // the storage for virtual experiment members
};
#endif