queso-0.57.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
QUESO::BaseVectorRV< V, M > Class Template Referenceabstract

A templated base class for handling vector RV. More...

#include <VectorRV.h>

Inheritance diagram for QUESO::BaseVectorRV< V, M >:
QUESO::GaussianVectorRV< Q_V, Q_M > QUESO::GenericVectorRV< P_V, P_M > QUESO::GenericVectorRV< Q_V, Q_M > QUESO::BetaVectorRV< V, M > QUESO::ConcatenatedVectorRV< V, M > QUESO::GammaVectorRV< V, M > QUESO::GaussianVectorRV< V, M > QUESO::GenericVectorRV< V, M > QUESO::InverseGammaVectorRV< V, M > QUESO::InvLogitGaussianVectorRV< V, M > QUESO::JeffreysVectorRV< V, M > QUESO::LogNormalVectorRV< V, M > QUESO::UniformVectorRV< V, M > QUESO::WignerVectorRV< V, M >

Public Member Functions

virtual double estimateENT_ANN () const
 
Constructor/Destructor methods
 BaseVectorRV (const char *prefix, const VectorSet< V, M > &imageSet)
 Constructor. More...
 
virtual ~BaseVectorRV ()
 Virtual destructor. More...
 
Random variable-handling methods
const BaseEnvironmentenv () const
 QUESO environment; access to private attribute m_env. More...
 
const VectorSet< V, M > & imageSet () const
 Image set of the vector RV; access to private attribute m_imageSet. More...
 
const BaseJointPdf< V, M > & pdf () const
 Posterior Density Function of the vector RV; access to private attribute m_pdf. More...
 
bool has_realizer () const
 Returns true iff this RV has the ability to produce realizations (samples) More...
 
const BaseVectorRealizer< V, M > & realizer () const
 Finds a realization (sample) of the PDF of this vector RV; access to private attribute m_realizer. More...
 
const BaseVectorCdf< V, M > & subCdf () const
 Finds the Cumulative Distribution Function of this vector RV, considering only the sub-sequence of data; access to private attribute m_subCdf. More...
 
const BaseVectorCdf< V, M > & unifiedCdf () const
 Finds the Cumulative Distribution Function of this vector RV, considering the unified sequence of data; access to private attribute m_unifiedCdf. More...
 
const BaseVectorMdf< V, M > & mdf () const
 Finds the Marginal Density Function of this vector RV; access to private attribute m_mdf. More...
 

Protected Attributes

const BaseEnvironmentm_env
 
std::string m_prefix
 
const VectorSet< V, M > & m_imageSet
 
BaseJointPdf< V, M > * m_pdf
 
BaseVectorRealizer< V, M > * m_realizer
 
const BaseVectorCdf< V, M > * m_subCdf
 
const BaseVectorCdf< V, M > * m_unifiedCdf
 
const BaseVectorMdf< V, M > * m_mdf
 

I/O methods

virtual void print (std::ostream &os) const =0
 TODO: Prints the vector RV. More...
 
std::ostream & operator<< (std::ostream &os, const BaseVectorRV< V, M > &obj)
 

Detailed Description

template<class V = GslVector, class M = GslMatrix>
class QUESO::BaseVectorRV< V, M >

A templated base class for handling vector RV.

This class allows two basic but quite crucial functionalities: to compute the value of the PDF of a random variable (RV) at a point and to generate realizations (samples) from such PDF.

Definition at line 53 of file VectorRV.h.

Constructor & Destructor Documentation

template<class V, class M>
QUESO::BaseVectorRV< V, M >::BaseVectorRV ( const char *  prefix,
const VectorSet< V, M > &  imageSet 
)

Constructor.

Constructs a new instance of BaseVectorRV, given a prefix and the image set of the vector RV.

Definition at line 37 of file VectorRV.C.

References QUESO::BaseEnvironment::displayVerbosity(), QUESO::BaseVectorRV< V, M >::m_env, QUESO::BaseVectorRV< V, M >::m_prefix, and QUESO::BaseEnvironment::subDisplayFile().

40  :
41  m_env (imageSet.env()),
42  m_prefix ((std::string)(prefix)+"rv_"),
44  m_pdf (NULL),
45  m_realizer (NULL),
46  m_subCdf (NULL),
47  m_unifiedCdf(NULL),
48  m_mdf (NULL)
49 {
50  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
51  *m_env.subDisplayFile() << "Entering BaseVectorRV<V,M>::constructor()"
52  << ": prefix = " << m_prefix
53  << std::endl;
54  }
55 
56  if ((m_env.subDisplayFile()) && (m_env.displayVerbosity() >= 54)) {
57  *m_env.subDisplayFile() << "Leaving BaseVectorRV<V,M>::constructor()"
58  << ": prefix = " << m_prefix
59  << std::endl;
60  }
61 }
std::string m_prefix
Definition: VectorRV.h:118
const BaseVectorCdf< V, M > * m_unifiedCdf
Definition: VectorRV.h:123
const BaseEnvironment & m_env
Definition: VectorRV.h:117
const VectorSet< V, M > & imageSet() const
Image set of the vector RV; access to private attribute m_imageSet.
Definition: VectorRV.C:83
BaseVectorRealizer< V, M > * m_realizer
Definition: VectorRV.h:121
BaseJointPdf< V, M > * m_pdf
Definition: VectorRV.h:120
const BaseVectorCdf< V, M > * m_subCdf
Definition: VectorRV.h:122
unsigned int displayVerbosity() const
Definition: Environment.C:450
const VectorSet< V, M > & m_imageSet
Definition: VectorRV.h:119
const BaseVectorMdf< V, M > * m_mdf
Definition: VectorRV.h:124
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
template<class V , class M >
QUESO::BaseVectorRV< V, M >::~BaseVectorRV ( )
virtual

Virtual destructor.

Definition at line 64 of file VectorRV.C.

65 {
66  //if (m_mdf ) delete m_mdf;
67  //if (m_subCdf ) delete m_subCdf;
68  //if (m_unifiedCdf) delete m_unifiedCdf;
69  //if (m_realizer ) delete m_realizer;
70  //if (m_pdf ) delete m_pdf;
71 }

Member Function Documentation

template<class V , class M >
const BaseEnvironment & QUESO::BaseVectorRV< V, M >::env ( ) const

QUESO environment; access to private attribute m_env.

Definition at line 76 of file VectorRV.C.

77 {
78  return m_env;
79 }
const BaseEnvironment & m_env
Definition: VectorRV.h:117
template<class V , class M >
double QUESO::BaseVectorRV< V, M >::estimateENT_ANN ( ) const
virtual

Definition at line 144 of file VectorRV.C.

References annAllocPts(), annDeallocPts(), dim, and QUESO::distANN_XY().

145 {
146  ANNpointArray data;
147  double* dists;
148  double ENT_est;
149 
150  // FIXME: these default values should be stored in the
151  // QUESO input file ( create a InfoTheoryOptions )
152  unsigned int k = UQ_INFTH_ANN_KNN;
153  double eps = UQ_INFTH_ANN_EPS;
154 
155  // here it is assumed that the entropy for the
156  // entire joint RV will be computed
157  unsigned int dim = this->imageSet().vectorSpace().dimGlobal();
158 
159  // FIXME: get the number already stored, otherwise
160  // use the default value
161  unsigned int N = this->realizer().subPeriod();
162  if( N == 0 ) {
163  N = UQ_INFTH_ANN_NO_SMP;
164  }
165 
166  // allocate memory
167  data = annAllocPts(N,dim);
168  dists = new double[N];
169 
170  // copy samples in the ANN data structure
171  V smpRV( this->imageSet().vectorSpace().zeroVector() );
172  for( unsigned int i = 0; i < N; i++ ) {
173  // get a sample from the distribution
174  this->realizer().realization( smpRV );
175  // copy the vector values in the ANN data structure
176  for( unsigned int j = 0; j < dim; j++ ) {
177  data[ i ][ j ] = smpRV[ j ];
178  }
179  }
180 
181  // get distance to knn for each point
182  // (k+1) because the 1st nn is itself
183  distANN_XY( data, data, dists, dim, dim, N, N, k+1, eps );
184 
185  // compute the entropy estimate using the L-infinity (Max) norm
186  // so no need for the adjustment of the mass of the hyperball
187  // this has to be enforced before compiling the ANN lib
188  double sum_log_dist = 0.0;
189  for( unsigned int i = 0; i < N; i++ ) {
190  if( dists[ i ] > 0 ) {
191  sum_log_dist += log( 2.0*dists[ i ] );
192  }
193  }
194  ENT_est = - gsl_sf_psi_int( k ) + gsl_sf_psi_int( N ) + (double)dim / (double)N * sum_log_dist; // todo: take specificity of gsl_, i.e., make it general (gsl or boost or etc)
195 
196  // deallocate memory
197  delete [] dists;
198  annDeallocPts( data );
199 
200  return ENT_est;
201 }
ANNpoint * ANNpointArray
Definition: ANN.h:376
const VectorSet< V, M > & imageSet() const
Image set of the vector RV; access to private attribute m_imageSet.
Definition: VectorRV.C:83
void distANN_XY(const ANNpointArray dataX, const ANNpointArray dataY, double *distsXY, unsigned int dimX, unsigned int dimY, unsigned int xN, unsigned int yN, unsigned int k, double eps)
DLL_API void annDeallocPts(ANNpointArray &pa)
Definition: ANN.cpp:133
int dim
Definition: ann_test.cpp:472
DLL_API ANNpointArray annAllocPts(int n, int dim)
Definition: ANN.cpp:117
const BaseVectorRealizer< V, M > & realizer() const
Finds a realization (sample) of the PDF of this vector RV; access to private attribute m_realizer...
Definition: VectorRV.C:106
template<class V , class M >
bool QUESO::BaseVectorRV< V, M >::has_realizer ( ) const

Returns true iff this RV has the ability to produce realizations (samples)

Definition at line 99 of file VectorRV.C.

Referenced by QUESO::ConcatenatedVectorRV< V, M >::ConcatenatedVectorRV().

100 {
101  return (m_realizer != NULL);
102 }
BaseVectorRealizer< V, M > * m_realizer
Definition: VectorRV.h:121
template<class V , class M >
const VectorSet< V, M > & QUESO::BaseVectorRV< V, M >::imageSet ( ) const
template<class V , class M >
const BaseVectorMdf< V, M > & QUESO::BaseVectorRV< V, M >::mdf ( ) const

Finds the Marginal Density Function of this vector RV; access to private attribute m_mdf.

Definition at line 133 of file VectorRV.C.

Referenced by QUESO::GenericVectorRV< V, M >::GenericVectorRV().

134 {
135  queso_require_msg(m_mdf, "m_mdf is NULL");
136 
137  return *m_mdf;
138 }
const BaseVectorMdf< V, M > * m_mdf
Definition: VectorRV.h:124
template<class V , class M >
const BaseJointPdf< V, M > & QUESO::BaseVectorRV< V, M >::pdf ( ) const

Posterior Density Function of the vector RV; access to private attribute m_pdf.

Definition at line 90 of file VectorRV.C.

Referenced by QUESO::GenericVectorRV< V, M >::GenericVectorRV().

91 {
92  queso_require_msg(m_pdf, "m_pdf is NULL");
93 
94  return *m_pdf;
95 }
BaseJointPdf< V, M > * m_pdf
Definition: VectorRV.h:120
template<class V , class M >
const BaseVectorRealizer< V, M > & QUESO::BaseVectorRV< V, M >::realizer ( ) const
template<class V , class M >
const BaseVectorCdf< V, M > & QUESO::BaseVectorRV< V, M >::subCdf ( ) const

Finds the Cumulative Distribution Function of this vector RV, considering only the sub-sequence of data; access to private attribute m_subCdf.

Definition at line 115 of file VectorRV.C.

Referenced by QUESO::GenericVectorRV< V, M >::GenericVectorRV().

116 {
117  queso_require_msg(m_subCdf, "m_subCdf is NULL");
118 
119  return *m_subCdf;
120 }
const BaseVectorCdf< V, M > * m_subCdf
Definition: VectorRV.h:122
template<class V , class M >
const BaseVectorCdf< V, M > & QUESO::BaseVectorRV< V, M >::unifiedCdf ( ) const

Finds the Cumulative Distribution Function of this vector RV, considering the unified sequence of data; access to private attribute m_unifiedCdf.

Definition at line 124 of file VectorRV.C.

Referenced by QUESO::GenericVectorRV< V, M >::GenericVectorRV().

125 {
126  queso_require_msg(m_unifiedCdf, "m_unifiedCdf is NULL");
127 
128  return *m_unifiedCdf;
129 }
const BaseVectorCdf< V, M > * m_unifiedCdf
Definition: VectorRV.h:123

Friends And Related Function Documentation

template<class V = GslVector, class M = GslMatrix>
std::ostream& operator<< ( std::ostream &  os,
const BaseVectorRV< V, M > &  obj 
)
friend

Definition at line 100 of file VectorRV.h.

101  {
102  obj.print(os);
103  return os;
104  }

Member Data Documentation


The documentation for this class was generated from the following files:

Generated on Tue Jun 5 2018 19:49:39 for queso-0.57.1 by  doxygen 1.8.5