55 this->
add(in,ch,fL,fH);
74 std::cout<<
"I am =\n";
110 for(
size_t i=1;
i<I;
i++) {
115 this->
chList.push_back(ww);
116 this->
chName.push_back(ch);
117 this->
chMask.push_back(mask);
135 std::cout<<
"regression::add() ERROR: add target first\n";
139 std::cout<<
"regression::add() ERROR: second witness channel can not be added to LPEF\n";
144 std::cout<<
"regression::add() warning: empty witness channel.\n";
153 if(n || abs(m)!=
int(pow(2.,l)+0.1)) {
154 std::cout<<
"regression::add() ERROR: incompatible target and witness channels\n";
180 std::cout<<
"regression::add() ERROR: incompatible target and witness channels\n";
184 ws.
setlow(fL>=fH ? 0. : fL);
190 for(
size_t i=0;
i<I;
i++) {
198 this->
chList.push_back(ws);
199 this->
chName.push_back(ch);
200 this->
chMask.push_back(mask);
219 std::cout<<
"regression::add() ERROR: second witness channel can not be added to LPEF\n";
223 std::cout<<
"regression::add() WARNING: can't construct witness channel.\n";
238 for(
size_t i=0;
i<I;
i++) {
239 if(!(pMn->
data[
i])) {
243 if(!(pMm->
data[
i])) {
247 if(!(pMn->
data[
i]))
continue;
248 for(
size_t j=0;
j<I;
j++) {
249 if(!(pMm->
data[
j]))
continue;
258 for(
size_t i=0;
i<I;
i++) {
265 wsm *= wsn; ts = wsm; ts -= ts.
mean();
267 this->
chList.push_back(wsn);
268 this->
chName.push_back(ch);
269 this->
chMask.push_back(mask);
288 size_t I = this->
chList[0].maxLayer();
294 this->
FILTER.clear(); std::vector<Wiener>().swap(
FILTER);
295 this->
matrix.clear(); std::vector<TMatrixDSym>().swap(
matrix);
296 this->
vCROSS.clear(); std::vector< wavearray<double> >().swap(
vCROSS);
297 this->
vEIGEN.clear(); std::vector< wavearray<double> >().swap(
vEIGEN);
301 if(!pT->
data[i])
continue;
305 for(j=0; j<
chList.size(); j++) {
307 if(!pW->
data[i])
continue;
309 WF.
layer.push_back(i);
310 WF.
norm.push_back(1.);
316 else pT->
data[
i] = 0;
329 int* pM = this->
chMask[
n].data;
332 for(
size_t i=0;
i<I;
i++) {
347 int* pM = this->
chMask[
n].data;
350 for(
size_t i=0;
i<I;
i++) {
367 size_t I = this->
vEIGEN.size();
368 if(n<(
int)I && n>=0)
return vEIGEN[
n];
369 for(
size_t i=0;
i<I;
i++) E.
append(this->vEIGEN[
i]);
390 if(nT>=0 && nT<N) {i=nT; I=nT+1;}
393 for(
int n=i ;
n<I;
n++) {
396 if(nW>0 && nW<M) {j=nW; J=nW+1;}
399 for(
int m=j;
m<J;
m++) {
404 for(
int k=0;
k<
K;
k++) {
412 OUT.
append((re*re-RE*RE)/(re*re+RE*RE));
435 int I = this->
FILTER.size();
440 int sIZe,sTEp,k00n,k90n,k00m,k90m;
442 double FLTR = !strcmp(this->
chName[0],this->
chName[1]) ? 0. : 1.;
445 double fraction, rms;
459 for(i=0; i<(
int)this->
chList.size(); i++) {
462 if(!I) {std::cout<<
"regression::nothing to clean.\n";
return;}
464 this->
matrix.clear(); std::vector<TMatrixDSym>().swap(
matrix);
465 this->
vCROSS.clear(); std::vector< wavearray<double> >().swap(
vCROSS);
466 this->
vEIGEN.clear(); std::vector< wavearray<double> >().swap(
vEIGEN);
470 N = pW->
layer.size();
474 pTFm = &(this->
chList[0]);
491 for(j=0; j<(
int)ww.
size(); j++) {
494 rms = sqrt(qq.
mean(fm));
506 for(k=-K; k<=
K; k++) {
511 k00m = s00m.
start()-k*sTEp;
512 k90m = s90m.
start()-k*sTEp;
515 k00n = s00n.
start()+k*sTEp;
516 k90n = s90n.
start()+k*sTEp;
520 for(j=K; j<sIZe-
K; j++) {
531 if(k==0) {VC.
data[kk] *= FLTR; VC.
data[kk+K4/2] *= FLTR;}
558 for(k=-K2; k<=K2; k++) {
563 k00m = s00m.
start()-k*sTEp;
564 k90m = s90m.
start()-k*sTEp;
567 k00n = s00n.
start()+k*sTEp;
568 k90n = s90n.
start()+k*sTEp;
573 for(j=K2; j<sIZe-K2; j++) {
588 for(ii=-K; ii<=
K; ii++) {
589 for(jj=-K; jj<=
K; jj++) {
590 MS[nn+ii][mm+jj] = (ii==0 || jj==0) ? acf[ii-jj]*FLTR : acf[ii-jj];
591 MS[mm+jj][nn+ii] = (ii==0 || jj==0) ? acf[ii-jj]*FLTR : acf[ii-jj];
592 MS[nn+ii][mm+jj+K4/2] = (ii==0 || jj==0) ? ccf[ii-jj]*FLTR : ccf[ii-jj];
593 MS[mm+jj+K4/2][nn+ii] = (ii==0 || jj==0) ? ccf[ii-jj]*FLTR : ccf[ii-jj];
594 MS[nn+ii+K4/2][mm+jj] = (ii==0 || jj==0) ? -ccf[ii-jj]*FLTR :-ccf[ii-jj];
595 MS[mm+jj][nn+ii+K4/2] = (ii==0 || jj==0) ? -ccf[ii-jj]*FLTR :-ccf[ii-jj];
596 MS[nn+ii+K4/2][mm+jj+K4/2] = (ii==0 || jj==0) ? acf[ii-jj]*FLTR : acf[ii-jj];
597 MS[mm+jj+K4/2][nn+ii+K4/2] = (ii==0 || jj==0) ? acf[ii-jj]*FLTR : acf[ii-jj];
605 this->
matrix.push_back(MS);
606 this->
vCROSS.push_back(VC);
620 int nA = this->
FILTER.size();
621 int nR = this->
matrix.size();
622 int nC = this->
vCROSS.size();
625 if(!nA) {std::cout<<
"regression::nothing to clean.\n";
return;}
626 if (nA!=nR || nA!=nC || nA==0) {
627 std::cout <<
"Error, filter not initialized\n";
exit(1);
634 this->
vEIGEN.clear(); std::vector< wavearray<double> >().swap(
vEIGEN);
636 for (i=0; i<nA; i++) {
637 int J =
FILTER[
i].layer.size()-1;
638 ne = nE<=0 ? K4*J : nE-1;
639 if(ne>=K4*J) ne = K4*J-1;
645 TMatrixDSymEigen QP(R);
646 TVectorD eigenval(QP.GetEigenValues());
647 TMatrixD eigenvec(QP.GetEigenVectors());
651 double TH = th<0. ? -th*eigenval[0] : th+1.e-12;
653 for(j=0; j<K4*J; j++) {
654 lambda.
data[
j] = eigenval[
j];
655 if(eigenval[j]>=TH) nlast++;
657 if(eigenval[j+1]>eigenval[j])
658 std::cout<<eigenval[
j]<<
" "<<eigenval[j+1]<<endl;
660 if(nlast<1) nlast = 1;
662 this->
vEIGEN.push_back(lambda);
663 if(nlast>ne) nlast = ne;
673 last = eigenval[nlast]>0. ? 1./eigenval[nlast] : 0.;
676 last = 1./eigenval[0];
679 for(j=0;j<=nlast;j++) lambda[j] = eigenval[j]>0. ? 1./eigenval[
j] : 0.;
680 for(j=nlast+1;j<K4*J;j++) lambda[j] = last;
686 for(j=0;j<K4*J;j++) {
688 for(k=0;k<K4*J;k++) temp += eigenvec[k][j]*pC->
data[k];
692 for(j=0;j<K4*J;j++) {
694 for(k=0;k<K4*J;k++) temp += eigenvec[j][k]*vv.
data[k];
699 for (j=0; j<J; j++) {
700 for(k=0;k<=2*
K;k++) {
702 FILTER[
i].filter90[j+1][
k] = aa[j*K4+k+K4/2];
724 int nA = this->
FILTER.size();
725 int nR = this->
matrix.size();
726 int nC = this->
vCROSS.size();
728 if(!nA) {std::cout<<
"regression::nothing to clean.\n";
return;}
729 if (nA!=nR || nA!=nC || nA==0) {
730 std::cout <<
"Error, filter is not initialized\n";
exit(1);
738 for(n=0; n<
L; n++) this->
vrank.push_back(tmp);
753 std::vector< wavearray<double> > wno;
754 std::vector< wavearray<double> > WNO;
767 if(KK<K) KK =
K; KK++;
770 double trms = wno[0].rms(
S);
771 double TRMS = WNO[0].rms(
S);
776 int* pM = this->chMask[j].data;
778 if(c==
'A' || c==
'M') {
779 qq=wno[0]; qq-=wno[
m];
780 QQ=WNO[0]; QQ-=WNO[
m];
783 sum = trms*trms-sum*sum;
784 SUM = TRMS*TRMS-SUM*
SUM;
787 sum = pow(wno[m].rms(
S),2);
788 SUM = pow(WNO[m].rms(
S),2);
796 if(sum+SUM < threshold*threshold) {
797 if(c==
'm' || c==
'M') pM[pF->
layer[
m]] = 0;
800 ww += wno[
m]; WW += WNO[
m];
803 if(c==
'A' || c==
'M') this->
vrank[0].data[
n] = trms*trms+TRMS*TRMS;
816 if(c==
'n') this->
rnoise = wnoise;
817 else if(c==
'N') this->
rnoise = WNOISE;
840 int nA = this->
FILTER.size();
841 int nR = this->
matrix.size();
842 int nC = this->
vCROSS.size();
845 std::cout<<
"regression::nothing to clean.\n";
848 if (nA!=nR || nA!=nC) {
849 std::cout <<
"Error, filter not initialized\n";
exit(1);
857 std::vector< wavearray<double> > vrms;
861 for (
int i=0;
i<tsize;
i++) {
863 if(fL<fH && (freq>fH || freq<fL))
continue;
871 for(m=N-1; m>=N-abs(nbins); m--) {
872 rms.
data[
n] += vrms[
n].data[
m];
873 if(vrms[n].data[m]>0.) nA++;
875 if(nA) rms.
data[
n] /= nA;
897 std::vector<double> *ff, *FF;
915 pW = &(this->chList[j]);
924 qq *= 1./pF->
norm[
m];
925 QQ *= 1./pF->
norm[
m];
927 for(i=0; i<(
int)qq.
size(); i++) {
929 if(i>=K && i<
int(qq.
size())-K) {
930 for(k=-K; k<=
K; k++) {
931 val += (*ff)[k+
K]*qq.
data[i+
k] - (*FF)[k+
K]*QQ.
data[i+
k];
932 VAL += (*FF)[k+
K]*qq.
data[i+
k] + (*ff)[k+
K]*QQ.
data[i+
k];
937 wno[0].data[
i] +=
val;
938 WNO[0].data[
i] += VAL;
size_t append(const wavearray< DataType_t > &)
virtual void resize(unsigned int)
void setMatrix(double edge=0., double f=1.)
void _apply_(int n, std::vector< wavearray< double > > &w, std::vector< wavearray< double > > &W)
virtual void rate(double r)
wavearray< double > target
virtual void edge(double s)
TMatrixTSym< double > TMatrixDSym
WDM< double > wdm(nLAYERS, nLAYERS, 6, 10)
std::vector< wavearray< double > > vCROSS
size_t add(WSeries< double > &target, char *name, double fL=0., double fH=0.)
std::vector< double > vectorD
cout<< "SNR "<< xsnr<< endl;wavearray< double > f
std::vector< wavearray< double > > vEIGEN
std::vector< Wiener > FILTER
std::vector< WSeries< double > > chList
virtual size_t size() const
wavearray< double > rank(int nbins=0, double fL=0., double fH=0.)
std::vector< vectorD > filter00
void apply(double threshold=0., char c='a')
int getLayer(wavearray< DataType_t > &w, double n)
param: n - layer number
std::vector< TMatrixDSym > matrix
std::vector< wavearray< int > > chMask
void solve(double th, int nE=0, char c='s')
std::vector< int > channel
wavearray< double > vfreq
std::vector< vectorD > filter90
wavearray< double > getVEIGEN(int n=-1)
std::vector< char * > chName
virtual std::slice getSlice(const double)
std::vector< double > norm
wavearray< double > ts(N)
virtual double mean() const
double fabs(const Complex &x)
wavearray< double > getFILTER(char c='a', int nT=-1, int nW=-1)
void Forward(int n=-1)
param: wavelet - n is number of steps (-1 means full decomposition)
void unmask(int n, double flow=0., double fhigh=0.)
Meyer< double > S(1024, 2)
void mask(int n, double flow=0., double fhigh=0.)
std::vector< wavearray< double > > vrank
WaveDWT< DataType_t > * pWavelet
regression & operator=(const regression &)
wavearray< double > rnoise
void Inverse(int n=-1)
param: n - number of steps (-1 means full reconstruction)
void putLayer(wavearray< DataType_t > &, double n)
param: n - layer number