Logo coherent WaveBurst  
Library Reference Guide
Logo
wavegraph.hh
Go to the documentation of this file.
1 /*
2 # Copyright (C) 2019 Eric Chassande-Mottin, Philippe Bacon, Gayathri V, Archana Pai
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17 
18 
19 /**********************************************************
20  * Package: wavegraph Class Library
21  * File name: wavegraph.hh
22  * Authors: Eric Chassande-Mottin, Eric O. Le Bigot
23  **********************************************************/
24 
25 #ifndef WAVEGRAPH_HH
26 #define WAVEGRAPH_HH
27 
28 #include <math.h>
29 #include <vector>
30 #include <set>
31 #include <iostream>
32 #include <fstream>
33 #include <sstream>
34 #include <string>
35 #include <algorithm>
36 #include <stdexcept>
37 #include <limits>
38 
39 #include "wseries.hh"
40 #include "wavepath.hh"
41 
42 // alias to functions from cWB WAT
43 
44 // scale exponent = log_2(scale)
45 inline int get_scale(WSeries<double> *WS) {return WS->maxLayer();}
46 
47 // number of freq bins (first & last bins have df/2)
48 inline int num_of_freq_bins(WSeries<double> *WS) {return WS->maxLayer()+1;}
49 
50 // number of time bins
51 inline int num_of_time_bins(WSeries<double> *WS) {return WS->sizeZero();}
52 
53 // get time (sec) and frequency (Hz) resolution
54 inline float freq_res(WSeries<double> *WS) {return (float)WS->rate()/WS->getLevel()/2;}
55 inline float time_res(WSeries<double> *WS) {return WS->getLevel()/(float)WS->rate();}
56 
57 // get map00/90 value from index
58 inline float get_map00(WSeries<double> *WS, int index)
59 {
60 #ifdef NDEBUG
61  if ((index < 0) | (index > WS->maxIndex())) {
62  std::cout << "debug clustering: requested index " << index << " is <0 or >" << WS->maxIndex() << "\n";
63  throw std::string("Error: index is out of range");
64  }
65 #endif
66  return float(WS->pWavelet->pWWS[index]);
67 }
68 inline float get_map90(WSeries<double> *WS, int index) {return float(WS->pWavelet->pWWS[index+WS->maxIndex()+1]);}
69 
70 // get map00/90 value at given time and frequency
71 inline float get_map00(WSeries<double> *WS, int time, int freq) {return get_map00(WS, time*(WS->maxLayer()+1)+freq);}
72 inline float get_map90(WSeries<double> *WS, int time, int freq) {return get_map90(WS, time*(WS->maxLayer()+1)+freq);}
73 
74 class wavegraph : public TNamed {
75 
76 public:
77 
78  wavegraph() {};
79  ~wavegraph() {};
80 
81  void create(const std::string& srcfile);
82 
83  void clear(){stride=0; span=0; scalemin=0; scalemax=0; nscales=0; samp_freq=0; graph.clear();}
84 
85  void print();
86 
87  void add_node(const int nodeidx, const int timeidx, const int freqidx, const int scaleidx,
88  const double value_avg, const double value_stdev,
89  const bool endnode, const nodeids& ancestors);
90 
91  void add_node(const wavenode node);
92 
93  int size() {return graph.size();}
94 
95  wavenode get_node(int id) {return graph.at(id);}
96 
97  nodeids get_ancestors(int id){return graph.at(id).ancestors;}
98 
99  int nodeid(int id) {return graph[id].nodeid;}
100 
101  int time(int id) {return graph[id].timeix;}
102 
103  int freq(int id) {return graph[id].freqix;}
104 
105  int scale(int id) {return graph[id].scaleix;}
106 
107  int is_endnode(int id) {return graph[id].is_endnode;}
108 
109  int get_span(){return span;}
110 
111  int get_stride(){return stride;}
112 
114 
115  void heaviest_path(std::vector<double>& total_weight, std::vector<int>& total_length,
116  std::vector<int>& best_ancestor, const std::vector<double> weights);
117 
118  bool is_compatible(const std::vector< WSeries<double>* >& data);
119 
120  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);
121 
122 private:
123 
124  nodes graph; // graph object
125  int span; // width of the graph (measured by a number of samples at the largest scale)
126  int stride; // number of samples at largest scale between a block and the next one
127  int scalemin; // smallest scale used to compute the graph
128  int scalemax; // largest scale used to compute the graph
129  int nscales; // number of scales used to compute the graph
130  int samp_freq; // sampling frequency in Hertz used to compute the graph
131 
132  ClassDef(wavegraph,0)
133 
134 };
135 
136 #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:493
bool is_compatible(const std::vector< WSeries< double > * > &data)
Definition: wavegraph.cc:438
virtual void rate(double r)
Definition: wavearray.hh:141
int num_of_time_bins(WSeries< double > *WS)
Definition: wavegraph.hh:51
int time(int id)
Definition: wavegraph.hh:101
int nodeid(int id)
Definition: wavegraph.hh:99
size_t maxIndex()
Definition: wseries.hh:149
int nscales
Definition: wavegraph.hh:129
DataType_t * pWWS
Definition: WaveDWT.hh:141
float freq_res(WSeries< double > *WS)
Definition: wavegraph.hh:54
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:366
float get_map00(WSeries< double > *WS, int index)
Definition: wavegraph.hh:58
float time_res(WSeries< double > *WS)
Definition: wavegraph.hh:55
nodes graph
Definition: wavegraph.hh:124
int getLevel()
Definition: wseries.hh:109
wavenode get_node(int id)
Definition: wavegraph.hh:95
wavearray< double > freq
Definition: Regression_H1.C:79
int stride
Definition: wavegraph.hh:126
int size()
Definition: wavegraph.hh:93
std::set< int > nodeids
Definition: wavepath.hh:37
int scalemax
Definition: wavegraph.hh:128
bool is_topologically_sorted()
Definition: wavegraph.cc:323
int num_of_freq_bins(WSeries< double > *WS)
Definition: wavegraph.hh:48
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:77
int is_endnode(int id)
Definition: wavegraph.hh:107
nodeids get_ancestors(int id)
Definition: wavegraph.hh:97
int scalemin
Definition: wavegraph.hh:127
int get_span()
Definition: wavegraph.hh:109
void create(const std::string &srcfile)
Definition: wavegraph.cc:117
int get_scale(WSeries< double > *WS)
Definition: wavegraph.hh:45
wavearray< int > index
int get_stride()
Definition: wavegraph.hh:111
~wavegraph()
Definition: wavegraph.hh:79
int samp_freq
Definition: wavegraph.hh:130
void clear()
Definition: wavegraph.hh:83
int scale(int id)
Definition: wavegraph.hh:105
Long_t id
WaveDWT< DataType_t > * pWavelet
Definition: wseries.hh:456
float get_map90(WSeries< double > *WS, int index)
Definition: wavegraph.hh:68
void print()
Definition: wavegraph.cc:296
int freq(int id)
Definition: wavegraph.hh:103
size_t sizeZero()
Definition: wseries.hh:144
std::vector< wavenode > nodes
Definition: wavepath.hh:60
int maxLayer()
Definition: wseries.hh:139