-
Notifications
You must be signed in to change notification settings - Fork 0
/
IInferenceEngine.h
160 lines (127 loc) · 4.69 KB
/
IInferenceEngine.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
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
/*
* IInferenceEngine.h
*
* Created on: 20 Dec 2013
* Author: rusty
*/
#ifndef IINFERENCEENGINE_H_
#define IINFERENCEENGINE_H_
#include "INetwork.h"
#include <iostream>
#include <cmath>
#include <stdlib.h>
#include <armadillo>
// depricated use of time.h, sstream, new
using namespace std;
using namespace arma;
class IInferenceEngine {
public:
virtual ~IInferenceEngine(){}
virtual bool runInference(int sampleStepLength)=0;
//virtual double ** runInference(const char* timeseriesFileName, int nTimesteps, int unitDimension, int sampleStepLength) = 0;
// sampleStepLength gives frequency to sample timeseries at (=1 => every measurement. Maximum.)
// virtual void buildJhat() = 0;
//
virtual bool fillJhat(int sampleStepLength) = 0;
//
// virtual mat timmeJhatI(double *thistories, UnitHistory *histories[], int Tsteps, int dim, int SpeciesID, int sampleStep, IDynamicalUnit **Units) = 0;
//
// virtual double **getJhat() = 0;
//
virtual void printJhat() = 0;
//
virtual bool getEstimatedIM(vector<vector<double> >& estIM) = 0;
virtual bool getEstimatedParams(vector<double>& estParams) = 0;
// virtual void printQ(double accuracy, INetwork *net) = 0;
// updated version:
virtual bool qualityOfReconstruction(double accuracy, double& quality, vector<double > IMelements) = 0;
virtual bool percentageQualityOfReconstruction(double accuracy, double& quality, vector<double > IMelements)=0;
virtual bool originalQualityOfReconstruction(double accuracy, double& quality, vector<double > IMelements)=0;
virtual bool unweightedQualityOfReconstruction(double threshold, double& quality, vector< vector <double > > adjacency)=0;
virtual double getSampleRate(int sampleStepLength) = 0;
};
class GradientMatchingEngine_wParameterEstimation : public IInferenceEngine
{
private:
int simID;
int unitCount;
int timestepCount; // is now redunadant. check now required for further methods.
int parametersPerUnit; // assumed to be 1?
vector <vector <double> >* interpolatedTimeseries;
vector <vector <double> > jHat; // following Timme notation: jHat is the inferred adjacency matrix.
// double **jHat;
mat X;
mat G;
bool saveResult();
public:
~GradientMatchingEngine_wParameterEstimation(){
// for (int i = 0; i < timestepCount; i++) {
// delete[] fullTimeseries[i];
// }
// delete[] fullTimeseries;
// for (int i=0; i < this->unitCount; i++){
// delete[] jHat[i];
// }
// delete[] jHat;
}
// this constructor takes a timeseires vector to run inference on. THIS SHOULD BE USED IN ALL CASES!
GradientMatchingEngine_wParameterEstimation(int unitCount, int timestepCount, int parametersPerUnit, vector<vector <double> >* interpolatedTimeseries, int simID=0);
bool runInference(int sampleStepLength);
bool fillJhat(int sampleStepLength);
void printJhat();
bool getEstimatedIM(vector<vector<double> >& estIM);
bool getEstimatedParams(vector<double>& estParams);
// updated from:
//double qualityOfReconstruction(double accuracy, INetwork *net);
// to:
bool qualityOfReconstruction(double accuracy, double& quality, vector<double > IMelements);
bool percentageQualityOfReconstruction(double accuracy, double& quality, vector<double > IMelements);
bool originalQualityOfReconstruction(double accuracy, double& quality, vector<double > IMelements);
bool unweightedQualityOfReconstruction(double threshold, double& quality, vector< vector<double > > adjacency);
double getSampleRate(int sampleStepLength);
private:
// helper functions, not accessible by base class pointer:
// void runInferenceNoLoops(int sampleStepLength);
bool timmeJhatI(int unitID, int sampleStepLength, mat &JHatI);
// double **getJhat();
// double heaviside(double x);
//
// bool movingWindow(int windowLength, int unitID, double **result){
// if (windowLength<(this->unitCount+1)){return 1;}
//
// int M = (timestepCount) - windowLength;
// mat X = zeros<mat>(1,windowLength);
// mat G = zeros<mat>(unitCount+1,windowLength);
// double xtau[unitCount];
//
// double xdotTau;
//
// mat jHat;
//
// // iterate over all windows:
// for (int i=0;i<M;i++){
// cout << "window " << i << endl;
// // iterate of entries in window:
// for (int w=0; w<windowLength; w++){
// xdotTau = (fullTimeseries[i+1+w][1+unitID] - fullTimeseries[i+w][1+unitID])/((fullTimeseries[i+1+w][0] - fullTimeseries[i+w][0]));
// X(0,w) = xdotTau;
//
// for(int j=0;j<unitCount;j++){
// xtau[j] = (fullTimeseries[i+1+w][1+j] + fullTimeseries[i+w][1+j])/2;
//
// G(j,w) = xtau[j] * xtau[unitID];
// }
// G(unitCount,w) = xtau[unitID];
// }
// jHat = X*trans(G)*inv(G*trans(G));
//
// for (int j=0;j<unitCount+1;j++){
// result[i][j] = jHat[j];
// }
// }
//
//
// return true;
// }
};
#endif /* IINFERENCEENGINE_H_ */