SynAPSE  0.6.0
Synergistic Analysis of Phase Space Evolution
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
DensityEstimator.hh
1 #ifndef DENSITYESTIMATOR_HH
2 #define DENSITYESTIMATOR_HH
3 
4 // C++ includes
5 #include <iostream>
6 #include <ctime>
7 #include <cmath>
8 #include <vector>
9 
10 // ROOT includes
11 #include "TRandom3.h"
12 
13 // Additional includes
14 #include "Vector.hh"
15 #include "Matrix.hh"
16 #include "Geometry.hh"
17 #include "OptimalBinning.hh"
18 #include "KNearestNeighbours.hh"
19 #include "LocalReachability.hh"
20 #include "TDE.hh"
21 #include "PBATDE.hh"
22 #include "ProbabilityContour.hh"
23 
32  public:
35 
43  DensityEstimator(const std::vector<std::vector<double>>& points,
44  const std::string algo="bin",
45  const bool ex=true,
46  const double norm=1.);
47 
50 
53 
58  double operator()(const std::vector<double>& v) const { return Evaluate(v); }
59 
64  double operator()(const double& v) const { return Evaluate(v); }
65 
70  double operator()(const double* v) const { return Evaluate(v); }
71 
74 
76  void Initialize();
77 
82  double Evaluate(const std::vector<double>& v) const;
83 
88  double Evaluate(const double& v) const;
89 
94  double Evaluate(const double* v) const;
95 
107  double ContourVolume(double alpha,
108  const std::string method="mc",
109  const bool draw=true,
110  std::vector<double> lower=std::vector<double>(),
111  std::vector<double> upper=std::vector<double>(),
112  const size_t nsamples=1e6);
113 
118  double ContourVolumeError();
119 
126  TH1F* Contour1D(size_t idx=0) const { return _prob.Contour1D(idx); }
127 
135  TH2F* Contour2D(size_t idx=0, size_t idy=1) const { return _prob.Contour2D(idx, idy); }
136 
145  TH3F* Contour3D(size_t idx=0, size_t idy=1, size_t idz=2) const
146  { return _prob.Contour3D(idx, idy, idz); }
147 
149  const size_t& GetDimension() const { return _dim; }
150 
152  const std::vector<std::vector<double>>& GetPoints() const
153  { return _points; }
154 
156  const std::vector<std::vector<double>>& GetCVTpoints() const
157  { return _tde.GetPointArray(); }
158 
167  Grid GetGrid(const std::vector<size_t>& number,
168  const std::vector<double> lower=std::vector<double>(),
169  const std::vector<double> upper=std::vector<double>()) const;
170 
175  std::vector<TPolyLine*> Meshing() const;
176 
181  std::vector<TPolyLine*> Tesselation() const;
182 
184  void SetName(const std::string& name) { _name = name+"_"+_algo; }
185 
193  TGraph* Graph(double xmin, double xmax,
194  size_t idx=0, std::vector<double> x=std::vector<double>()) const;
195 
206  TH2F* Graph2D(double xmin, double xmax, double ymin, double ymax,
207  size_t idx=0, size_t idy=1, std::vector<double> x=std::vector<double>()) const;
208 
220  void Draw(double xmin, double xmax, double ymin=0, double ymax=0, const std::string opt="",
221  int idx=0, int idy=1, std::vector<double> x=std::vector<double>()) const;
222 
234  void Print(double xmin, double xmax, double ymin=0, double ymax=0, const std::string opt="",
235  int idx=0, int idy=1, std::vector<double> x=std::vector<double>()) const;
236 
237  private:
238 
239  size_t _dim;
240  std::string _name;
241  std::string _algo;
242  std::vector<std::vector<double>> _points;
249  bool _ex;
250  double _norm;
251 };
252 
253 #endif
double ContourVolume(double alpha, const std::string method="mc", const bool draw=true, std::vector< double > lower=std::vector< double >(), std::vector< double > upper=std::vector< double >(), const size_t nsamples=1e6)
Returns the volume of an alpha contour of the probability density function.
Definition: DensityEstimator.cc:162
std::string _algo
Density estimation algorithm.
Definition: DensityEstimator.hh:241
PBATDE _pbatde
PBA tesselation density estimator.
Definition: DensityEstimator.hh:247
double operator()(const double &v) const
Overloaded function operator, calls Evaluate.
Definition: DensityEstimator.hh:64
double _norm
Norm. factor (truncated parent)
Definition: DensityEstimator.hh:250
bool _ex
Extrapolation switch.
Definition: DensityEstimator.hh:249
size_t _dim
Dimension of the space.
Definition: DensityEstimator.hh:239
double ContourVolumeError()
Returns the uncertainty on the uncertainty on the reconstructed contour volume.
Definition: DensityEstimator.cc:283
Computes the Optimal Binning density estimator of a set of points.
Definition: OptimalBinning.hh:28
TH2F * Graph2D(double xmin, double xmax, double ymin, double ymax, size_t idx=0, size_t idy=1, std::vector< double > x=std::vector< double >()) const
Returns a 2D histogram of the estimator in the requested axis.
Definition: DensityEstimator.cc:398
TDE _tde
Tesselation density estimator.
Definition: DensityEstimator.hh:246
Grid GetGrid(const std::vector< size_t > &number, const std::vector< double > lower=std::vector< double >(), const std::vector< double > upper=std::vector< double >()) const
Returns a grid built on the DensityEstimator, which is defined everywhere.
Definition: DensityEstimator.cc:309
double operator()(const double *v) const
Overloaded function operator, calls Evaluate.
Definition: DensityEstimator.hh:70
LocalReachability _lrd
LRD density estimator.
Definition: DensityEstimator.hh:245
DensityEstimator()
Default constructor, initilizes everything to 0.
Definition: DensityEstimator.cc:3
Data structure for a grid of points and their mapping onto a scalar field.
Definition: Grid.hh:19
Set of functions that compose the Geometry package.
Computes the non parametric density estimator of a set of points.
Definition: DensityEstimator.hh:31
KNearestNeighbours _knn
kNN density estimator
Definition: DensityEstimator.hh:244
TH3F * Contour3D(size_t idx=0, size_t idy=1, size_t idz=2) const
Returns the requested 3D contour on a function.
Definition: DensityEstimator.hh:145
const size_t & GetDimension() const
Returns the dimension of the space in which the estimator is constructed.
Definition: DensityEstimator.hh:149
std::string _name
Name of the density estimator.
Definition: DensityEstimator.hh:240
double operator()(const std::vector< double > &v) const
Overloaded function operator, calls Evaluate.
Definition: DensityEstimator.hh:58
Computes the Tesselation Density Estimator (TDE) of a set of points.
Definition: TDE.hh:22
void Print(double xmin, double xmax, double ymin=0, double ymax=0, const std::string opt="", int idx=0, int idy=1, std::vector< double > x=std::vector< double >()) const
Creates a canvas, draws the estimator on it and save it to a file.
Definition: DensityEstimator.cc:445
TH3F * Contour3D(size_t idx=0, size_t idy=1, size_t idz=2) const
Returns the requested 2D contour on a function.
Definition: ProbabilityContour.cc:157
ProbabilityContour _prob
Stores the last requested contour.
Definition: DensityEstimator.hh:248
DensityEstimator & operator=(const DensityEstimator &de)
Equality operator.
Definition: DensityEstimator.cc:29
void SetName(const std::string &name)
Sets the name of the density estimator.
Definition: DensityEstimator.hh:184
TH1F * Contour1D(size_t idx=0) const
Returns segments that represent the 1D contour on a function.
Definition: ProbabilityContour.cc:70
TGraph * Graph(double xmin, double xmax, size_t idx=0, std::vector< double > x=std::vector< double >()) const
Returns a 1D graph of the estimator in the requested axis.
Definition: DensityEstimator.cc:369
void Initialize()
Initializes the requested density estimator.
Definition: DensityEstimator.cc:51
TH2F * Contour2D(size_t idx=0, size_t idy=1) const
Returns the requested 2D contour on a function.
Definition: ProbabilityContour.cc:114
OptimalBinning _ob
Optimal binning density estimator.
Definition: DensityEstimator.hh:243
Computes the Local Reachability density estimator of a set of points.
Definition: LocalReachability.hh:24
Computes the k-Nearest Neighbour (kNN) density estimator of a set of points.
Definition: KNearestNeighbours.hh:27
TH1F * Contour1D(size_t idx=0) const
Returns segments that represent the 1D contour on a function.
Definition: DensityEstimator.hh:126
Reconstructs the optimal α-contour of a Probability Density Function.
Definition: ProbabilityContour.hh:31
double Evaluate(const std::vector< double > &v) const
Performs the density estimation at an n-point v.
Definition: DensityEstimator.cc:121
std::vector< std::vector< double > > _points
Array of input points.
Definition: DensityEstimator.hh:242
const std::vector< std::vector< double > > & GetCVTpoints() const
Returns the CVT points of the space.
Definition: DensityEstimator.hh:156
std::vector< TPolyLine * > Meshing() const
Returns the meshing used to build the interpolation as polygons.
Definition: DensityEstimator.cc:342
void Draw(double xmin, double xmax, double ymin=0, double ymax=0, const std::string opt="", int idx=0, int idy=1, std::vector< double > x=std::vector< double >()) const
Draws the estimator on whichever TCanvas is currently being used (ROOT)
Definition: DensityEstimator.cc:430
TH2F * Contour2D(size_t idx=0, size_t idy=1) const
Returns the requested 2D contour on a function.
Definition: DensityEstimator.hh:135
const std::vector< std::vector< double > > & GetPointArray() const
Returns the array of points on which the triangulation is constructed.
Definition: TDE.hh:90
const std::vector< std::vector< double > > & GetPoints() const
Returns the points on which the DensityEstimator is constructed.
Definition: DensityEstimator.hh:152
~DensityEstimator()
Destructor.
Definition: DensityEstimator.cc:49
std::vector< TPolyLine * > Tesselation() const
Returns the tesselation of the space as polygons.
Definition: DensityEstimator.cc:358
Computes the Penalised Bootstrap Aggregate Tesselation Density Estimator (PBATDE) of a set of points...
Definition: PBATDE.hh:31