Logo coherent WaveBurst  
Library Reference Guide
Logo
Test6.C
Go to the documentation of this file.
1 //Test 6: Two witness channels, one highly correlated and the other not
2 //Witness channels: A(t) = y(t) + w(t)
3 // B(t) = w(t)
4 //Target channel: H(t) = x(t) + 0.8*w(t)
5 //Hopefully, the code figures out that it should use B(t) in the regression and
6 //ignore A(t). The net reduction in noise should be the same as Test 1 above.
7 //* Try this with hard, soft, and mild regulators *
8 
9 {
10  //Time
11  #define LENGHT 1200
12  #define SCRATCH 32
13  #define RATE 2048
14 
15  using namespace CWB;
16 
17  //define x channel properties -> gauss 1
18  int N = RATE*(LENGHT+2*SCRATCH);
20  x.rate(RATE);
21  x.resize(N);
22  x.start(0);
23  x.stop(LENGHT+2*SCRATCH);
24 
25  //define w channel properties -> gauss 2
28 
29  // time series is filled with white noise data:
30  TRandom3 rnd(0);
31  for(int i=0; i<N; i++) x[i] = rnd.Gaus();
32  for(int i=0; i<N; i++) w[i] = rnd.Gaus();
33  for(int i=0; i<N; i++) y[i] = rnd.Gaus();
34 
35  //Fill target and witness
36  wavearray<double> A = w; A += y;
38  wavearray<double> H = x; w*= 0.8; H += w;
39 
40  //Make WDM transform, resolution = 1Hz
41  int lev=H.rate()/2;
42  WDM<double> wdtf(lev, 2*lev, 6, 10);
44  tfmap.Forward(H, wdtf);
45 
46  //Adding target channel
47  regression r;
48  r.add(tfmap,const_cast<char*>("hchannel"));
49 
50  //Adding witness channel
51  r.add(A,const_cast<char*>("witness"));
52  r.add(B,const_cast<char*>("witness"));
53 
54  regression r_s = r;
55  regression r_m = r;
56 
57  //Calculate prediction
58  r.setFilter(5);
59  r.setMatrix(SCRATCH);
60  r.solve(0, 20, 'h');
61  r.apply(0.2);
62 
63  wavearray<double> clean=r.getClean();
64 
65  cout << "HARD:" << endl;
66  cout << "Ratio rms: (" << clean.rms() << "/" << H.rms() << ")= " << clean.rms()/H.rms() << endl;
67 
68  cout << "x : " << x.mean() << " " << x.rms() << endl;
69  cout << "clean : " << clean.mean() << " " << clean.rms() << endl;
70  clean -= x;
71  cout << "clean-x : " << clean.mean() << " " << clean.rms() << endl;
72  cout << "-------------------" << endl;
73 
74  //Calculate prediction
75  r_s.setFilter(5);
76  r_s.setMatrix(SCRATCH);
77  r_s.solve(0, 20, 's');
78  r_s.apply(0.2);
79 
80  clean=r_s.getClean();
81 
82  cout << "SOFT:" << endl;
83  cout << "Ratio rms: (" << clean.rms() << "/" << H.rms() << ")= " << clean.rms()/H.rms() << endl;
84 
85  cout << "x : " << x.mean() << " " << x.rms() << endl;
86  cout << "clean : " << clean.mean() << " " << clean.rms() << endl;
87  clean -= x;
88  cout << "clean-x : " << clean.mean() << " " << clean.rms() << endl;
89  cout << "-------------------" << endl;
90 
91  //Calculate prediction
92  r_m.setFilter(5);
93  r_m.setMatrix(SCRATCH);
94  r_m.solve(0, 20, 'm');
95  r_m.apply(0.2);
96 
97  clean=r_m.getClean();
98 
99  cout << "MILD:" << endl;
100  cout << "Ratio rms: (" << clean.rms() << "/" << H.rms() << ")= " << clean.rms()/H.rms() << endl;
101 
102  cout << "x : " << x.mean() << " " << x.rms() << endl;
103  cout << "clean : " << clean.mean() << " " << clean.rms() << endl;
104  clean -= x;
105  cout << "clean-x : " << clean.mean() << " " << clean.rms() << endl;
106  cout << "-------------------" << endl;
107 
108  wavearray<double> eigen=r.getVEIGEN(-1);
109  eigen.rate(22);
110  watplot plot;
111  TCanvas *c1 = plot.canvas;
112  c1->SetCanvasSize(1600,800);
113  c1->Divide(1,2);
114 
115  c1->cd(1);
116  plot.plot(eigen,const_cast<char*>("alp"),1);
117  plot.graph[0]->SetTitle("Eigen-values of all layers");
118 
119  c1->cd(2);
120  TPad* P=(TPad*)c1->GetPad(2);
121  P->Divide(3,1);
122 
125  wavearray<double> rank1=r.getRank(1);
126  wavearray<double> rank2=r.getRank(2);
127  P->cd(1);
128  TMultiGraph* mg=new TMultiGraph();
129  TGraph* g=new TGraph(freq.size(),freq.data,rank.data);
130  g->SetLineColor(1);
131  mg->Add(g);
132  TGraph* g1=new TGraph(freq.size(),freq.data,rank1.data);
133  g1->SetLineColor(2);
134  mg->Add(g1);
135  TGraph* g2=new TGraph(freq.size(),freq.data,rank2.data);
136  g2->SetLineColor(3);
137  mg->Add(g2);
138  mg->Draw(const_cast<char*>("alp"));
139  mg->SetTitle("HARD: Ranking for all layers");
140 
141  wavearray<double> freq_s=r_s.vfreq;
142  wavearray<double> rank_s=r_s.getRank(0);
143  wavearray<double> rank1_s=r_s.getRank(1);
144  wavearray<double> rank2_s=r_s.getRank(2);
145  P->cd(2);
146  TMultiGraph* mg_s=new TMultiGraph();
147  TGraph* g_s=new TGraph(freq_s.size(),freq_s.data,rank_s.data);
148  g_s->SetLineColor(1);
149  mg_s->Add(g_s);
150  TGraph* g1_s=new TGraph(freq_s.size(),freq_s.data,rank1_s.data);
151  g1_s->SetLineColor(2);
152  mg_s->Add(g1_s);
153  TGraph* g2_s=new TGraph(freq_s.size(),freq_s.data,rank2_s.data);
154  g2_s->SetLineColor(3);
155  mg_s->Add(g2_s);
156  mg_s->Draw(const_cast<char*>("alp"));
157  mg_s->SetTitle("SOFT: Ranking for all layers");
158 
159  wavearray<double> freq_m=r_m.vfreq;
160  wavearray<double> rank_m=r_m.getRank(0);
161  wavearray<double> rank1_m=r_m.getRank(1);
162  wavearray<double> rank2_m=r_m.getRank(2);
163  P->cd(3);
164  TMultiGraph* mg_m=new TMultiGraph();
165  TGraph* g_m=new TGraph(freq_m.size(),freq_m.data,rank_m.data);
166  g_m->SetLineColor(1);
167  mg_m->Add(g_m);
168  TGraph* g1_m=new TGraph(freq_m.size(),freq_m.data,rank1_m.data);
169  g1_m->SetLineColor(2);
170  mg_m->Add(g1_m);
171  TGraph* g2_m=new TGraph(freq_m.size(),freq_m.data,rank2_m.data);
172  g2_m->SetLineColor(3);
173  mg_m->Add(g2_m);
174  mg_m->Draw(const_cast<char*>("alp"));
175  mg_m->SetTitle("MILD: Ranking for all layers");
176 
177  c1->SaveAs("Test6.png");
178 
179  exit(0);
180 
181 }
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
#define B
wavearray< double > rank
Definition: Regression_H1.C:80
std::vector< TGraph * > graph
Definition: watplot.hh:194
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
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
wavearray< double > w
Definition: Test6.C:26
virtual double rms()
Definition: wavearray.cc:1206
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
WSeries< double > tfmap
int N
Definition: Test6.C:18
void solve(double th, int nE=0, char c='s')
Definition: regression.cc:610
#define SCRATCH
wavearray< double > vfreq
Definition: regression.hh:189
static double A
Definition: geodesics.cc:26
TRandom3 rnd(0)
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
#define LENGHT
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
wavearray< double > x
Definition: Test6.C:19
DataType_t * data
Definition: wavearray.hh:319
wavearray< double > y
Definition: Test6.C:27
int lev
Definition: Regression_H1.C:38
virtual void resize(unsigned int)
Definition: wavearray.cc:463
#define RATE
TMultiGraph * mg
exit(0)