/usr/include/openturns/DistributionImplementation.hxx is in libopenturns-dev 0.15-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 | // -*- C++ -*-
/**
* @file DistributionImplementation.hxx
* @brief Abstract top-level class for all distributions
*
* (C) Copyright 2005-2011 EDF-EADS-Phimeca
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License.
*
* This library is distributed in the hope that it will be useful
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* @author: $LastChangedBy: schueller $
* @date: $LastChangedDate: 2011-07-28 18:31:43 +0200 (Thu, 28 Jul 2011) $
* Id: $Id: DistributionImplementation.hxx 2046 2011-07-28 16:31:43Z schueller $
*/
#ifndef OPENTURNS_DISTRIBUTIONIMPLEMENTATION_HXX
#define OPENTURNS_DISTRIBUTIONIMPLEMENTATION_HXX
#include "PersistentObject.hxx"
#include "NumericalPoint.hxx"
#include "NumericalPointWithDescription.hxx"
#include "NumericalSample.hxx"
#include "Indices.hxx"
#include "Interval.hxx"
#include "CorrelationMatrix.hxx"
#include "SquareMatrix.hxx"
#include "Graph.hxx"
#include "Description.hxx"
#include "NumericalMathFunction.hxx"
#include "PersistentCollection.hxx"
#include "UniVariatePolynomial.hxx"
namespace OpenTURNS {
namespace Uncertainty {
namespace Model {
/**
* @class DistributionImplementation
*
* The class describes the probabilistic concept of distribution.
* Instances of this class can produce samples following the
* distribution, can compute PDF or CDF, etc.
* They are the actual key component of RandomVectors.
*/
class DistributionImplementation
: public Base::Common::PersistentObject
{
CLASSNAME;
public:
// For drawing PDF and CDF graphs
static const UnsignedLong DefaultPointNumber; /* = 129 */
// Numerical precision for computing the quantile
static const NumericalScalar DefaultQuantileEpsilon; /* = 1e-12 */
// Numerical precision for computing the PDF
static const NumericalScalar DefaultPDFEpsilon; /* = 1e-14 */
// Numerical precision for computing the CDF
static const NumericalScalar DefaultCDFEpsilon; /* = 1e-14 */
// Newton iterations for computing the quantile
static const UnsignedLong DefaultQuantileIteration; /* = 10 */
// Lower quantile level for drawing
static const NumericalScalar QMin; /* = 1.5e-1 */
// Upper quantile level for drawing
static const NumericalScalar QMax; /* = 8.5e-1 */
// Default number of integration points for Gauss integration
static const UnsignedLong DefaultIntegrationNodesNumber; /* = 255 */
// Default number of level in Sinh Tanh integration method
static const UnsignedLong DefaultLevelNumber; /* = 10 */
// Cache size for the scalar quantile cache
static const UnsignedLong DefaultQuantileCacheSize; /* = 128 */
typedef Base::Common::InvalidArgumentException InvalidArgumentException;
typedef Base::Common::InvalidDimensionException InvalidDimensionException;
typedef Base::Common::InternalException InternalException;
typedef Base::Common::NotDefinedException NotDefinedException;
typedef Base::Func::UniVariatePolynomial UniVariatePolynomial;
typedef Base::Type::NumericalPoint NumericalPoint;
typedef Base::Type::NumericalPointWithDescription NumericalPointWithDescription;
typedef Base::Stat::NumericalSample NumericalSample;
typedef Base::Stat::CovarianceMatrix CovarianceMatrix;
typedef Base::Stat::CorrelationMatrix CorrelationMatrix;
typedef Base::Type::SquareMatrix SquareMatrix;
typedef Base::Type::Indices Indices;
typedef Base::Type::Interval Interval;
typedef Pointer<DistributionImplementation> Implementation;
typedef Base::Func::NumericalMathFunction IsoProbabilisticTransformation;
typedef IsoProbabilisticTransformation InverseIsoProbabilisticTransformation;
typedef Base::Graph::Graph Graph;
typedef Base::Type::Collection<NumericalPoint> NumericalPointCollection;
typedef Base::Type::Collection<NumericalPointWithDescription> NumericalPointWithDescriptionCollection;
typedef Base::Type::Description Description;
typedef Base::Common::StorageManager StorageManager;
/** Default constructor */
DistributionImplementation(const String & name = OT::DefaultName);
/** Comparison operator */
Bool operator ==(const DistributionImplementation & other) const;
/** String converter */
virtual String __repr__() const;
String __str__(const String & offset = "") const;
/** Weight accessor */
void setWeight(NumericalScalar w) /* throw(InvalidArgumentException) */;
NumericalScalar getWeight() const;
/** Dimension accessor */
UnsignedLong getDimension() const;
/* Here is the interface that all derived class must implement */
/** Virtual constructor */
virtual DistributionImplementation * clone() const;
/** Get one realization of the distributionImplementation */
virtual NumericalPoint getRealization() const;
/** Get a numerical sample whose elements follow the distributionImplementation */
virtual NumericalSample getNumericalSample(const UnsignedLong size) const;
/** Get the DDF of the distributionImplementation */
virtual NumericalScalar computeDDF(const NumericalScalar scalar) const;
virtual NumericalPoint computeDDF(const NumericalPoint & point) const;
virtual NumericalSample computeDDF(const NumericalSample & sample) const;
/** Get the PDF of the distributionImplementation */
virtual NumericalScalar computePDF(const NumericalScalar scalar) const;
virtual NumericalScalar computePDF(const NumericalPoint & point) const;
virtual NumericalSample computePDF(const NumericalSample & sample) const;
/** Compute the PDF of 1D distributions over a regular grid */
virtual NumericalSample computePDF(const NumericalScalar xMin,
const NumericalScalar xMax,
const UnsignedLong pointNumber,
const NumericalScalar precision = DefaultPDFEpsilon) const;
/** Get the CDF of the distributionImplementation */
virtual NumericalScalar computeCDF(const NumericalScalar scalar,
const Bool tail = false) const;
virtual NumericalScalar computeCDF(const NumericalPoint & point,
const Bool tail = false) const;
virtual NumericalSample computeCDF(const NumericalSample & sample,
const Bool tail = false) const;
/** Compute the CDF of 1D distributions over a regular grid */
virtual NumericalSample computeCDF(const NumericalScalar xMin,
const NumericalScalar xMax,
const UnsignedLong pointNumber,
const NumericalScalar precision = DefaultPDFEpsilon,
const Bool tail = false) const;
/** Get the probability content of an interval */
virtual NumericalScalar computeProbability(const Interval & interval) const;
/** Get the characteristic function of the distribution, i.e. phi(u) = E(exp(I*u*X)) */
virtual NumericalComplex computeCharacteristicFunction(const NumericalScalar x,
const Bool logScale = false) const;
/** Compute the generating function, i.e. psi(z) = E(z^X) */
virtual NumericalScalar computeGeneratingFunction(const NumericalScalar z,
const Bool logScale = false) const;
virtual NumericalComplex computeGeneratingFunction(const NumericalComplex & z,
const Bool logScale = false) const;
/** Get the PDF gradient of the distribution */
virtual NumericalPoint computePDFGradient(const NumericalPoint & point) const;
/** Get the CDF gradient of the distribution */
virtual NumericalPoint computeCDFGradient(const NumericalPoint & point) const;
/** Get the quantile of the distributionImplementation */
virtual NumericalPoint computeQuantile(const NumericalScalar prob,
const Bool tail = false) const;
/** Compute the quantile over a regular grid */
virtual NumericalSample computeQuantile(const NumericalScalar qMin,
const NumericalScalar qMax,
const UnsignedLong pointNumber,
const NumericalScalar precision = DefaultQuantileEpsilon,
const Bool tail = false) const;
/** Get the mathematical and numerical range of the distribution.
Its mathematical range is the smallest closed interval outside
of which the PDF is zero, and the numerical range is the interval
outside of which the PDF is rounded to zero in double precision */
virtual Interval getRange() const;
protected:
virtual void setRange(const Interval & range);
public:
/** Get the roughness, i.e. the L2-norm of the PDF */
virtual NumericalScalar getRoughness() const;
/** Get the mean of the distribution */
virtual NumericalPoint getMean() const /* throw(NotDefinedException) */;
/** Get the standard deviation of the distribution */
virtual NumericalPoint getStandardDeviation() const /* throw(NotDefinedException) */;
/** Get the skewness of the distribution */
virtual NumericalPoint getSkewness() const /* throw(NotDefinedException) */;
/** Get the kurtosis of the distribution */
virtual NumericalPoint getKurtosis() const /* throw(NotDefinedException) */;
/** Get the raw moments of the standardized distribution */
virtual NumericalPoint getStandardMoment(const UnsignedLong n) const;
/** Get the raw moments of the distribution */
virtual NumericalPoint getMoment(const UnsignedLong n) const;
/** Get the centered moments of the distribution */
virtual NumericalPoint getCenteredMoment(const UnsignedLong n) const;
/** Get the covariance of the distribution */
virtual CovarianceMatrix getCovariance() const /* throw(NotDefinedException) */;
/** Correlation matrix accessor */
CorrelationMatrix getCorrelation() const;
/** Cholesky factor of the covariance matrix accessor */
SquareMatrix getCholesky() const;
/** Inverse of the Cholesky factor of the covariance matrix accessor */
SquareMatrix getInverseCholesky() const;
/** Check if the distribution is elliptical */
virtual Bool isElliptical() const;
/** Check if the distribution is constinuous */
virtual Bool isContinuous() const;
/** Tell if the distribution is integer valued */
virtual Bool isIntegral() const;
/** Tell if the distribution has elliptical copula */
virtual Bool hasEllipticalCopula() const;
/** Tell if the distribution has independent copula */
virtual Bool hasIndependentCopula() const;
/** Get the support of a distribution that intersect a given interval */
virtual NumericalSample getSupport(const Interval & interval) const;
/** Get the support on the whole range */
virtual NumericalSample getSupport() const;
/** Compute the density generator of the elliptical generator, i.e.
* the function phi such that the density of the distribution can
* be written as p(x) = phi(t(x-mu)R(x-mu)) */
virtual NumericalScalar computeDensityGenerator(const NumericalScalar betaSquare) const;
/** Compute the derivative of the density generator */
virtual NumericalScalar computeDensityGeneratorDerivative(const NumericalScalar betaSquare) const;
/** Compute the seconde derivative of the density generator */
virtual NumericalScalar computeDensityGeneratorSecondDerivative(const NumericalScalar betaSquare) const;
/** Compute the radial distribution CDF */
virtual NumericalScalar computeRadialDistributionCDF(const NumericalScalar radius,
const Bool tail = false) const;
/** Get the i-th marginal distribution */
virtual DistributionImplementation * getMarginal(const UnsignedLong i) const /* throw(InvalidArgumentException) */;
/** Get the distribution of the marginal distribution corresponding to indices dimensions */
virtual DistributionImplementation * getMarginal(const Indices & indices) const /* throw(InvalidArgumentException) */;
/** Get the copula of a distribution */
virtual Implementation getCopula() const;
/** Compute the DDF of Xi | X1, ..., Xi-1. x = Xi, y = (X1,...,Xi-1) */
virtual NumericalScalar computeConditionalDDF(const NumericalScalar x,
const NumericalPoint & y) const;
/** Compute the PDF of Xi | X1, ..., Xi-1. x = Xi, y = (X1,...,Xi-1) */
virtual NumericalScalar computeConditionalPDF(const NumericalScalar x,
const NumericalPoint & y) const;
/** Compute the CDF of Xi | X1, ..., Xi-1. x = Xi, y = (X1,...,Xi-1) */
virtual NumericalScalar computeConditionalCDF(const NumericalScalar x,
const NumericalPoint & y) const;
/** Compute the quantile of Xi | X1, ..., Xi-1, i.e. x such that CDF(x|y) = q with x = Xi, y = (X1,...,Xi-1) */
virtual NumericalScalar computeConditionalQuantile(const NumericalScalar q,
const NumericalPoint & y) const;
/** Get the isoprobabilist transformation */
virtual IsoProbabilisticTransformation getIsoProbabilisticTransformation() const;
/** Get the inverse isoprobabilist transformation */
virtual InverseIsoProbabilisticTransformation getInverseIsoProbabilisticTransformation() const;
/** Get the standard distribution */
virtual Implementation getStandardDistribution() const;
/** integrationNodesNumber accessors */
UnsignedLong getIntegrationNodesNumber() const;
void setIntegrationNodesNumber(const UnsignedLong integrationNodesNumber) const;
/** Gauss nodes and weights accessor */
NumericalSample getGaussNodesAndWeights() const;
NumericalPoint getGaussNodesAndWeights(NumericalPoint & weights) const;
/** Draw the PDF of the distribution when its dimension is 1 or 2 */
virtual Graph drawPDF() const
/* throw(InvalidDimensionException, InvalidArgumentException) */;
/** Draw the PDF of the distribution when its dimension is 1 */
virtual Graph drawPDF(const NumericalScalar xMin,
const NumericalScalar xMax,
const UnsignedLong pointNumber = DefaultPointNumber) const
/* throw(InvalidDimensionException, InvalidArgumentException) */;
virtual Graph drawPDF(const UnsignedLong pointNumber) const
/* throw(InvalidDimensionException, InvalidArgumentException) */;
/** Draw the PDF of a 1D marginal */
virtual Graph drawMarginal1DPDF(const UnsignedLong marginalIndex,
const NumericalScalar xMin,
const NumericalScalar xMax,
const UnsignedLong pointNumber) const
/* throw(InvalidArgumentException) */;
/** Draw the PDF of the distribution when its dimension is 2 */
virtual Graph drawPDF(const NumericalPoint & xMin,
const NumericalPoint & xMax,
const NumericalPoint & pointNumber) const
/* throw(InvalidDimensionException, InvalidArgumentException) */;
virtual Graph drawPDF(const NumericalPoint & xMin,
const NumericalPoint & xMax) const
/* throw(InvalidDimensionException, InvalidArgumentException) */;
virtual Graph drawPDF(const NumericalPoint & pointNumber) const
/* throw(InvalidDimensionException, InvalidArgumentException) */;
/** Draw the PDF of a 2D marginal */
virtual Graph drawMarginal2DPDF(const UnsignedLong firstMarginal,
const UnsignedLong secondMarginal,
const NumericalPoint & xMin,
const NumericalPoint & xMax,
const NumericalPoint & pointNumber) const
/* throw(InvalidArgumentException) */;
/** Draw the CDF of the distribution when its dimension is 1 or 2 */
virtual Graph drawCDF() const
/* throw(InvalidDimensionException, InvalidArgumentException) */;
/** Draw the CDF of the distribution when its dimension is 1 */
virtual Graph drawCDF(const NumericalScalar xMin,
const NumericalScalar xMax,
const UnsignedLong pointNumber = DefaultPointNumber) const
/* throw(InvalidDimensionException, InvalidArgumentException) */;
virtual Graph drawCDF(const UnsignedLong pointNumber) const
/* throw(InvalidDimensionException, InvalidArgumentException) */;
/** Draw the CDF of the distribution when its dimension is 2 */
virtual Graph drawCDF(const NumericalPoint & xMin,
const NumericalPoint & xMax,
const NumericalPoint & pointNumber) const
/* throw(InvalidDimensionException, InvalidArgumentException) */;
virtual Graph drawCDF(const NumericalPoint & xMin,
const NumericalPoint & xMax) const
/* throw(InvalidDimensionException, InvalidArgumentException) */;
virtual Graph drawCDF(const NumericalPoint & pointNumber) const
/* throw(InvalidDimensionException, InvalidArgumentException) */;
/** Draw the CDF of a 1D marginal */
virtual Graph drawMarginal1DCDF(const UnsignedLong marginalIndex,
const NumericalScalar xMin,
const NumericalScalar xMax,
const UnsignedLong pointNumber) const
/* throw(InvalidArgumentException) */;
/** Draw the CDF of a 2D marginal */
virtual Graph drawMarginal2DCDF(const UnsignedLong firstMarginal,
const UnsignedLong secondMarginal,
const NumericalPoint & xMin,
const NumericalPoint & xMax,
const NumericalPoint & pointNumber) const
/* throw(InvalidArgumentException) */;
/** Parameters value and description accessor */
virtual NumericalPointWithDescriptionCollection getParametersCollection() const;
virtual void setParametersCollection(const NumericalPointWithDescriptionCollection & parametersCollection);
virtual void setParametersCollection(const NumericalPointCollection & parametersCollection);
virtual void setParametersCollection(const NumericalPoint & parameters);
/** Total number of parameters */
virtual UnsignedLong getParametersNumber() const;
/** Description accessor */
void setDescription(const Description & description);
Description getDescription() const;
/** Method save() stores the object through the StorageManager */
virtual void save(StorageManager::Advocate & adv) const;
/** Method load() reloads the object from the StorageManager */
virtual void load(StorageManager::Advocate & adv);
/** Accessor to PDF computation precision */
NumericalScalar getPDFEpsilon() const;
/** Accessor to CDF computation precision */
NumericalScalar getCDFEpsilon() const;
/** Get a positon indicator for a 1D distribution */
NumericalScalar getPositionIndicator() const;
/** Get a dispersion indicator for a 1D distribution */
NumericalScalar getDispersionIndicator() const;
protected:
/** Compute the PDF and CDF of Xi | X1, ..., Xi-1. x = Xi, y = (X1,...,Xi-1)
Used to speed-up the computeConditionalQuantile() method */
NumericalScalar computeConditionalPDFAndCDF(const NumericalScalar x,
const NumericalPoint & y,
NumericalScalar & cdf,
const Implementation & conditioningDistribution,
const Implementation & conditionedDistribution,
const NumericalScalar xMin) const;
/** Compute the CDF of Xi | X1, ..., Xi-1. x = Xi, y = (X1,...,Xi-1) with reuse of expansive data */
NumericalScalar computeConditionalCDFForQuantile(const NumericalScalar x,
const NumericalPoint & y,
const Implementation & conditioningDistribution,
const Implementation & conditionedDistribution,
const NumericalScalar xMin) const;
/** Compute the characteristic function of 1D distributions in a regular pattern with cache */
virtual NumericalComplex computeCharacteristicFunction(const UnsignedLong index,
const NumericalScalar step,
const Bool logScale = false) const;
/** Compute the mean of the distribution */
virtual void computeMean() const;
/** Compute the covariance of the distribution */
virtual void computeCovariance() const;
/** Compute the shifted moments of the distribution */
virtual NumericalPoint computeShiftedMoment(const UnsignedLong n,
const NumericalPoint & shift) const;
/** Compute the nodes and weights of the 1D gauss integration rule over [-1, 1] */
virtual void computeGaussNodesAndWeights() const;
/** Dimension accessor */
void setDimension(UnsignedLong dim);
/** Quantile computation for dimension=1 */
virtual NumericalScalar computeScalarQuantile(const NumericalScalar prob,
const Bool tail = false,
const NumericalScalar precision = DefaultQuantileEpsilon) const;
/** Compute the numerical range of the distribution given the parameters values */
virtual void computeRange();
virtual NumericalPoint computeLowerBound() const;
virtual NumericalPoint computeUpperBound() const;
/** Compute the standard distribution associated with the current distribution */
virtual void computeStandardDistribution() const;
mutable NumericalPoint mean_;
mutable CovarianceMatrix covariance_;
mutable NumericalSample gaussNodesAndWeights_;
/** The integration nodes number for covariance computation */
mutable UnsignedLong integrationNodesNumber_;
/** Flags to avoid redundant computations */
mutable Bool isAlreadyComputedMean_;
mutable Bool isAlreadyComputedCovariance_;
mutable Bool isAlreadyComputedGaussNodesAndWeights_;
/** Indicators for PDF and CDF absolute precision. By default, equals to DefaultPDFEpsilon, DefaultCDFEpsilon and DefaultQuantileEpsilon */
mutable NumericalScalar pdfEpsilon_;
mutable NumericalScalar cdfEpsilon_;
mutable NumericalScalar quantileEpsilon_;
/** Standard distribution */
mutable Bool isAlreadyComputedStandardDistribution_;
mutable Implementation p_standardDistribution_;
/** Optimization to make a call to computeScalarQuantile less costly
The strategy is to build a cheap approximation of the quantile
function at the first call to the computeScalarQuantile method
then to use it to initialize the quantile search
*/
void initializeQuantileCache() const;
mutable Bool isAlreadyInitializedQuantileCache_;
/** Sample that stores some precomputed quantiles: the first component is the probability level, the second component is the scalar quantile value */
mutable NumericalSample scalarQuantileCache_;
/** Optimization for the generating function evaluation */
mutable Bool isAlreadyCreatedGeneratingFunction_;
mutable UniVariatePolynomial generatingFunction_;
private:
/** The dimension of the distributionImplementation */
UnsignedLong dimension_;
/** The weight used ONLY by Mixture */
NumericalScalar weight_;
/** Range of the distribution */
Interval range_;
/** Description of each component */
Description description_;
}; /* class DistributionImplementation */
} /* namespace Model */
} /* namespace Uncertainty */
} /* namespace OpenTURNS */
#endif /* OPENTURNS_DISTRIBUTIONIMPLEMENTATION_HXX */
|