1
1
#include " DCCA.h"
2
2
3
- DCCA::DCCA (std::string fileName_, double *ts_ , int tsLen_ , std::string fileName2_, double *ts2_ , int tsLen2_ , int minWin_ , int maxWin_ , int ord_ , std::string isAbs_ , int winStep_ )
4
- : FA(ts_, tsLen_ )
3
+ DCCA::DCCA (std::string fileName, std::vector< double > ts , int tsLen , std::string fileName2, std::vector< double > ts2 , int tsLen2 , int minWin , int maxWin , int ord , std::string isAbs , int winStep, bool showProgBar )
4
+ : FA(ts, tsLen )
5
5
{
6
- fileName = fileName_;
7
- fileName2 = fileName2_;
8
- ts2 = ts2_;
9
- tsLen2 = tsLen2_;
10
- minWin = minWin_;
11
- maxWin = maxWin_;
12
- ord = ord_;
13
- isAbs = isAbs_;
14
- winStep = winStep_;
6
+ this ->fileName = fileName;
7
+ this ->fileName2 = fileName2;
8
+ this ->tsLen2 = tsLen2;
9
+ this ->ts2 .reserve (tsLen2);
10
+ for (int i = 0 ; i < tsLen2; i++)
11
+ this ->ts2 .push_back (ts2.at (i));
12
+ this ->minWin = minWin;
13
+ this ->maxWin = maxWin;
14
+ this ->ord = ord;
15
+ this ->isAbs = isAbs;
16
+ this ->winStep = winStep;
17
+ this ->showProgBar = showProgBar;
15
18
getEqualLength ();
16
19
allocateMemory ();
17
20
}
18
21
19
- DCCA::~DCCA (){
20
- delAlloc<double >(t);
21
- delAlloc<double >(y);
22
- delAlloc<double >(y2);
23
- delAlloc<int >(s);
24
- delAlloc<double >(F);
25
- }
22
+ DCCA::~DCCA (){}
26
23
27
24
void DCCA::allocateMemory (){
28
- t = new double [N] ;
29
- y = new double [N] ;
30
- y2 = new double [N] ;
31
- s = new int [ getRangeLength (minWin, maxWin, winStep)] ;
32
- F = new double [ getRangeLength (minWin, maxWin, winStep)] ;
25
+ t. reserve (N) ;
26
+ y. reserve (N) ;
27
+ y2. reserve (N) ;
28
+ s. reserve ( getRangeLength (minWin, maxWin, winStep)) ;
29
+ F. reserve ( getRangeLength (minWin, maxWin, winStep)) ;
33
30
}
34
31
35
32
void DCCA::getEqualLength (){
36
- int N1 = setTsLength ();
37
- int N2 = setTsLength ();
33
+ int N1 = setTsLength (ts, tsLen );
34
+ int N2 = setTsLength (ts2, tsLen2 );
38
35
if (N1 > N2){
39
36
N = N2;
40
37
}else {
41
38
N = N1;
42
- }
39
+ }
43
40
}
44
41
45
42
int DCCA::getTsLength (){
@@ -48,22 +45,16 @@ int DCCA::getTsLength(){
48
45
49
46
void DCCA::setFlucVectors (){
50
47
FA::setFlucVectors ();
51
- MathOps mo = MathOps ();
52
- FileOps fo = FileOps ();
53
- double *pn2, *pn2Nomean;
54
- pn2 = new double [N];
55
- pn2Nomean = new double [N];
56
- int idx = 0 ;
57
- for (int i = 0 ; i < tsLen2; i++){
58
- if (!std::isnan (ts2[i])){
59
- pn2[idx] = ts2[i];
60
- idx++;
61
- }
62
- }
63
- mo.subtractMean (pn2, N, pn2Nomean);
64
- mo.cumsum (pn2Nomean, y2, N);
65
- delAlloc<double >(pn2);
66
- delAlloc<double >(pn2Nomean);
48
+ MathOps mo;
49
+ ArrayOps ao;
50
+ std::vector<double > pn2, pn2Nomean, pn2NoNan;
51
+ pn2.reserve (N);
52
+ pn2Nomean.reserve (N);
53
+ pn2NoNan.reserve (setTsLength (ts2, tsLen2));
54
+ ao.noNan (ts2, tsLen2, pn2NoNan);
55
+ ao.sliceVec (pn2NoNan, pn2, 0 , N-1 );
56
+ mo.subtractMean (pn2, N, pn2Nomean);
57
+ mo.cumsum (pn2Nomean, y2, N);
67
58
}
68
59
69
60
bool DCCA::computeFlucVec (){
@@ -73,36 +64,41 @@ bool DCCA::computeFlucVec(){
73
64
int range = getRangeLength (minWin, maxWin, winStep);
74
65
ao.intRange (s, range, minWin, winStep);
75
66
int Flen = N - minWin;
76
- double * Fnu;
77
- Fnu = new double [ Flen] ;
67
+ std::vector< double > Fnu;
68
+ Fnu. reserve ( Flen) ;
78
69
79
70
QProgressDialog progress (strDCCA+" \n " +QString::fromStdString (fileName.substr (fileName.find_last_of (" /" )+1 ))+
80
71
" vs " +QString::fromStdString (fileName2.substr (fileName2.find_last_of (" /" )+1 )), " Stop" , 0 , range);
81
- progress.setWindowModality (Qt::WindowModal);
82
- progress.setMinimumDuration (0 );
83
- progress.setFixedSize (xPG, yPG);
72
+ progress.setAttribute (Qt::WA_DeleteOnClose, true );
73
+ if (showProgBar){
74
+ progress.setWindowModality (Qt::WindowModal);
75
+ progress.setMinimumDuration (0 );
76
+ progress.setFixedSize (xPG, yPG);
77
+ }
84
78
85
79
for (int i = 0 ; i < range; i++){
86
- progress.setValue (i);
87
- if (progress.wasCanceled ()){
88
- execStop = true ;
89
- break ;
80
+ if (showProgBar){
81
+ progress.setValue (i);
82
+ if (progress.wasCanceled ()){
83
+ execStop = true ;
84
+ break ;
85
+ }
90
86
}
91
- int currWinSize = s[i] ;
87
+ int currWinSize = s. at (i) ;
92
88
int Ns = N - currWinSize;
93
89
ao.zeroVec (Fnu, Flen);
94
90
95
91
#pragma omp parallel for
96
92
for (int v = 0 ; v < Ns; v++){
97
93
int startLim = v;
98
94
int endLim = v + currWinSize;
99
- double * tFit, * yFit1, * yFit2, * diffVec, * coeffs1, * coeffs2;
100
- tFit = new double [ currWinSize+1 ] ;
101
- yFit1 = new double [ currWinSize+1 ] ;
102
- yFit2 = new double [ currWinSize+1 ] ;
103
- diffVec = new double [ currWinSize+1 ] ;
104
- coeffs1 = new double [ ord+1 ] ;
105
- coeffs2 = new double [ ord+1 ] ;
95
+ std::vector< double > tFit, yFit1, yFit2, diffVec, coeffs1, coeffs2;
96
+ tFit. reserve ( currWinSize+1 ) ;
97
+ yFit1. reserve ( currWinSize+1 ) ;
98
+ yFit2. reserve ( currWinSize+1 ) ;
99
+ diffVec. reserve ( currWinSize+1 ) ;
100
+ coeffs1. reserve ( ord+1 ) ;
101
+ coeffs2. reserve ( ord+1 ) ;
106
102
ao.sliceVec (t, tFit, startLim, endLim);
107
103
ao.sliceVec (y, yFit1, startLim, endLim);
108
104
ao.sliceVec (y2, yFit2, startLim, endLim);
@@ -112,38 +108,32 @@ bool DCCA::computeFlucVec(){
112
108
for (int j = 0 ; j <= currWinSize; j++){
113
109
double polySum1 = 0 , polySum2 = 0 ;
114
110
for (int k = 0 ; k < ord+1 ; k++){
115
- polySum1 += coeffs1[k] * pow (tFit[j] , k);
116
- polySum2 += coeffs2[k] * pow (tFit[j] , k);
111
+ polySum1 += coeffs1. at (k) * pow (tFit. at (j) , k);
112
+ polySum2 += coeffs2. at (k) * pow (tFit. at (j) , k);
117
113
}
118
- diffVec[j] = ( yFit1[j] - polySum1) * (yFit2[j] - polySum2);
114
+ diffVec. push_back (( yFit1. at (j) - polySum1) * (yFit2. at (j) - polySum2) );
119
115
}
120
116
}else if (isAbs.compare (defaultDCCA) == 0 ){
121
117
for (int j = 0 ; j <= currWinSize; j++){
122
118
double polySum1 = 0 , polySum2 = 0 ;
123
119
for (int k = 0 ; k < ord+1 ; k++){
124
- polySum1 += coeffs1[k] * pow (tFit[j] , k);
125
- polySum2 += coeffs2[k] * pow (tFit[j] , k);
120
+ polySum1 += coeffs1. at (k) * pow (tFit. at (j) , k);
121
+ polySum2 += coeffs2. at (k) * pow (tFit. at (j) , k);
126
122
}
127
- diffVec[j] = fabs ((yFit1[j] - polySum1) * (yFit2[j] - polySum2));
123
+ diffVec. push_back ( fabs ((yFit1. at (j) - polySum1) * (yFit2. at (j) - polySum2) ));
128
124
}
129
125
}
130
- Fnu[v] = mo.customMean (diffVec, currWinSize+1 , currWinSize-1 );
131
- delAlloc<double >(tFit);
132
- delAlloc<double >(yFit1);
133
- delAlloc<double >(yFit2);
134
- delAlloc<double >(diffVec);
135
- delAlloc<double >(coeffs1);
136
- delAlloc<double >(coeffs2);
126
+ Fnu.at (v) = mo.customMean (diffVec, currWinSize+1 , currWinSize-1 );
137
127
}
138
128
if (isAbs.compare (corrDCCA) == 0 ){
139
- F[i] = mo.mean (Fnu, Ns);
129
+ F. push_back ( mo.mean (Fnu, Ns) );
140
130
}else if (isAbs.compare (defaultDCCA) == 0 ){
141
- F[i] = sqrt (mo.mean (Fnu, Ns));
131
+ F. push_back ( sqrt (mo.mean (Fnu, Ns) ));
142
132
}
143
133
}
144
134
145
- progress. setValue (range);
146
- delAlloc< double >(Fnu );
135
+ if (showProgBar)
136
+ progress. setValue (range );
147
137
148
138
return execStop;
149
139
}
@@ -156,7 +146,7 @@ std::string DCCA::getFileName2(){
156
146
return fileName2;
157
147
}
158
148
159
- double * DCCA::getF (){
149
+ std::vector< double > DCCA::getF (){
160
150
return F;
161
151
}
162
152
@@ -179,18 +169,16 @@ double DCCA::getHintercept(){
179
169
void DCCA::fitFlucVec (int start, int end){
180
170
MathOps mo = MathOps ();
181
171
int range = getRangeLength (start, end, winStep);
182
- double * logS, * logF;
183
- logS = new double [ range] ;
184
- logF = new double [ range] ;
172
+ std::vector< double > logS, logF;
173
+ logS. reserve ( range) ;
174
+ logF. reserve ( range) ;
185
175
int idx = 0 ;
186
176
for (int i = (start-minWin)/winStep; i <= (end-minWin)/winStep; i++){
187
- logS[ idx] = log (s[i] );
188
- logF[ idx] = log (F[i] );
177
+ logS. at ( idx) = log (s. at (i) );
178
+ logF. at ( idx) = log (F. at (i) );
189
179
idx++;
190
180
}
191
181
mo.linFit (range, logS, logF, &H, &Hintercept);
192
- delAlloc<double >(logS);
193
- delAlloc<double >(logF);
194
182
}
195
183
196
184
std::string DCCA::outFileStr (){
@@ -207,16 +195,16 @@ void DCCA::saveFile(std::string pathTot){
207
195
FILE *f;
208
196
f = fo.openFile (pathTot+outFileStr (), " w" );
209
197
for (int i = 0 ; i < range; i++)
210
- fprintf (f, " %d %lf\n " , s[i] , F[i] );
198
+ fprintf (f, " %d %lf\n " , s. at (i) , F. at (i) );
211
199
fclose (f);
212
200
}
213
201
214
202
void DCCA::plot (BasePlot *plt){
215
203
int len = getRangeLength (minWin, maxWin, winStep);
216
204
QVector<double > pltVec (len), n (len), Hfit (len);
217
205
for (int i = 0 ; i < len; i++){
218
- n[i] = log (s[i] );
219
- pltVec[i] = log (F[i] );
206
+ n[i] = log (s. at (i) );
207
+ pltVec[i] = log (F. at (i) );
220
208
Hfit[i] = Hintercept + H * n[i];
221
209
}
222
210
plt->addGraph ();
0 commit comments