25 #include <queso/VectorRV.h>
26 #include <queso/GslVector.h>
27 #include <queso/GslMatrix.h>
29 #include <queso/Defines.h>
30 #include <gsl/gsl_sf_psi.h>
31 #include <queso/InfoTheory_impl.h>
36 template<
class V,
class M>
41 m_env (imageSet.env()),
42 m_prefix ((std::string)(prefix)+
"rv_"),
43 m_imageSet (imageSet),
63 template<
class V,
class M>
74 template <
class V,
class M>
81 template<
class V,
class M>
88 template<
class V,
class M>
92 queso_require_msg(m_pdf,
"m_pdf is NULL");
97 template<
class V,
class M>
101 return (m_realizer != NULL);
104 template<
class V,
class M>
108 queso_require_msg(m_realizer,
"m_realizer is NULL");
113 template<
class V,
class M>
117 queso_require_msg(m_subCdf,
"m_subCdf is NULL");
122 template<
class V,
class M>
126 queso_require_msg(m_unifiedCdf,
"m_unifiedCdf is NULL");
128 return *m_unifiedCdf;
131 template<
class V,
class M>
135 queso_require_msg(m_mdf,
"m_mdf is NULL");
142 template <
class V,
class M>
152 unsigned int k = UQ_INFTH_ANN_KNN;
153 double eps = UQ_INFTH_ANN_EPS;
157 unsigned int dim = this->imageSet().vectorSpace().dimGlobal();
161 unsigned int N = this->realizer().subPeriod();
163 N = UQ_INFTH_ANN_NO_SMP;
168 dists =
new double[N];
171 V smpRV( this->imageSet().vectorSpace().zeroVector() );
172 for(
unsigned int i = 0; i < N; i++ ) {
174 this->realizer().realization( smpRV );
176 for(
unsigned int j = 0; j <
dim; j++ ) {
177 data[ i ][ j ] = smpRV[ j ];
183 distANN_XY( data, data, dists, dim, dim, N, N, k+1, eps );
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 ] );
194 ENT_est = - gsl_sf_psi_int( k ) + gsl_sf_psi_int( N ) + (double)dim / (
double)N * sum_log_dist;
202 #endif // QUESO_HAS_ANN
207 template <
class P_V,
class P_M,
class Q_V,
class Q_M>
212 unsigned int localNumSamples,
220 queso_require_msg(useOnlyInter0Comm,
"parallel vectors not supported yet");
225 queso_require_msg(!((numRows != pqCovMatrix.numRows()) || (numCols != pqCovMatrix.numCols())),
"inconsistent dimensions for covariance matrix");
227 queso_require_msg(!((numRows != pqCorrMatrix.numRows()) || (numCols != pqCorrMatrix.numCols())),
"inconsistent dimensions for correlation matrix");
229 queso_require_msg(!((localNumSamples > paramRv.
realizer().period()) || (localNumSamples > qoiRv.
realizer().period())),
"localNumSamples is too large");
241 for (
unsigned int k = 0; k < localNumSamples; ++k) {
243 localWorkingPSeq.setPositionValues(k,tmpP);
246 localWorkingQSeq.setPositionValues(k,tmpQ);
const V & zeroVector() const
Returns a vector filled with zeros.
const BaseJointPdf< V, M > & pdf() const
Posterior Density Function of the vector RV; access to private attribute m_pdf.
A templated (base) class for handling sampling from vector RVs.
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
unsigned int numOfProcsForStorage() const
Returns total number of processes.
virtual void realization(V &nextValues) const =0
Performs a realization (sample) from a probability density function. See template specialization...
const BaseEnvironment & m_env
const VectorSet< V, M > & imageSet() const
Image set of the vector RV; access to private attribute m_imageSet.
A templated (base) class for handling MDFs of vector functions.
A templated (base) class for handling CDFs of vector functions.
A templated class for handling sets.
virtual const VectorSpace< V, M > & vectorSpace() const =0
Vector space to which this set belongs to. See template specialization.
const BaseVectorMdf< V, M > & mdf() const
Finds the Marginal Density Function of this vector RV; access to private attribute m_mdf...
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)
void ComputeCovCorrMatricesBetweenVectorRvs(const BaseVectorRV< P_V, P_M > ¶mRv, const BaseVectorRV< Q_V, Q_M > &qoiRv, unsigned int localNumSamples, P_M &pqCovMatrix, P_M &pqCorrMatrix)
DLL_API void annDeallocPts(ANNpointArray &pa)
Class for handling vector samples (sequence of vectors).
A templated (base) class for handling joint PDFs.
const BaseVectorCdf< V, M > & subCdf() const
Finds the Cumulative Distribution Function of this vector RV, considering only the sub-sequence of da...
BaseVectorRV(const char *prefix, const VectorSet< V, M > &imageSet)
Constructor.
virtual double estimateENT_ANN() const
const BaseEnvironment & env() const
QUESO environment; access to private attribute m_env.
unsigned int displayVerbosity() const
virtual ~BaseVectorRV()
Virtual destructor.
DLL_API ANNpointArray annAllocPts(int n, int dim)
bool has_realizer() const
Returns true iff this RV has the ability to produce realizations (samples)
const BaseVectorRealizer< V, M > & realizer() const
Finds a realization (sample) of the PDF of this vector RV; access to private attribute m_realizer...
const BaseVectorCdf< V, M > & unifiedCdf() const
Finds the Cumulative Distribution Function of this vector RV, considering the unified sequence of dat...
void ComputeCovCorrMatricesBetweenVectorSequences(const BaseVectorSequence< P_V, P_M > &subPSeq, const BaseVectorSequence< Q_V, Q_M > &subQSeq, unsigned int subNumSamples, P_M &pqCovMatrix, P_M &pqCorrMatrix)
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).