Logo coherent WaveBurst  
Library Reference Guide
Logo
Test5.C
Go to the documentation of this file.
1 //Test 5: Two identical (i.e., redundant) witness channels:
2 //Witness channels: A(t) = 0.6*y(t) + w(t)
3 // B(t) = A(t)
4 //Target channel: H(t) = x(t) + 0.8*w(t)
5 //This could be pathological in terms of matrix inversion, but corresponds to a very
6 //realistic case of, say, two power-line monitors (with high signal-to-noise) both
7 //showing 60 Hz and harmonics, equivalently. The right answer in terms of the
8 //regression goal is that we can use EITHER A(t) or B(t) (or any linear combination
9 //of them) and achieve the same result as Test 2 above. In other words, I'd like to
10 //think that it is harmless to include extra redundant aux channels. So does the
11 //code manage to do that?
12 //* Try this with hard, soft, and mild regulators *
13 
14 {
15  //Time
16  #define LENGHT 1200
17  #define SCRATCH 32
18  #define RATE 2048
19 
20  using namespace CWB;
21 
22  //define x channel properties -> gauss 1
23  int N = RATE*(LENGHT+2*SCRATCH);
25  x.rate(RATE);
26  x.resize(N);
27  x.start(0);
28  x.stop(LENGHT+2*SCRATCH);
29 
30  //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++) y[i] = rnd.Gaus();
39 
40  //Fill target and witness
41  wavearray<double> A = w; y*= 0.6; A += y;
43  wavearray<double> H = x; w*= 0.8; H += w;
44 
45  //Make WDM transform, resolution = 1Hz
46  int lev=H.rate()/2;
47  WDM<double> wdtf(lev, 2*lev, 6, 10);
49  tfmap.Forward(H, wdtf);
50 
51  //Adding target channel
52  regression r;
53  r.add(tfmap,const_cast<char*>("hchannel"));
54 
55  //Adding witness channel
56  r.add(A,const_cast<char*>("witness"));
57  r.add(B,const_cast<char*>("witness"));
58 
59  regression r_s = r;
60  regression r_m = r;
61 
62  //Calculate prediction
63  r.setFilter(5);
64  r.setMatrix(SCRATCH);
65  r.solve(0, 20, 'h');
66  r.apply(0.2);
67 
68  wavearray<double> clean=r.getClean();
69 
70  cout << "HARD:" << endl;
71  cout << "Ratio rms: (" << clean.rms() << "/" << H.rms() << ")= " << clean.rms()/H.rms() << endl;
72 
73  cout << "x : " << x.mean() << " " << x.rms() << endl;
74  cout << "clean : " << clean.mean() << " " << clean.rms() << endl;
75  clean -= x;
76  cout << "clean-x : " << clean.mean() << " " << clean.rms() << endl;
77  cout << "-------------------" << endl;
78 
79  //Calculate prediction
80  r_s.setFilter(5);
81  r_s.setMatrix(SCRATCH);
82  r_s.solve(0, 20, 's');
83  r_s.apply(0.2);
84 
85  clean=r_s.getClean();
86 
87  cout << "SOFT:" << endl;
88  cout << "Ratio rms: (" << clean.rms() << "/" << H.rms() << ")= " << clean.rms()/H.rms() << endl;
89 
90  cout << "x : " << x.mean() << " " << x.rms() << endl;
91  cout << "clean : " << clean.mean() << " " << clean.rms() << endl;
92  clean -= x;
93  cout << "clean-x : " << clean.mean() << " " << clean.rms() << endl;
94  cout << "-------------------" << endl;
95 
96  //Calculate prediction
97  r_m.setFilter(5);
98  r_m.setMatrix(SCRATCH);
99  r_m.solve(0, 20, 'm');
100  r_m.apply(0.2);
101 
102  clean=r_m.getClean();
103 
104  cout << "MILD:" << endl;
105  cout << "Ratio rms: (" << clean.rms() << "/" << H.rms() << ")= " << clean.rms()/H.rms() << endl;
106 
107  cout << "x : " << x.mean() << " " << x.rms() << endl;
108  cout << "clean : " << clean.mean() << " " << clean.rms() << endl;
109  clean -= x;
110  cout << "clean-x : " << clean.mean() << " " << clean.rms() << endl;
111  cout << "-------------------" << endl;
112 
113  wavearray<double> eigen=r.getVEIGEN(-1);
114  eigen.rate(22);
115  watplot plot;
116  TCanvas *c1 = plot.canvas;
117  c1->SetCanvasSize(1600,800);
118  c1->Divide(1,2);
119 
120  c1->cd(1);
121  plot.plot(eigen,const_cast<char*>("alp"),1);
122  plot.graph[0]->SetTitle("Eigen-values of all layers");
123 
124  c1->cd(2);
125  TPad* P=(TPad*)c1->GetPad(2);
126  P->Divide(3,1);
127 
130  wavearray<double> rank1=r.getRank(1);
131  wavearray<double> rank2=r.getRank(2);
132  P->cd(1);
133  TMultiGraph* mg=new TMultiGraph();
134  TGraph* g=new TGraph(freq.size(),freq.data,rank.data);
135  g->SetLineColor(1);
136  mg->Add(g);
137  TGraph* g1=new TGraph(freq.size(),freq.data,rank1.data);
138  g1->SetLineColor(2);
139  mg->Add(g1);
140  TGraph* g2=new TGraph(freq.size(),freq.data,rank2.data);
141  g2->SetLineColor(3);
142  mg->Add(g2);
143  mg->Draw(const_cast<char*>("alp"));
144  mg->SetTitle("HARD: Ranking for all layers");
145 
146  wavearray<double> freq_s=r_s.vfreq;
147  wavearray<double> rank_s=r_s.getRank(0);
148  wavearray<double> rank1_s=r_s.getRank(1);
149  wavearray<double> rank2_s=r_s.getRank(2);
150  P->cd(2);
151  TMultiGraph* mg_s=new TMultiGraph();
152  TGraph* g_s=new TGraph(freq_s.size(),freq_s.data,rank_s.data);
153  g_s->SetLineColor(1);
154  mg_s->Add(g_s);
155  TGraph* g1_s=new TGraph(freq_s.size(),freq_s.data,rank1_s.data);
156  g1_s->SetLineColor(2);
157  mg_s->Add(g1_s);
158  TGraph* g2_s=new TGraph(freq_s.size(),freq_s.data,rank2_s.data);
159  g2_s->SetLineColor(3);
160  mg_s->Add(g2_s);
161  mg_s->Draw(const_cast<char*>("alp"));
162  mg_s->SetTitle("SOFT: Ranking for all layers");
163 
164  wavearray<double> freq_m=r_m.vfreq;
165  wavearray<double> rank_m=r_m.getRank(0);
166  wavearray<double> rank1_m=r_m.getRank(1);
167  wavearray<double> rank2_m=r_m.getRank(2);
168  P->cd(3);
169  TMultiGraph* mg_m=new TMultiGraph();
170  TGraph* g_m=new TGraph(freq_m.size(),freq_m.data,rank_m.data);
171  g_m->SetLineColor(1);
172  mg_m->Add(g_m);
173  TGraph* g1_m=new TGraph(freq_m.size(),freq_m.data,rank1_m.data);
174  g1_m->SetLineColor(2);
175  mg_m->Add(g1_m);
176  TGraph* g2_m=new TGraph(freq_m.size(),freq_m.data,rank2_m.data);
177  g2_m->SetLineColor(3);
178  mg_m->Add(g2_m);
179  mg_m->Draw(const_cast<char*>("alp"));
180  mg_m->SetTitle("MILD: Ranking for all layers");
181 
182  c1->SaveAs("Test5.png");
183 
184  exit(0);
185 
186 }
#define LENGHT
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
int N
Definition: Test5.C:23
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
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 > y
Definition: Test5.C:32
wavearray< double > getRank(int n)
Definition: regression.hh:152
WSeries< double > tfmap
wavearray< double > x
Definition: Test5.C:24
wavearray< double > w
Definition: Test5.C:31
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
#define RATE
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
DataType_t * data
Definition: wavearray.hh:319
TRandom3 rnd(0)
int lev
Definition: Regression_H1.C:38
virtual void resize(unsigned int)
Definition: wavearray.cc:463
TMultiGraph * mg
#define SCRATCH
exit(0)