Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Test8.C
Go to the documentation of this file.
1 //Test 8: Similar, but second witness channel has a very small (but nonzero) correlation
2 //Witness channels: A(t) = 0.6*y(t) + w(t)
3 // B(t) = z(t) + 0.2*w(t)
4 //Target channel: H(t) = x(t) + 0.8*w(t)
5 //Hopefully, the code will give the same result as tests 2 and 7 -- i.e. ignore B(t),
6 //since trying to use it in the regression would only add noise.
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
29 
30  // time series is filled with white noise data:
31  TRandom3 rnd(0);
32  for(int i=0; i<N; i++) x[i] = rnd.Gaus();
33  for(int i=0; i<N; i++) w[i] = rnd.Gaus();
34  for(int i=0; i<N; i++) y[i] = rnd.Gaus();
35  for(int i=0; i<N; i++) z[i] = rnd.Gaus();
36 
37  //Fill target and witness
38  wavearray<double> A = w; y*= 0.6; A += y;
39  wavearray<double> w_1 = w; w_1*= 0.2;
40  wavearray<double> B = w_1; B += z;
41  wavearray<double> H = x; w*= 0.8; H += w;
42 
43  //Make WDM transform, resolution = 1Hz
44  int lev=H.rate()/2;
45  WDM<double> wdtf(lev, 2*lev, 6, 10);
47  tfmap.Forward(H, wdtf);
48 
49  //Adding target channel
50  regression r;
51  r.add(tfmap,const_cast<char*>("hchannel"));
52 
53  //Adding witness channel
54  r.add(A,const_cast<char*>("witness"));
55  r.add(B,const_cast<char*>("witness"));
56 
57  regression r_s = r;
58  regression r_m = r;
59 
60  //Calculate prediction
61  r.setFilter(5);
62  r.setMatrix(SCRATCH);
63  r.solve(0, 20, 'h');
64  r.apply(0.2);
65 
66  wavearray<double> clean=r.getClean();
67 
68  cout << "HARD:" << endl;
69  cout << "Ratio rms: (" << clean.rms() << "/" << H.rms() << ")= " << clean.rms()/H.rms() << endl;
70 
71  cout << "x : " << x.mean() << " " << x.rms() << endl;
72  cout << "clean : " << clean.mean() << " " << clean.rms() << endl;
73  clean -= x;
74  cout << "clean-x : " << clean.mean() << " " << clean.rms() << endl;
75  cout << "-------------------" << endl;
76 
77  //Calculate prediction
78  r_s.setFilter(5);
79  r_s.setMatrix(SCRATCH);
80  r_s.solve(0, 20, 's');
81  r_s.apply(0.2);
82 
83  clean=r_s.getClean();
84 
85  cout << "SOFT:" << endl;
86  cout << "Ratio rms: (" << clean.rms() << "/" << H.rms() << ")= " << clean.rms()/H.rms() << endl;
87 
88  cout << "x : " << x.mean() << " " << x.rms() << endl;
89  cout << "clean : " << clean.mean() << " " << clean.rms() << endl;
90  clean -= x;
91  cout << "clean-x : " << clean.mean() << " " << clean.rms() << endl;
92  cout << "-------------------" << endl;
93 
94  //Calculate prediction
95  r_m.setFilter(5);
96  r_m.setMatrix(SCRATCH);
97  r_m.solve(0, 20, 'm');
98  r_m.apply(0.2);
99 
100  clean=r_m.getClean();
101 
102  cout << "MILD:" << endl;
103  cout << "Ratio rms: (" << clean.rms() << "/" << H.rms() << ")= " << clean.rms()/H.rms() << endl;
104 
105  cout << "x : " << x.mean() << " " << x.rms() << endl;
106  cout << "clean : " << clean.mean() << " " << clean.rms() << endl;
107  clean -= x;
108  cout << "clean-x : " << clean.mean() << " " << clean.rms() << endl;
109  cout << "-------------------" << endl;
110 
111 
112  wavearray<double> eigen=r.getVEIGEN(-1);
113  eigen.rate(22);
114  watplot plot;
115  TCanvas *c1 = plot.canvas;
116  c1->SetCanvasSize(1600,800);
117  c1->Divide(1,2);
118 
119  c1->cd(1);
120  plot.plot(eigen,const_cast<char*>("alp"),1);
121  plot.graph[0]->SetTitle("Eigen-values of all layers");
122 
123  c1->cd(2);
124  TPad* P=(TPad*)c1->GetPad(2);
125  P->Divide(3,1);
126 
127  wavearray<double> freq=r.vfreq;
129  wavearray<double> rank1=r.getRank(1);
130  wavearray<double> rank2=r.getRank(2);
131  P->cd(1);
132  TMultiGraph* mg=new TMultiGraph();
133  TGraph* g=new TGraph(freq.size(),freq.data,rank.data);
134  g->SetLineColor(1);
135  mg->Add(g);
136  TGraph* g1=new TGraph(freq.size(),freq.data,rank1.data);
137  g1->SetLineColor(2);
138  mg->Add(g1);
139  TGraph* g2=new TGraph(freq.size(),freq.data,rank2.data);
140  g2->SetLineColor(3);
141  mg->Add(g2);
142  mg->Draw(const_cast<char*>("alp"));
143  mg->SetTitle("HARD: Ranking for all layers");
144 
145  wavearray<double> freq_s=r_s.vfreq;
146  wavearray<double> rank_s=r_s.getRank(0);
147  wavearray<double> rank1_s=r_s.getRank(1);
148  wavearray<double> rank2_s=r_s.getRank(2);
149  P->cd(2);
150  TMultiGraph* mg_s=new TMultiGraph();
151  TGraph* g_s=new TGraph(freq_s.size(),freq_s.data,rank_s.data);
152  g_s->SetLineColor(1);
153  mg_s->Add(g_s);
154  TGraph* g1_s=new TGraph(freq_s.size(),freq_s.data,rank1_s.data);
155  g1_s->SetLineColor(2);
156  mg_s->Add(g1_s);
157  TGraph* g2_s=new TGraph(freq_s.size(),freq_s.data,rank2_s.data);
158  g2_s->SetLineColor(3);
159  mg_s->Add(g2_s);
160  mg_s->Draw(const_cast<char*>("alp"));
161  mg_s->SetTitle("SOFT: Ranking for all layers");
162 
163  wavearray<double> freq_m=r_m.vfreq;
164  wavearray<double> rank_m=r_m.getRank(0);
165  wavearray<double> rank1_m=r_m.getRank(1);
166  wavearray<double> rank2_m=r_m.getRank(2);
167  P->cd(3);
168  TMultiGraph* mg_m=new TMultiGraph();
169  TGraph* g_m=new TGraph(freq_m.size(),freq_m.data,rank_m.data);
170  g_m->SetLineColor(1);
171  mg_m->Add(g_m);
172  TGraph* g1_m=new TGraph(freq_m.size(),freq_m.data,rank1_m.data);
173  g1_m->SetLineColor(2);
174  mg_m->Add(g1_m);
175  TGraph* g2_m=new TGraph(freq_m.size(),freq_m.data,rank2_m.data);
176  g2_m->SetLineColor(3);
177  mg_m->Add(g2_m);
178  mg_m->Draw(const_cast<char*>("alp"));
179  mg_m->SetTitle("MILD: Ranking for all layers");
180 
181  c1->SaveAs("Test8.png");
182 
183  exit(0);
184 
185 }
virtual size_t size() const
Definition: wavearray.hh:127
TF1 * g2
Definition: slag.C:248
static double g(double e)
Definition: GNGen.cc:98
void setMatrix(double edge=0., double f=1.)
Definition: regression.cc:407
Definition: ced.hh:24
virtual void rate(double r)
Definition: wavearray.hh:123
float * rank
#define B
cout<< "skymap size : "<< L<< endl;for(int l=0;l< L;l++) sm.set(l, l);sm > const_cast< char * >("skymap.dat")
std::vector< TGraph * > graph
Definition: watplot.hh:176
TRandom3 P
Definition: compare_bkg.C:296
size_t add(WSeries< double > &target, char *name, double fL=0., double fH=0.)
Definition: regression.cc:73
virtual void start(double s)
Definition: wavearray.hh:119
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:132
virtual double mean() const
Definition: wavearray.cc:1053
virtual double rms()
Definition: wavearray.cc:1188
TCanvas * canvas
Definition: watplot.hh:174
wavearray< double > w
Definition: Test8.C:26
x plot
int N
Definition: Test8.C:18
TCanvas * c1
TF1 * g1
Definition: compare_bkg.C:505
#define SCRATCH
void apply(double threshold=0., char c='a')
Definition: regression.cc:691
wavearray< double > getRank(int n)
Definition: regression.hh:134
WSeries< double > tfmap
void solve(double th, int nE=0, char c='s')
Definition: regression.cc:592
wavearray< double > vfreq
Definition: regression.hh:171
static double A
Definition: geodesics.cc:8
size_t setFilter(size_t)
Definition: regression.cc:258
wavearray< double > getVEIGEN(int n=-1)
Definition: regression.cc:339
wavearray< double > getClean()
Definition: regression.hh:117
wavearray< double > z
Definition: Test8.C:28
regression r
Definition: Regression_H1.C:44
TRandom3 rnd(0)
WDM< double > wdtf(lev, 2 *lev, 6, 10)
wavearray< double > x
Definition: Test8.C:19
virtual void stop(double s)
Definition: wavearray.hh:121
wavearray< double > y
Definition: Test8.C:27
void Forward(int n=-1)
param: wavelet - n is number of steps (-1 means full decomposition)
Definition: wseries.cc:228
#define RATE
#define LENGHT
DataType_t * data
Definition: wavearray.hh:301
int lev
Definition: Regression_H1.C:38
virtual void resize(unsigned int)
Definition: wavearray.cc:445
TMultiGraph * mg
exit(0)