-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulation.cpp
More file actions
183 lines (102 loc) · 4.18 KB
/
simulation.cpp
File metadata and controls
183 lines (102 loc) · 4.18 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
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <float.h>
#include "gillespie.h"
#include "infcalc.h"
const float Nmax = 200000;
///////// initialisation
float step = 1;
long MCsteps = 20000;
long MCeq = 1000;
// calculating m2 average and variance
void generateDataFromUD( float * params, int write, char * filename){
FILE * pFile;
FILE * pFile2;
pFile = fopen (filename, "w");
FILE * myAvFile = fopen ("steady_state", "w");
params[28] = params[21];
while(params[28] <= params[20] + 0.1){
if( Nmax > m1 + m2 + c1 + c2 + mu){
Tstop = MCeq;
gillespie( params, 0, pFile, NULL); // equilibrating the system
Tstop = MCsteps; // number of monte carlo steps
gillespie( params, 1, pFile, myAvFile); // recording the steady state
}
params[28] += step;
}
fclose(myAvFile);
fclose(pFile);
}
// processing the optimal input
int generateDataFromGivenDist(float * params, int write, char * filename, int stopTime){
char s [50];
float fm1q = 0;
float probabiliti = 0;
FILE * pFile1 = fopen ("prob_notNormalised", "r");
FILE * pFile = fopen ("alll", "w");
int i = 0, u = 0;
int m2maxx = 0;
float normalizationFactor = 0;
if (pFile1 != NULL)
while (fgetc(pFile1) != EOF)
{
fscanf(pFile1, "%s\t%f\t%f\n", s, ¶ms[28], &probabiliti );
i++;
if( Nmax > m1 + m2 + c1 + c2 + mu && i >= step * u && i>1){
// printf("t%f\t%f\n", params[26], probabiliti);
Tstop = MCeq;
gillespie(params, 0, pFile, NULL); // equilibrating the system
normalizationFactor += probabiliti;
if(m2 > m2maxx) m2maxx = m2;
Tstop = probabiliti * stopTime;
gillespie(params, 1, pFile, NULL); // recording the steady state
u++;
}
}
fclose(pFile);
fclose(pFile1);
return m2maxx;
}
/////////////////////////-------------- main
int main(){
float fm10 = 1;
srand (time(NULL));
char filename [10] = "alll1";
char meanfilename [15] = "steady_state";
float b1=0, b2=0, bmu=0, d1=0, d2=0, dmu=0, sigma1=0, sigma2=0, k1pl=0, k2pl=0, k1min=0, k2min=0, kappa1=0, kappa2=0, n1var=0, n2var=0, nmuvar=0, h=0, kin=0, kout=0, tfmax=0, tfmin=0, m2min=0, m2max=0, channel=0, fvar=0;
float params [29] = { b1, b2, bmu, d1, d2,
dmu, sigma1, sigma2, k1pl, k2pl,
k1min, k2min, kappa1, kappa2, n1var,
n2var, nmuvar, h, kin, kout,
tfmax, tfmin, m2min, m2max, channel,
step, MCsteps, MCeq, fvar};
float maxprob = 0;
char filename1 [10] = "alll";
char s[20];
FILE * paramsFile;
paramsFile = fopen("parameters","r"); // read mode
int i= 0;
if (paramsFile != NULL){
while (fgetc(paramsFile) != EOF)
{
fscanf(paramsFile, "%s\t%f\n", s, ¶ms[i]);
i ++;
}
}
step = params[25];
tfmax = params[20];
MCsteps = (long) params[26];
MCeq = (long) params[27];
maxbound = 0;
minbound = 10000;
minVariance2 = 10000;
generateDataFromUD(params, 0, filename); // generating the output
maxprob = calculateOptInf(params[20], 2, meanfilename); // calculating optimal input
m2max = generateDataFromGivenDist(params, 1, filename1, MCsteps/maxprob); // processing optimal input distribution
printf("MI\t\t Delta m2 \t m2min \t\t variance(m2min)\n"); // displaying results
calculateInf2( 0, b1/d1, 0, m2max, 1, tfmax, filename1, step); // calculating MI
printf("\t%f\t%f\t%f\n", maxbound - minbound, minbound, minVariance2 ); // displaying results
return 0;
}