-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1highconc_response_no-chemsim.cpp
More file actions
260 lines (236 loc) · 6.48 KB
/
1highconc_response_no-chemsim.cpp
File metadata and controls
260 lines (236 loc) · 6.48 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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <fstream>
#include <ctime>
#include <iomanip>
#include <string>
#include <sstream>
using namespace std;
#include "RandNum.h"
CRandNum randNum;
#define RAN randNum.GenRandReal_10()
#define RAN00 randNum.GenRandReal_00()
#define RANDINT randNum.GenRandInt32()
#define Norm randNum.Gaussian_Noise()
const int noofodour = 16;
const int noofodourant = 160;
const int knownodourant = 26;
const double varconst= 0.005;
const double varsd = 0.028;
const double meanone = 0.27;
const double meanvarone = 0.27;
//const double meansegre = 0.308;
const double meantwo = 0.53;
const double meanvartwo = 0.35;
const double smallres = 0.01;
const double softminthres = -0.15;
int main()
{
int i;
int j;
int k;
int m;
double min[noofodourant];
double softmin[noofodourant];
double max[noofodourant];
double response[noofodourant][noofodour];
double s[noofodourant][noofodourant-1];
// double obtainings(int indexofnewodourant, int indexofpreviousodourant);
double getnewresponse(double responseofpreviousodourant, double s, double minprevious, double maxprevious);
// double getnoise (double averages);
double temprestot;
double temprestotsq;
double tempone;
double temptwo;
double var;
double varmean;
double normcounter;
double noise[noofodour];
double propofnoise[noofodourant];
ifstream inputfile;
inputfile.open("ORNdata.txt");
for (i=0;i<knownodourant;i++)
for (j=0;j<noofodour;j++)
inputfile>>response[i][j];
inputfile.close();
ofstream outzero;
// outzero.open("knownsets.txt");
// for (i=0;i<knownodourant;i++)
// {
// for (j=0;j<noofodour;j++)
// outzero<<response[i][j]<<" ";
// outzero<<endl;
// }
// outzero.close();
for (i=0;i<knownodourant;i++)
{
min[i]=1000;
max[i]=-1000;
for (j=0;j<noofodour;j++)
{
if (response[i][j]<min[i]) //finding min and max so that it can be scaled to [0,1] and be used in eq. 4.9
min[i] = response[i][j];
if (response[i][j]>max[i])
max[i] = response[i][j];
}
}
for (k=1;k<noofodourant;k++) //to obtain s
{
for (m=0;m<k;m++)
{
tempone = RAN;
if (RAN<0.16)
{
do
{
s[k][m]= 0.88+0.075*Norm;
}
while ((s[k][m]>1) or (s[k][m]<0));
}
else if (RAN>0.76)
{
do
{
s[k][m]= 0.16+0.075*Norm;
}
while ((s[k][m]>1) or (s[k][m]<0));
}
else
{
do
{
s[k][m]= 0.64+0.075*Norm;
}
while ((s[k][m]>1) or (s[k][m]<0));
}
}
do
{
propofnoise[k]= 0.9+Norm; //modulate the strength of output correlation
}
while ((propofnoise[k]>2) or (propofnoise[k]<0));
}
// ofstream outone;
// outone.open("sandnoise.txt");
// for (k=1;k<noofodourant;k++)
// {
// for (m=0;m<k;m++)
// outone<<s[k][m]<<" ";
// outone<<endl;
// }
// outone<<endl;
// for (k=1;k<noofodourant;k++)
// outone<<propofnoise[k]<<" ";
// outone<<endl;
// outone.close();
// s[1][0]=0.25;
// s[2][0]=1;
// s[2][1]=1;
// s[3][0]=0.5;
// s[3][1]=0.5;
// s[3][2]=0.5;
temprestot = 0;
temprestotsq = 0;
for (k=knownodourant;k<noofodourant;k++)
{
temprestot = 0;
temprestotsq = 0;
normcounter =0;
for (j=0;j<noofodour;j++)
{
noise[j]=0;
response[k][j]=0;
}
for (m=0;m<k;m++)
{
normcounter = normcounter + 2*(abs(s[k][m]-0.5));
for (j=0;j<noofodour;j++)
{
response[k][j]=response[k][j]+getnewresponse(response[m][j], s[k][m],min[m],max[m]); //1st or 3rd terms of equation (4.9)
noise[j]=noise[j]+2*RAN00*(max[m]-min[m])*(0.5-(abs(s[k][m]-0.5))); //2nd term of equation (4.9)
}
}
for (j=0;j<noofodour;j++)
{
noise[j]=noise[j]*propofnoise[k];
response[k][j]=response[k][j]+noise[j];
response[k][j]=response[k][j]/(normcounter+(k-normcounter)*propofnoise[k]); //normalization: missing in 1st or 3rd terms equation (4.9)
temprestot = temprestot + response[k][j]; //finding mean and varaince
temprestotsq = temprestotsq + response[k][j]*response[k][j];
}
temprestot = temprestot/(noofodour); //next 10 lines or so: same operation as in the 1st odourant
temprestotsq = temprestotsq/(noofodour);
var = temprestotsq - temprestot*temprestot;
min[k] = 1000;
softmin[k] = 1000;
max[k] = -1000;
varmean=abs(varsd*Norm);
tempone = RAN-0.5;
temptwo = RAN;
for (j=0;j<noofodour;j++)
{
if (temptwo<0.25)
response[k][j]= (response[k][j]-temprestot)*sqrt(varmean/var)+meantwo+meanvartwo*tempone; //scaling the variance and mean of the response
else
response[k][j]= (response[k][j]-temprestot)*sqrt(varmean/var)+meanone+meanvarone*tempone;
if (response[k][j]<min[k]) //finding min and max so that it can be scaled to [0,1] and be used in eq. 4.9
{
if (response[k][j]>softminthres)
softmin[k]=response[k][j];
min[k] = response[k][j];
}
if (response[k][j]>max[k])
max[k] = response[k][j];
}
}
for (k=knownodourant;k<noofodourant;k++)
{
if (softmin[k]<0)
{
tempone=smallres*RAN;
for (j=0;j<noofodour;j++)
response[k][j]=response[k][j]-softmin[k]+tempone; //increase overall response strength a little bit
}
}
for (k=knownodourant;k<noofodourant;k++)
for (j=0;j<noofodour;j++)
{
if (response[k][j]<0)
response[k][j]= smallres*RAN; //make sure that all responses are positive
}
ofstream outtwo;
outtwo.open("responseinter.txt");
for (j=0;j<noofodour;j++)
{
for (k=0;k<noofodourant;k++)
outtwo<<response[k][j]<<" ";
outtwo<<endl;
}
outtwo.close();
return 1;
}
//double obtainings(int k,int m)
//{
// double sspec[4][3];
// sspec[1][0]=0.25;
// sspec[2][0]=1;
// sspec[2][1]=1;
// sspec[3][0]=0.5;
// sspec[3][1]=0.5;
// sspec[3][2]=0.5;
// return (sspec[k][m]);
//}
double getnewresponse (double pres, double s, double min, double max) //1st or 3rd terms of equation (4.9)
{
double scaledpres;
//scaledpres = (pres-min)/(max-min); //scaled to interval between 0 and 1
if (s>=0.5)
return (2*pres*(s-0.5)); //strong response if previous OR responding strongly and the two ORs are similar (factor 2 missing in thesis' equation)
else
return (2*(1-pres)*(0.5-s)); //strong response if previous OR responding weakly and the two ORs are dissimilar
}
//double getnoise (double s) //2nd term of equation (4.9)
//{
// return (2*RAN*(0.5-(abs(s-0.5)))); //a lot of noise if neither similar nor dissimilar with previous (i.e. uncorrelationed)
//}