Logo Coherent WaveBurst  
Reference Guide
Logo
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
wavepath.cc
Go to the documentation of this file.
1 #include "wavepath.hh"
2 
3 ClassImp(wavepath)
4 
5 bool compare_paths(const wavepath& path1, const wavepath& path2) {
6  return path1.get_weight() > path2.get_weight();
7 }
8 
9 ////////////////////////////////////////////////////////////////////////////////
10 /* BEGIN_HTML
11 
12 <p>Wavegraph is a graph-based clustering algorithm for coherent WaveBurst (cWB).
13 Wavegraph generates structured clusters of pixels in the time-frequency-scale
14 energy maps computed by cWB. The structure of the clusters is dictated by an
15 auxiliary user-provided directed graph. Admissible clusters are one-dimensional
16 paths in this graph. Wavegraph finds paths of connected pixels that maximizes a
17 figure-of-merit related to the cumulated sum of the time-frequency-scale energy
18 along the path plus a regularization term.</p>
19 
20 <p>Wavegraph clustering analyses the data segment by successive blocks. The
21 block duration corresponds to that of the input graph. The algorithm collects
22 paths from the analysis of each blocks and then it sorts them and selects
23 distinct path that do not overlap significantly in time.</p>
24 
25 <p>A graph connects nodes together. A node is associated to a
26 (time-frequency-scale) pixel. The node object contains only geometrical
27 information. For instance it includes the list of nodes to which it is connected
28 (its ancestors). The pixel object contains physical information (center of time,
29 frequency and scale bin in physical units) but it does not include any
30 connectivity information.</p>
31 
32 <p>The wavepath class defines methods for paths in the graph. Wavepath are
33 ordered lists of nodes with some auxiliary information.</p>
34 
35 <p>The cluster object is also an ordered list of pixels.</p>
36 
37 <p>We use a fiducial scale as reference for time measurement. XXX TIME
38 CONVERSION FORMULA HERE! XXX</p>
39 
40 END_HTML */
41 ////////////////////////////////////////////////////////////////////////////////
42 
43 
44 void
45 wavepath::init(const wavenode node, const int path_offset, const int path_refscaleidx, const double path_weight) {
46  // Initialize a path and append a first node
47  //
48  // Input: node = node to append
49  // weight = initial path weight
50  // offset = time origin of the block (number of samples in the reference scale plane
51  // from the beginning of the data segment)
52  // refscale_idx = index of the reference scale
53  //
54 
55  weight=path_weight;
56  offset=path_offset;
57  refscaleidx=path_refscaleidx;
58  add_node(node);
59 
60 }
61 
62 void
64  // Append one node to a path
65  //
66  // Input: node = node to append
67 
68  path.push_back(node);
69 
70 }
71 
72 void
74  // Print path to standard output
75 
76  for (unsigned int rank = length(); rank-- > 0; ) {
77  std::cout << "node " << nodeid(rank);
78  std::cout << " (t=" << time(rank)+offset*pow(2,refscaleidx-scale(rank)) << ",f=" << freq(rank) << ",s=" << scale(rank) << ") ->\n";
79  }
80  std::cout << "weight=" << weight << "\n";
81 
82 }
83 
84 cluster
85 wavepath::convert_to_cluster(const int scalemin,const double deltaf_refscale, const int path_width) {
86  // Convert a path object to a cluster object
87  //
88  // Input: scalemin = value of the minimum scale
89  // deltaf_refscale = frequency resolution at reference scale in Hertz
90  // path_width = width of the path in time
91  //
92  // The time offset of the path/cluster is computed in the reference scale plane
93  //
94  // Output: cluster object
95 
96  cluster out;
97  for (unsigned int rank = length(); rank-- > 0; ) {
98  int refscale_to_thisscale = pow(2,refscaleidx-scale(rank));
99  double deltaf_thisscale = deltaf_refscale * refscale_to_thisscale;
100 
101  // init and add pixel in the center
102  pixel path_center = {
103  scale(rank), // scale index
104  time(rank)+offset*refscale_to_thisscale, // time index
105  freq(rank), // freq index
106  0, // log2(scale)
107  nodeid(rank), // node ID
108  0.0, // time
109  0.0}; // freq
110  path_center.log2scale=scalemin+path_center.scaleix; // log2(scale)
111  path_center.time=path_center.timeix/(2*deltaf_thisscale); // time (sec)
112  path_center.freq=path_center.freqix*deltaf_thisscale; // freq (Hz)
113 
114  out.push_back(path_center);
115 
116  // add pixels on the side if width > 1
117  // XXX The node ID of the side pixels is that of the path center and do not match with the graph. XXX
118  // XXX This will lead to issues in the chi^2 test. XXX
119  for (int n=1; n<path_width; ++n) {
120  pixel path_side=path_center;
121  path_side.timeix++;
122  path_side.time=path_side.timeix/(2*deltaf_thisscale);
123  out.push_back(path_side);
124 
125  path_side=path_center;
126  path_side.timeix--;
127  path_side.time=path_side.timeix/(2*deltaf_thisscale);
128  out.push_back(path_side);
129  }
130 
131  }
132  return out;
133 }
134 
135 class is_coincident_with {
136 public:
137  is_coincident_with(double ref_time, double precision): _ref_time(ref_time),_precision(precision){}
138 
139  bool operator()(cluster const & x) const {
140  return abs(_ref_time-(x.back()).time) <= _precision;
141  }
142 private:
143  double _ref_time;
144  double _precision;
145 };
146 
147 std::vector<cluster>
148 select_clusters_distinct_in_time(std::vector<cluster>& sorted_clusters,const double precision) {
149  // Select the loudest univocal clusters that do not overlap significantly with any others
150  //
151  // Input: sorted_clusters = list of clusters sorted by descending weights
152  // precision = duration of the coincidence window according to which two clusters
153  // are said to be overlapping
154  //
155  // Output: list of univocal clusters
156 
157  std::vector<cluster> selected;
158 
159 #ifdef NDEBUG
160  std::cout << "debug flag: select univocal clusters\n";
161  std::cout << "total number of clusters is " << sorted_clusters.size() << "\n";
162 #endif
163 
164  while (! sorted_clusters.empty()) {
165  cluster first=sorted_clusters.front();
166  selected.push_back(first);
167  double ref_time=(first.back()).time;
168  sorted_clusters.erase(std::remove_if(sorted_clusters.begin(),sorted_clusters.end(),is_coincident_with(ref_time,precision)),sorted_clusters.end());
169 #ifdef NDEBUG
170  std::cout << "remaining number of clusters is " << sorted_clusters.size() << "\n";
171 #endif
172  }
173 
174 #ifdef NDEBUG
175  std::cout << "retained " << selected.size() << " univocal clusters\n";
176 #endif
177 
178  return selected;
179 
180 }
double time
Definition: wavepath.hh:38
int refscaleidx
Definition: wavepath.hh:81
std::vector< pixel > cluster
Definition: wavepath.hh:43
float * rank
int n
Definition: cwb_net.C:10
cout<< endl;cout<< "ts size = "<< ts.size()<< " ts rate = "<< ts.rate()<< endl;tf.Forward(ts, wdm);int levels=tf.getLevel();cout<< "tf size = "<< tf.size()<< endl;double dF=tf.resolution();double dT=1./(2 *dF);cout<< "rate(hz) : "<< RATE<< "\t layers : "<< nLAYERS<< "\t dF(hz) : "<< dF<< "\t dT(ms) : "<< dT *1000.<< endl;int itime=TIME_PIXEL_INDEX;int ifreq=FREQ_PIXEL_INDEX;int index=(levels+1)*itime+ifreq;double time=itime *dT;double freq=(ifreq >0)?ifreq *dF:dF/4;cout<< endl;cout<< "PIXEL TIME = "<< time<< " sec "<< endl;cout<< "PIXEL FREQ = "<< freq<< " Hz "<< endl;cout<< endl;wavearray< double > x
std::vector< cluster > select_clusters_distinct_in_time(std::vector< cluster > &sorted_clusters, const double precision)
Definition: wavepath.cc:148
int length()
Definition: wavepath.hh:51
void init(const wavenode node, const int offset, const int refscaleidx, const double path_weight)
Definition: wavepath.cc:45
ofstream out
Definition: cwb_merge.C:196
double time[6]
Definition: cbc_plots.C:435
double precision
int scaleix
Definition: wavepath.hh:33
int log2scale
Definition: wavepath.hh:36
int nodeid(int id)
Definition: wavepath.hh:53
int freqix
Definition: wavepath.hh:35
int time(int id)
Definition: wavepath.hh:55
int offset
Definition: wavepath.hh:79
nodes path
Definition: wavepath.hh:78
double weight
Definition: wavepath.hh:82
int timeix
Definition: wavepath.hh:34
bool compare_paths(const wavepath &path1, const wavepath &path2)
Definition: wavepath.cc:5
void add_node(const wavenode node)
Definition: wavepath.cc:63
double freq
Definition: wavepath.hh:39
int scale(int id)
Definition: wavepath.hh:59
cluster convert_to_cluster(const int scalemin, const double fs, const int path_width)
Definition: wavepath.cc:85
int freq(int id)
Definition: wavepath.hh:57
void print()
Definition: wavepath.cc:73