-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path3highconc_chemsim_response.cpp
More file actions
173 lines (156 loc) · 4.55 KB
/
3highconc_chemsim_response.cpp
File metadata and controls
173 lines (156 loc) · 4.55 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
#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 whochangemagicnoone = 0.2;
const double whochangemagicnotwo = 0.8;
const double whochangemagicnothree = 0.5;
const double whochangemagicnofour = 0.25;
const double scaleresmagicno = 1;
const double ratioofsimchange = 1;
const double smallchange = 0.05;
const double smallres = 0.02;
const int totalnoit = 100;
int main()
{
int i;
int j;
int k;
int m;
double defchemsim[noofodour][noofodour-1];
double responsesim[noofodour][noofodour-1];
double response[noofodourant][noofodour];
double scalefactor;
double chemsimdiff;
double maxchemsim;
double perturbone;
double perturbtwo;
double tempone;
double temptwo;
ifstream inputfile;
inputfile.open("ORNdatachemsim.txt");
maxchemsim=0;
for (j=1;j<noofodour;j++)
for (m=0;m<j;m++)
{
inputfile>>defchemsim[j][m];
if (defchemsim[j][m]>maxchemsim)
maxchemsim= defchemsim[j][m];
}
inputfile.close();
// ifstream inputresponsesim;
// inputfile.open("alldatachemsim.txt");
// for (j=1;j<noofodour;j++)
// for (m=0;m<j;m++)
// inputfile>>responsesim[j][m];
// inputfile.close();
ifstream inputresponse;
inputresponse.open("responseinter.txt");
for (j=0;j<noofodour;j++)
for (i=0;i<noofodourant;i++)
inputresponse>>response[i][j];
inputresponse.close();
for (k=1;k<=totalnoit;k++)
{
scalefactor=(double)(1/(double)(k)); //less changes made in later iteration
for (j=1;j<noofodour;j++)
for (m=0;m<j;m++)
{
responsesim[j][m]=0; //finding similarity of odor in the current responses
for (i=knownodourant;i<noofodourant;i++)
responsesim[j][m]=responsesim[j][m]+(response[i][j]-response[i][m])*(response[i][j]-response[i][m]);
responsesim[j][m]=sqrt(responsesim[j][m]/noofodourant);
}
for (j=1;j<noofodour;j++)
{
for (m=0;m<j;m++)
{
chemsimdiff=defchemsim[j][m]-responsesim[j][m];
for (i=knownodourant;i<noofodourant;i++)
{
tempone=RAN;
temptwo=RAN;
if (chemsimdiff<0)
{
perturbone = scaleresmagicno*scalefactor*ratioofsimchange*temptwo*(-sqrt(-chemsimdiff))*(maxchemsim-defchemsim[j][m]);
perturbtwo = scaleresmagicno*scalefactor*ratioofsimchange*temptwo*(-sqrt(-chemsimdiff))*(maxchemsim-defchemsim[j][m]); //determine size of changes
}
else
{
perturbone = scaleresmagicno*scalefactor*temptwo*(sqrt(chemsimdiff)*defchemsim[j][m]);
perturbtwo = scaleresmagicno*scalefactor*temptwo*(sqrt(chemsimdiff)*defchemsim[j][m]);
}
if (response[i][j]>=response[i][m])
{
if (tempone<whochangemagicnoone)
response[i][j]=response[i][j]+perturbone+perturbtwo;
else if (tempone>=whochangemagicnotwo)
response[i][m]=response[i][m]-perturbone-perturbtwo;
else
{
response[i][j]=response[i][j]+perturbone;
response[i][m]=response[i][m]-perturbtwo;
}
}
if (response[i][m]>response[i][j])
{
if (tempone<whochangemagicnoone)
response[i][j]=response[i][j]-perturbone-perturbtwo;
else if (tempone>=whochangemagicnotwo)
response[i][m]=response[i][m]+perturbone+perturbtwo;
else
{
response[i][j]=response[i][j]-perturbone;
response[i][m]=response[i][m]+perturbtwo;
}
}
}
}
}
}
for (i=knownodourant;i<noofodourant;i++)
for (j=0;j<noofodour;j++)
if (response[i][j]<smallres)
response[i][j]=smallres*RAN; //reset negative responses to a very small positive value
ofstream outres;
outres.open("chemsimresponse.txt");
for (j=0;j<noofodour;j++)
{
for (i=0;i<noofodourant;i++)
outres<<response[i][j]<<" ";
outres<<endl;
}
outres.close();
for (j=1;j<noofodour;j++)
for (m=0;m<j;m++)
{
responsesim[j][m]=0;
for (i=knownodourant;i<noofodourant;i++)
responsesim[j][m]=responsesim[j][m]+(response[i][j]-response[i][m])*(response[i][j]-response[i][m]);
responsesim[j][m]=sqrt(responsesim[j][m]/noofodourant);
}
ofstream outchemsim;
outchemsim.open("newchemsim.txt");
for (j=1;j<noofodour;j++)
{
for (m=0;m<j;m++)
outchemsim<<responsesim[j][m]<<" ";
outchemsim<<endl;
}
outchemsim.close();
return 1;
}