Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
wavegraph.hh
Go to the documentation of this file.
1 /**********************************************************
2  * Package: wavegraph Class Library
3  * File name: wavegraph.hh
4  * Authors: Eric Chassande-Mottin, Eric O. Le Bigot
5  **********************************************************/
6 
7 #ifndef WAVEGRAPH_HH
8 #define WAVEGRAPH_HH
9 
10 #include <math.h>
11 #include <vector>
12 #include <set>
13 #include <iostream>
14 #include <fstream>
15 #include <sstream>
16 #include <string>
17 #include <algorithm>
18 #include <stdexcept>
19 #include <limits>
20 
21 #include "wseries.hh"
22 #include "wavepath.hh"
23 
24 // alias to functions from cWB WAT
25 
26 // scale exponent = log_2(scale)
27 inline int get_scale(WSeries<double> *WS) {return WS->maxLayer();}
28 
29 // number of freq bins (first & last bins have df/2)
30 inline int num_of_freq_bins(WSeries<double> *WS) {return WS->maxLayer()+1;}
31 
32 // number of time bins
33 inline int num_of_time_bins(WSeries<double> *WS) {return WS->sizeZero();}
34 
35 // get time (sec) and frequency (Hz) resolution
36 inline float freq_res(WSeries<double> *WS) {return (float)WS->rate()/WS->getLevel()/2;}
37 inline float time_res(WSeries<double> *WS) {return WS->getLevel()/(float)WS->rate();}
38 
39 // get map00/90 value from index
40 inline float get_map00(WSeries<double> *WS, int index)
41 {
42 #ifdef NDEBUG
43  if ((index < 0) | (index > WS->maxIndex())) {
44  std::cout << "debug clustering: requested index " << index << " is <0 or >" << WS->maxIndex() << "\n";
45  throw std::string("Error: index is out of range");
46  }
47 #endif
48  return float(WS->pWavelet->pWWS[index]);
49 }
50 inline float get_map90(WSeries<double> *WS, int index) {return float(WS->pWavelet->pWWS[index+WS->maxIndex()+1]);}
51 
52 // get map00/90 value at given time and frequency
53 inline float get_map00(WSeries<double> *WS, int time, int freq) {return get_map00(WS, time*(WS->maxLayer()+1)+freq);}
54 inline float get_map90(WSeries<double> *WS, int time, int freq) {return get_map90(WS, time*(WS->maxLayer()+1)+freq);}
55 
56 class wavegraph : public TNamed {
57 
58 public:
59 
60  wavegraph() {};
61  ~wavegraph() {};
62 
63  void create(const std::string& srcfile);
64 
65  void clear(){stride=0; span=0; scalemin=0; scalemax=0; nscales=0; samp_freq=0; graph.clear();}
66 
67  void print();
68 
69  void add_node(const int nodeidx, const int timeidx, const int freqidx, const int scaleidx,
70  const double value_avg, const double value_stdev,
71  const bool endnode, const nodeids& ancestors);
72 
73  void add_node(const wavenode node);
74 
75  int size() {return graph.size();}
76 
77  wavenode get_node(int id) {return graph.at(id);}
78 
79  nodeids get_ancestors(int id){return graph.at(id).ancestors;}
80 
81  int nodeid(int id) {return graph[id].nodeid;}
82 
83  int time(int id) {return graph[id].timeix;}
84 
85  int freq(int id) {return graph[id].freqix;}
86 
87  int scale(int id) {return graph[id].scaleix;}
88 
89  int is_endnode(int id) {return graph[id].is_endnode;}
90 
91  int get_span(){return span;}
92 
93  int get_stride(){return stride;}
94 
96 
97  void heaviest_path(std::vector<double>& total_weight, std::vector<int>& total_length,
98  std::vector<int>& best_ancestor, const std::vector<double> weights);
99 
100  bool is_compatible(const std::vector< WSeries<double>* >& data);
101 
102  std::vector<cluster> clustering(const double threshold, const std::vector< WSeries<double>* >& data, const double strip_edges, const int path_halfwidth, const double penal_factor, const std::vector<double>& energy_thresholds);
103 
104 private:
105 
106  nodes graph; // graph object
107  int span; // width of the graph (measured by a number of samples at the largest scale)
108  int stride; // number of samples at largest scale between a block and the next one
109  int scalemin; // smallest scale used to compute the graph
110  int scalemax; // largest scale used to compute the graph
111  int nscales; // number of scales used to compute the graph
112  int samp_freq; // sampling frequency in Hertz used to compute the graph
113 
114  ClassDef(wavegraph,0)
115 
116 };
117 
118 #endif
std::vector< cluster > clustering(const double threshold, const std::vector< WSeries< double > * > &data, const double strip_edges, const int path_halfwidth, const double penal_factor, const std::vector< double > &energy_thresholds)
Definition: wavegraph.cc:475
bool is_compatible(const std::vector< WSeries< double > * > &data)
Definition: wavegraph.cc:420
virtual void rate(double r)
Definition: wavearray.hh:123
int num_of_time_bins(WSeries< double > *WS)
Definition: wavegraph.hh:33
int time(int id)
Definition: wavegraph.hh:83
int nodeid(int id)
Definition: wavegraph.hh:81
size_t maxIndex()
Definition: wseries.hh:131
int nscales
Definition: wavegraph.hh:111
DataType_t * pWWS
Definition: WaveDWT.hh:123
float freq_res(WSeries< double > *WS)
Definition: wavegraph.hh:36
void heaviest_path(std::vector< double > &total_weight, std::vector< int > &total_length, std::vector< int > &best_ancestor, const std::vector< double > weights)
Definition: wavegraph.cc:348
float get_map00(WSeries< double > *WS, int index)
Definition: wavegraph.hh:40
float time_res(WSeries< double > *WS)
Definition: wavegraph.hh:37
nodes graph
Definition: wavegraph.hh:106
int getLevel()
Definition: wseries.hh:91
wavenode get_node(int id)
Definition: wavegraph.hh:77
double time[6]
Definition: cbc_plots.C:435
int stride
Definition: wavegraph.hh:108
int size()
Definition: wavegraph.hh:75
std::set< int > nodeids
Definition: wavepath.hh:19
int scalemax
Definition: wavegraph.hh:110
bool is_topologically_sorted()
Definition: wavegraph.cc:305
int num_of_freq_bins(WSeries< double > *WS)
Definition: wavegraph.hh:30
void add_node(const int nodeidx, const int timeidx, const int freqidx, const int scaleidx, const double value_avg, const double value_stdev, const bool endnode, const nodeids &ancestors)
Definition: wavegraph.cc:59
int is_endnode(int id)
Definition: wavegraph.hh:89
nodeids get_ancestors(int id)
Definition: wavegraph.hh:79
int scalemin
Definition: wavegraph.hh:109
int get_span()
Definition: wavegraph.hh:91
void create(const std::string &srcfile)
Definition: wavegraph.cc:99
int get_scale(WSeries< double > *WS)
Definition: wavegraph.hh:27
wavearray< int > index
int get_stride()
Definition: wavegraph.hh:93
~wavegraph()
Definition: wavegraph.hh:61
int samp_freq
Definition: wavegraph.hh:112
void clear()
Definition: wavegraph.hh:65
int scale(int id)
Definition: wavegraph.hh:87
Long_t id
WaveDWT< DataType_t > * pWavelet
Definition: wseries.hh:438
float get_map90(WSeries< double > *WS, int index)
Definition: wavegraph.hh:50
void print()
Definition: wavegraph.cc:278
int freq(int id)
Definition: wavegraph.hh:85
size_t sizeZero()
Definition: wseries.hh:126
std::vector< wavenode > nodes
Definition: wavepath.hh:42
int maxLayer()
Definition: wseries.hh:121