Logo coherent WaveBurst  
Library Reference Guide
Logo
regression.hh
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Sergey Klimenko, Vaibhav Tiwari
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 
19 //**************************************************************
20 // Wavelet Analysis Tool
21 // Sergey Klimenko, University of Florida
22 // class for regression analysis of GW data
23 //**************************************************************
24 
25 #ifndef REGRESSION_HH
26 #define REGRESSION_HH
27 
28 #include <iostream>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <vector>
32 #include "wavearray.hh"
33 #include "wseries.hh"
34 #include "TMatrixDSym.h"
35 #include "TMatrixDSymEigen.h"
36 #include "TVectorD.h"
37 
38 typedef TMatrixTSym<double> TMatrixDSym;
39 typedef std::vector<double> vectorD;
40 
41 struct Wiener { // filter structure for a single target layer
42  std::vector<int> channel; // data channels: 0 - target, >0 witness
43  std::vector<int> layer; // data layers: 0 - target, >0 witness
44  std::vector<double> norm; // normalization factor
45  std::vector<vectorD> filter00; // 0-phase filter:
46  std::vector<vectorD> filter90; // 90-phase filter:
47 };
48 
50 {
51  public:
52 
53  /* ************** */
54  /* constructors */
55  /* ************** */
56 
57  regression();
58 
59  regression(WSeries<double> &, char*, double fL=0., double fH=0.);
60 
61  regression(const regression&);
62 
63  /* ************** */
64  /* destructor */
65  /* ************** */
66 
67  virtual ~regression() {this->clear();}
68 
69  /* ************** */
70  /* operators */
71  /* ************** */
72 
73  regression& operator= (const regression&);
74 
75  /* ************** */
76  /* accessors */
77  /* ************** */
78 
79  size_t add(WSeries<double> & target, char* name, double fL=0., double fH=0.);
80 
81  size_t add(wavearray<double>& witness, char* name, double fL=0., double fH=0.);
82 
83  size_t add(int n, int m, char* name);
84 
85  /* ************** */
86  /* mask frequency */
87  /* ************** */
88 
89  void mask(int n, double flow=0., double fhigh=0.);
90  void unmask(int n, double flow=0., double fhigh=0.);
91 
92  /* ************** */
93  /* compute filter */
94  /* ************** */
95 
96  size_t setFilter(size_t);
97 
98  void setMatrix(double edge=0., double f=1.);
99 
100  void solve(double th, int nE=0, char c='s');
101 
102  void apply(double threshold=0., char c='a');
103 
104  /* ************** */
105  /* get parameters */
106  /* ************** */
107 
108  // extract matrix
109  //
110  // n: channel index
111  //
112  TMatrixDSym getMatrix(size_t n=0)
113  { return n<matrix.size() ? matrix[n] : matrix[0]; }
114 
115  // extract cross vector
116  //
117  // n: channel index
118  //
120  { return n<vCROSS.size() ? vCROSS[n] : vCROSS[0]; }
121 
122  wavearray<double> getVEIGEN(int n=-1);
123 
124  wavearray<double> getFILTER(char c='a', int nT=-1, int nW=-1);
125 
126  // get pointer to TF series
127  WSeries<double>* getTFmap(int n=0) {return n<(int)chList.size() ? &chList[n] : NULL;}
128 
129  wavearray<double> rank(int nbins=0, double fL=0., double fH=0.);
130 
131  //get target-prediction wseries
132  inline WSeries <double> getWNoise() { return WNoise; }
133 
134  // get target-prediction time series
136  wavearray<double> x = this->target;
137  return x -= this->rnoise;
138  }
139 
140  // get prediction time series
141  inline wavearray<double> getNoise() {return rnoise;}
142 
143  // get time series for channel n
144  inline wavearray<double> channel(size_t n) {
145  WSeries<double> w = n<chList.size() ? chList[n] : chList[0];
146  w.Inverse(); return (wavearray<double>)w;
147  }
148 
149  // get rank values for all frequecy layers
150  //
151  // n: channel index
152  inline wavearray<double> getRank(int n) { //RANK
153  int tsize=vrank[n].size(); //RANK
154  wavearray<double> trank(tsize); //RANK
155  for (int i=0; i<tsize; i++) trank.data[i]=sqrt(vrank[n].data[i]); //RANK
156  return trank; //RANK
157  } //RANK
158 
159  // clear channel list
160  inline void clear() {
161  chList.clear(); std::vector< WSeries<double> >().swap(chList);
162  chName.clear(); std::vector< char* >().swap(chName);
163  chMask.clear(); std::vector< wavearray<int> >().swap(chMask);
164  FILTER.clear(); std::vector<Wiener>().swap(FILTER);
165  matrix.clear(); std::vector<TMatrixDSym>().swap(matrix);
166  vCROSS.clear(); std::vector< wavearray<double> >().swap(vCROSS);
167  vEIGEN.clear(); std::vector< wavearray<double> >().swap(vEIGEN);
168  vrank.clear(); std::vector< wavearray<double> >().swap(vrank); //RANK
169  vfreq.resize(0); //RANK
170  }
171 
172  // data members
173 
174  size_t kSIZE; // unit filter half-length
175  double Edge; // time offset at the boundaries
176  bool pOUT; // true/false printout flag
177 
178  std::vector< WSeries<double> > chList; // TF data: 0 - target, >0 - withess
179  std::vector<char*> chName; // channel names: 0 - target, >0-witness
180  std::vector< wavearray<int> > chMask; // layer mask: 0 - target, >0-witness
181  std::vector<Wiener> FILTER; // total Wiener filter
182  std::vector<TMatrixDSym> matrix; // symmetric matrix
183  std::vector< wavearray<double> > vCROSS; // cross-correlation vector
184  std::vector< wavearray<double> > vEIGEN; // vector of eigenvalues
185  wavearray<double> target; // target time series
186  wavearray<double> rnoise; // regressed out noise
187  WSeries<double> WNoise; // Wavelet series for regressed out noise
188  std::vector< wavearray<double> > vrank; //RANK
190 
191 
192 private:
193  void _apply_(int n,
194  std::vector< wavearray<double> > &w,
195  std::vector< wavearray<double> > &W);
196 
197  // used by THtml doc
198  ClassDef(regression,1)
199 
200 }; // class regression
201 
202 #endif // REGRESSION_HH
WSeries< double > * getTFmap(int n=0)
Definition: regression.hh:127
r solve(0.2, 0, 'h')
WSeries< double > getWNoise()
Definition: regression.hh:132
r apply(0.2)
wavearray< double > target
wavearray< double > target
Definition: regression.hh:185
par [0] name
int n
Definition: cwb_net.C:28
wavearray< double > getNoise()
Definition: regression.hh:141
TMatrixTSym< double > TMatrixDSym
Definition: regression.hh:38
cout<< endl;cout<< "ts size = "<< ts.size()<< " ts rate = "<< ts.rate()<< endl;tf.Forward(ts, wdm);int levels=tf.getLevel();cout<< "tf size = "<< tf.size()<< endl;double dF=tf.resolution();double dT=1./(2 *dF);cout<< "rate(hz) : "<< RATE<< "\ layers : "<< nLAYERS<< "\ dF(hz) : "<< dF<< "\ dT(ms) : "<< dT *1000.<< endl;int itime=TIME_PIXEL_INDEX;int ifreq=FREQ_PIXEL_INDEX;int index=(levels+1) *itime+ifreq;double time=itime *dT;double freq=(ifreq >0) ? ifreq *dF :dF/4;cout<< endl;cout<< "PIXEL TIME = "<< time<< " sec "<< endl;cout<< "PIXEL FREQ = "<< freq<< " Hz "<< endl;cout<< endl;wavearray< double > x
wavearray< double > rank
Definition: Regression_H1.C:80
TMatrixDSym getMatrix(size_t n=0)
Definition: regression.hh:112
std::vector< wavearray< double > > vCROSS
Definition: regression.hh:183
int m
Definition: cwb_net.C:28
i drho i
wc clear()
cout<< "SNR "<< xsnr<< endl;wavearray< double > f
Definition: ComputeSNR.C:75
r add(tfmap, const_cast< char *>("hchannel"))
std::vector< wavearray< double > > vEIGEN
Definition: regression.hh:184
std::vector< Wiener > FILTER
Definition: regression.hh:181
std::vector< WSeries< double > > chList
Definition: regression.hh:178
wavearray< double > w
Definition: Test1.C:27
virtual size_t size() const
Definition: wavearray.hh:145
TString chName[NIFO_MAX]
std::vector< double > vectorD
Definition: regression.hh:39
std::vector< vectorD > filter00
Definition: regression.hh:45
r setFilter(10)
i() int(T_cor *100))
virtual ~regression()
Definition: regression.hh:67
double fhigh
wavearray< double > getRank(int n)
Definition: regression.hh:152
std::vector< TMatrixDSym > matrix
Definition: regression.hh:182
std::vector< wavearray< int > > chMask
Definition: regression.hh:180
std::vector< int > channel
Definition: regression.hh:42
r unmask(0, F1, F2)
wavearray< double > vfreq
Definition: regression.hh:189
std::vector< vectorD > filter90
Definition: regression.hh:46
wavearray< double > getClean()
Definition: regression.hh:135
double Edge
Definition: regression.hh:175
size_t kSIZE
Definition: regression.hh:174
void clear()
Definition: regression.hh:160
std::vector< int > layer
Definition: regression.hh:43
double flow
std::vector< char * > chName
Definition: regression.hh:179
WSeries< double > WNoise
Definition: regression.hh:187
std::vector< double > norm
Definition: regression.hh:44
double mask
r setMatrix(totalscratch,.95)
wavearray< double > getVCROSS(size_t n=0)
Definition: regression.hh:119
DataType_t * data
Definition: wavearray.hh:319
std::vector< wavearray< double > > vrank
Definition: regression.hh:188
wavearray< double > rnoise
Definition: regression.hh:186
void Inverse(int n=-1)
param: n - number of steps (-1 means full reconstruction)
Definition: wseries.cc:291
wavearray< double > channel(size_t n)
Definition: regression.hh:144