Logo coherent WaveBurst  
Library Reference Guide
Logo
Test10.C
Go to the documentation of this file.
1 //Test 10: Two good witness channels plus one slightly correlated one
2 //Witness channels: A(t) = w(t)
3 // B(t) = v(t)
4 // C(t) = y(t) + 0.5*z(t)
5 //Target channel: H(t) = x(t) + 0.8*w(t) + 0.6*v(t) + z(t)
6 //Compare the ASD (or simply the RMS) of H(t) before and after regression.
7 //Although C(t) is correlated, using it in the regression would add more noise than
8 //it removes. So hopefully the code will use A and B to regress but ignore C.
9 //The result, then, should be the same as Test 9.
10 //* Try this with hard, soft, and mild regulators *
11 
12 {
13  //Time
14  #define LENGHT 1200
15  #define SCRATCH 32
16  #define RATE 2048
17 
18  using namespace CWB;
19 
20  //define x channel properties -> gauss 1
21  int N = RATE*(LENGHT+2*SCRATCH);
23  x.rate(RATE);
24  x.resize(N);
25  x.start(0);
26  x.stop(LENGHT+2*SCRATCH);
27 
28  //define w channel properties -> gauss 2
33 
34  // time series is filled with white noise data:
35  TRandom3 rnd(0);
36  for(int i=0; i<N; i++) x[i] = rnd.Gaus();
37  for(int i=0; i<N; i++) w[i] = rnd.Gaus();
38  for(int i=0; i<N; i++) v[i] = rnd.Gaus();
39  for(int i=0; i<N; i++) y[i] = rnd.Gaus();
40  for(int i=0; i<N; i++) z[i] = rnd.Gaus();
41 
42  //Fill target and witness
45  wavearray<double> H = x; w*= 0.8; H += w; v*= 0.6; H += v; H += z;
46  wavearray<double> C = y; z*= 0.5; C += z;
47 
48  //Make WDM transform, resolution = 1Hz
49  int lev=H.rate()/2;
50  WDM<double> wdtf(lev, 2*lev, 6, 10);
52  tfmap.Forward(H, wdtf);
53 
54  //Adding target channel
55  regression r;
56  r.add(tfmap,const_cast<char*>("hchannel"));
57 
58  //Adding witness channel
59  r.add(A,const_cast<char*>("witness"));
60  r.add(B,const_cast<char*>("witness"));
61  r.add(C,const_cast<char*>("witness"));
62 
63  regression r_s = r;
64  regression r_m = r;
65 
66  //Calculate prediction
67  r.setFilter(5);
68  r.setMatrix(SCRATCH);
69  r.solve(0, 20, 'h');
70  r.apply(0.2);
71 
72  wavearray<double> clean=r.getClean();
73 
74  cout << "HARD:" << endl;
75  cout << "Ratio rms: (" << clean.rms() << "/" << H.rms() << ")= " << clean.rms()/H.rms() << endl;
76 
77  cout << "x : " << x.mean() << " " << x.rms() << endl;
78  cout << "clean : " << clean.mean() << " " << clean.rms() << endl;
79  clean -= x;
80  cout << "clean-x : " << clean.mean() << " " << clean.rms() << endl;
81  cout << "-------------------" << endl;
82 
83  //Calculate prediction
84  r_s.setFilter(5);
85  r_s.setMatrix(SCRATCH);
86  r_s.solve(0, 20, 's');
87  r_s.apply(0.2);
88 
89  clean=r_s.getClean();
90 
91  cout << "SOFT:" << endl;
92  cout << "Ratio rms: (" << clean.rms() << "/" << H.rms() << ")= " << clean.rms()/H.rms() << endl;
93 
94  cout << "x : " << x.mean() << " " << x.rms() << endl;
95  cout << "clean : " << clean.mean() << " " << clean.rms() << endl;
96  clean -= x;
97  cout << "clean-x : " << clean.mean() << " " << clean.rms() << endl;
98  cout << "-------------------" << endl;
99 
100  //Calculate prediction
101  r_m.setFilter(5);
102  r_m.setMatrix(SCRATCH);
103  r_m.solve(0, 20, 'm');
104  r_m.apply(0.2);
105 
106  clean=r_m.getClean();
107 
108  cout << "MILD:" << endl;
109  cout << "Ratio rms: (" << clean.rms() << "/" << H.rms() << ")= " << clean.rms()/H.rms() << endl;
110 
111  cout << "x : " << x.mean() << " " << x.rms() << endl;
112  cout << "clean : " << clean.mean() << " " << clean.rms() << endl;
113  clean -= x;
114  cout << "clean-x : " << clean.mean() << " " << clean.rms() << endl;
115  cout << "-------------------" << endl;
116 
117  wavearray<double> eigen=r.getVEIGEN(-1);
118  eigen.rate(22);
119  watplot plot;
120  TCanvas *c1 = plot.canvas;
121  c1->SetCanvasSize(1600,800);
122  c1->Divide(1,2);
123 
124  c1->cd(1);
125  plot.plot(eigen,const_cast<char*>("alp"),1);
126  plot.graph[0]->SetTitle("Eigen-values of all layers");
127 
128  c1->cd(2);
129  TPad* P=(TPad*)c1->GetPad(2);
130  P->Divide(3,1);
131 
134  wavearray<double> rank1=r.getRank(1);
135  wavearray<double> rank2=r.getRank(2);
136  wavearray<double> rank3=r.getRank(3);
137  P->cd(1);
138  TMultiGraph* mg=new TMultiGraph();
139  TGraph* g=new TGraph(freq.size(),freq.data,rank.data);
140  g->SetLineColor(1);
141  mg->Add(g);
142  TGraph* g1=new TGraph(freq.size(),freq.data,rank1.data);
143  g1->SetLineColor(2);
144  mg->Add(g1);
145  TGraph* g2=new TGraph(freq.size(),freq.data,rank2.data);
146  g2->SetLineColor(3);
147  mg->Add(g2);
148  TGraph* g3=new TGraph(freq.size(),freq.data,rank3.data);
149  g3->SetLineColor(4);
150  mg->Add(g3);
151  mg->Draw(const_cast<char*>("alp"));
152  mg->SetTitle("HARD: Ranking for all layers");
153 
154  wavearray<double> freq_s=r_s.vfreq;
155  wavearray<double> rank_s=r_s.getRank(0);
156  wavearray<double> rank1_s=r_s.getRank(1);
157  wavearray<double> rank2_s=r_s.getRank(2);
158  wavearray<double> rank3_s=r_s.getRank(3);
159  P->cd(2);
160  TMultiGraph* mg_s=new TMultiGraph();
161  TGraph* g_s=new TGraph(freq_s.size(),freq_s.data,rank_s.data);
162  g_s->SetLineColor(1);
163  mg_s->Add(g_s);
164  TGraph* g1_s=new TGraph(freq_s.size(),freq_s.data,rank1_s.data);
165  g1_s->SetLineColor(2);
166  mg_s->Add(g1_s);
167  TGraph* g2_s=new TGraph(freq_s.size(),freq_s.data,rank2_s.data);
168  g2_s->SetLineColor(3);
169  mg_s->Add(g2_s);
170  TGraph* g3_s=new TGraph(freq_s.size(),freq_s.data,rank3_s.data);
171  g3_s->SetLineColor(4);
172  mg_s->Add(g3_s);
173  mg_s->Draw(const_cast<char*>("alp"));
174  mg_s->SetTitle("SOFT: Ranking for all layers");
175 
176  wavearray<double> freq_m=r_m.vfreq;
177  wavearray<double> rank_m=r_m.getRank(0);
178  wavearray<double> rank1_m=r_m.getRank(1);
179  wavearray<double> rank2_m=r_m.getRank(2);
180  wavearray<double> rank3_m=r_m.getRank(3);
181  P->cd(3);
182  TMultiGraph* mg_m=new TMultiGraph();
183  TGraph* g_m=new TGraph(freq_m.size(),freq_m.data,rank_m.data);
184  g_m->SetLineColor(1);
185  mg_m->Add(g_m);
186  TGraph* g1_m=new TGraph(freq_m.size(),freq_m.data,rank1_m.data);
187  g1_m->SetLineColor(2);
188  mg_m->Add(g1_m);
189  TGraph* g2_m=new TGraph(freq_m.size(),freq_m.data,rank2_m.data);
190  g2_m->SetLineColor(3);
191  mg_m->Add(g2_m);
192  TGraph* g3_m=new TGraph(freq_m.size(),freq_m.data,rank3_m.data);
193  g3_m->SetLineColor(4);
194  mg_m->Add(g3_m);
195  mg_m->Draw(const_cast<char*>("alp"));
196  mg_m->SetTitle("MILD: Ranking for all layers");
197 
198  c1->SaveAs("Test10.png");
199 
200 
201  exit(0);
202 
203 }
static const double C
Definition: GNGen.cc:28
#define LENGHT
#define SCRATCH
static double g(double e)
Definition: GNGen.cc:116
void setMatrix(double edge=0., double f=1.)
Definition: regression.cc:425
Definition: ced.hh:42
virtual void rate(double r)
Definition: wavearray.hh:141
TF1 * g2
wavearray< double > v
Definition: Test10.C:30
#define B
wavearray< double > z
Definition: Test10.C:32
wavearray< double > rank
Definition: Regression_H1.C:80
std::vector< TGraph * > graph
Definition: watplot.hh:194
int N
Definition: Test10.C:21
size_t add(WSeries< double > &target, char *name, double fL=0., double fH=0.)
Definition: regression.cc:91
virtual void start(double s)
Definition: wavearray.hh:137
i drho i
wavearray< double > x
Definition: Test10.C:22
void plot(wavearray< double > &, char *=NULL, int=1, double=0., double=0., bool=false, float=0., float=0., bool=false, float=0., bool=false)
Definition: watplot.cc:150
virtual double rms()
Definition: wavearray.cc:1206
wavearray< double > w
Definition: Test10.C:29
virtual size_t size() const
Definition: wavearray.hh:145
TCanvas * canvas
Definition: watplot.hh:192
TF1 * g1
wavearray< double > freq
Definition: Regression_H1.C:79
x plot
TCanvas * c1
void apply(double threshold=0., char c='a')
Definition: regression.cc:709
wavearray< double > getRank(int n)
Definition: regression.hh:152
TRandom3 rnd(0)
WSeries< double > tfmap
void solve(double th, int nE=0, char c='s')
Definition: regression.cc:610
wavearray< double > vfreq
Definition: regression.hh:189
static double A
Definition: geodesics.cc:26
size_t setFilter(size_t)
Definition: regression.cc:276
wavearray< double > getVEIGEN(int n=-1)
Definition: regression.cc:357
wavearray< double > getClean()
Definition: regression.hh:135
regression r
Definition: Regression_H1.C:44
WDM< double > wdtf(lev, 2 *lev, 6, 10)
virtual double mean() const
Definition: wavearray.cc:1071
virtual void stop(double s)
Definition: wavearray.hh:139
void Forward(int n=-1)
param: wavelet - n is number of steps (-1 means full decomposition)
Definition: wseries.cc:246
#define RATE
DataType_t * data
Definition: wavearray.hh:319
int lev
Definition: Regression_H1.C:38
virtual void resize(unsigned int)
Definition: wavearray.cc:463
wavearray< double > y
Definition: Test10.C:31
TMultiGraph * mg
exit(0)