Skip to content

Commit b8627c3

Browse files
committed
rhoDCCA thresholds
1 parent 1a63fa9 commit b8627c3

25 files changed

+528
-632
lines changed

DCCA.cpp

+75-87
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,42 @@
11
#include "DCCA.h"
22

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)
55
{
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;
1518
getEqualLength();
1619
allocateMemory();
1720
}
1821

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(){}
2623

2724
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));
3330
}
3431

3532
void DCCA::getEqualLength(){
36-
int N1 = setTsLength();
37-
int N2 = setTsLength();
33+
int N1 = setTsLength(ts, tsLen);
34+
int N2 = setTsLength(ts2, tsLen2);
3835
if(N1 > N2){
3936
N = N2;
4037
}else{
4138
N = N1;
42-
}
39+
}
4340
}
4441

4542
int DCCA::getTsLength(){
@@ -48,22 +45,16 @@ int DCCA::getTsLength(){
4845

4946
void DCCA::setFlucVectors(){
5047
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);
6758
}
6859

6960
bool DCCA::computeFlucVec(){
@@ -73,36 +64,41 @@ bool DCCA::computeFlucVec(){
7364
int range = getRangeLength(minWin, maxWin, winStep);
7465
ao.intRange(s, range, minWin, winStep);
7566
int Flen = N - minWin;
76-
double *Fnu;
77-
Fnu = new double [Flen];
67+
std::vector<double> Fnu;
68+
Fnu.reserve(Flen);
7869

7970
QProgressDialog progress(strDCCA+"\n"+QString::fromStdString(fileName.substr(fileName.find_last_of("/")+1))+
8071
" 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+
}
8478

8579
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+
}
9086
}
91-
int currWinSize = s[i];
87+
int currWinSize = s.at(i);
9288
int Ns = N - currWinSize;
9389
ao.zeroVec(Fnu, Flen);
9490

9591
#pragma omp parallel for
9692
for(int v = 0; v < Ns; v++){
9793
int startLim = v;
9894
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);
106102
ao.sliceVec(t, tFit, startLim, endLim);
107103
ao.sliceVec(y, yFit1, startLim, endLim);
108104
ao.sliceVec(y2, yFit2, startLim, endLim);
@@ -112,38 +108,32 @@ bool DCCA::computeFlucVec(){
112108
for(int j = 0; j <= currWinSize; j++){
113109
double polySum1 = 0, polySum2 = 0;
114110
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);
117113
}
118-
diffVec[j] = (yFit1[j] - polySum1) * (yFit2[j] - polySum2);
114+
diffVec.push_back((yFit1.at(j) - polySum1) * (yFit2.at(j) - polySum2));
119115
}
120116
}else if(isAbs.compare(defaultDCCA) == 0){
121117
for(int j = 0; j <= currWinSize; j++){
122118
double polySum1 = 0, polySum2 = 0;
123119
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);
126122
}
127-
diffVec[j] = fabs((yFit1[j] - polySum1) * (yFit2[j] - polySum2));
123+
diffVec.push_back(fabs((yFit1.at(j) - polySum1) * (yFit2.at(j) - polySum2)));
128124
}
129125
}
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);
137127
}
138128
if(isAbs.compare(corrDCCA) == 0){
139-
F[i] = mo.mean(Fnu, Ns);
129+
F.push_back(mo.mean(Fnu, Ns));
140130
}else if(isAbs.compare(defaultDCCA) == 0){
141-
F[i] = sqrt(mo.mean(Fnu, Ns));
131+
F.push_back(sqrt(mo.mean(Fnu, Ns)));
142132
}
143133
}
144134

145-
progress.setValue(range);
146-
delAlloc<double>(Fnu);
135+
if(showProgBar)
136+
progress.setValue(range);
147137

148138
return execStop;
149139
}
@@ -156,7 +146,7 @@ std::string DCCA::getFileName2(){
156146
return fileName2;
157147
}
158148

159-
double* DCCA::getF(){
149+
std::vector<double> DCCA::getF(){
160150
return F;
161151
}
162152

@@ -179,18 +169,16 @@ double DCCA::getHintercept(){
179169
void DCCA::fitFlucVec(int start, int end){
180170
MathOps mo = MathOps();
181171
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);
185175
int idx = 0;
186176
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));
189179
idx++;
190180
}
191181
mo.linFit(range, logS, logF, &H, &Hintercept);
192-
delAlloc<double>(logS);
193-
delAlloc<double>(logF);
194182
}
195183

196184
std::string DCCA::outFileStr(){
@@ -207,16 +195,16 @@ void DCCA::saveFile(std::string pathTot){
207195
FILE *f;
208196
f = fo.openFile(pathTot+outFileStr(), "w");
209197
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));
211199
fclose(f);
212200
}
213201

214202
void DCCA::plot(BasePlot *plt){
215203
int len = getRangeLength(minWin, maxWin, winStep);
216204
QVector<double> pltVec(len), n(len), Hfit(len);
217205
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));
220208
Hfit[i] = Hintercept + H * n[i];
221209
}
222210
plt->addGraph();

DCCA.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
class DCCA : public FA
77
{
88
public:
9-
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_);
9+
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=true);
1010
~DCCA();
1111
void allocateMemory() override;
1212
void getEqualLength();
@@ -15,7 +15,7 @@ class DCCA : public FA
1515
bool computeFlucVec() override;
1616
std::string getFileName1();
1717
std::string getFileName2();
18-
double *getF();
18+
std::vector<double> getF();
1919
int getMinWin();
2020
int getMaxWin();
2121
double getH();
@@ -26,17 +26,18 @@ class DCCA : public FA
2626
void plot(BasePlot *plt) override;
2727
private:
2828
std::string fileName2;
29-
double *ts2;
29+
std::vector<double> ts2;
3030
int tsLen2;
3131
int minWin;
3232
int maxWin;
3333
int ord;
3434
std::string isAbs;
3535
int winStep;
36-
double *y2;
37-
int *s;
36+
std::vector<double> y2;
37+
std::vector<int> s;
3838
double H;
3939
double Hintercept;
40+
bool showProgBar;
4041
};
4142

4243
#endif

0 commit comments

Comments
 (0)