/usr/include/openturns/RandomMixture.hxx is in libopenturns-dev 1.5-7build2.
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 | // -*- C++ -*-
/**
* @file RandomMixture.hxx
* @brief The class that implements randomMixtures
*
* Copyright 2005-2015 Airbus-EDF-IMACS-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 3 of the License, or
* (at your option) any later version.
*
* 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
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* @author schueller
* @date 2012-07-16 10:12:54 +0200 (Mon, 16 Jul 2012)
*/
#ifndef OPENTURNS_RANDOMMIXTURE_HXX
#define OPENTURNS_RANDOMMIXTURE_HXX
#include "Distribution.hxx"
#include "DistributionFactory.hxx"
#include "DistributionImplementation.hxx"
#include "Collection.hxx"
#include "PersistentCollection.hxx"
#include "SpecFunc.hxx"
#include "Normal.hxx"
#include "ResourceMap.hxx"
#include "SphereUniformNorm.hxx"
#include "Indices.hxx"
#include "FFT.hxx"
#include <limits> // std::numeric_limits
BEGIN_NAMESPACE_OPENTURNS
/**
* @class RandomMixture
*
* The class describes the probabilistic concept of RandomMixture.
*/
class OT_API RandomMixture
: public DistributionImplementation
{
CLASSNAME;
public:
typedef Collection<Distribution> DistributionCollection;
typedef PersistentCollection<Distribution> DistributionPersistentCollection;
typedef PersistentCollection<NumericalComplex> NumericalComplexPersistentCollection;
typedef Collection<DistributionFactory> DistributionFactoryCollection;
/** Parameter constructor - 1D */
explicit RandomMixture(const DistributionCollection & coll,
const NumericalScalar constant = 0.0);
/** Parameter constructor - 1D */
explicit RandomMixture(const DistributionCollection & coll,
const NumericalPoint & weights,
const NumericalScalar constant = 0.0);
/** Parameter constructor - nD */
RandomMixture(const DistributionCollection & coll,
const Matrix & weights,
const NumericalPoint constant);
/** Parameter constructor - nD */
RandomMixture(const DistributionCollection & coll,
const Matrix & weights);
/** Parameter constructor - nD */
RandomMixture(const DistributionCollection & coll,
const NumericalSample & weights,
const NumericalPoint constant);
/** Parameter constructor - nD */
RandomMixture(const DistributionCollection & coll,
const NumericalSample & weights);
/** Comparison operator */
Bool operator ==(const RandomMixture & other) const;
/** String converter */
String __repr__() const;
String __str__(const String & offset = "") const;
/** Distribution collection accessor */
const DistributionCollection & getDistributionCollection() const;
/** FFT algorithm accessor */
FFT getFFTAlgorithm() const;
void setFFTAlgorithm(const FFT & fft);
/** Constant accessor */
void setConstant(const NumericalPoint & constant);
NumericalPoint getConstant() const;
/* Here is the interface that all derived class must implement */
/** Virtual constructor */
virtual RandomMixture * clone() const;
/** Get one realization of the RandomMixture */
NumericalPoint getRealization() const;
/** Get the DDF of the RandomMixture */
using DistributionImplementation::computeDDF;
NumericalPoint computeDDF(const NumericalPoint & point) const;
/** Get the PDF of the RandomMixture */
using DistributionImplementation::computePDF;
NumericalScalar computePDF(const NumericalPoint & point) const;
/** Compute the PDF over a regular grid */
NumericalSample computePDF(const NumericalScalar xMin,
const NumericalScalar xMax,
const UnsignedInteger pointNumber,
NumericalSample & grid) const;
/* Compute the PDF of over a regular grid */
NumericalSample computePDF(const NumericalPoint & xMin,
const NumericalPoint & xMax,
const Indices & pointNumber,
NumericalSample & grid) const;
/** Get the i-th marginal distribution */
Implementation getMarginal(const UnsignedInteger i) const;
/** Get the distribution of the marginal distribution corresponding to indices dimensions */
Implementation getMarginal(const Indices & indices) const;
protected:
private:
/** Quantile computation for dimension=1 */
NumericalScalar computeScalarQuantile(const NumericalScalar prob,
const Bool tail = false) const;
/** Compute the characteristic function of 1D distributions by difference to a reference Normal distribution with the same mean and the same standard deviation in a regular pattern with cache */
NumericalComplex computeDeltaCharacteristicFunction(const UnsignedInteger index) const;
/** Compute the characteristic function of nD distributions by difference to a reference Normal distribution with the same mean and the same covariance */
friend struct AddPDFOn1DGridPolicy;
friend struct AddPDFOn2DGridPolicy;
friend struct AddPDFOn3DGridPolicy;
NumericalComplex computeDeltaCharacteristicFunction(const NumericalPoint & x) const;
/** Update cache of the characteristic function */
void updateCacheDeltaCharacteristicFunction(const NumericalSample & points) const;
/** Contribution to computePDF on a 1D grid */
void addPDFOn1DGrid(const Indices & pointNumber, const NumericalPoint & h, const NumericalPoint & tau, NumericalSample & result) const;
/** Contribution to computePDF on a 2D grid */
void addPDFOn2DGrid(const Indices & pointNumber, const NumericalPoint & h, const NumericalPoint & tau, NumericalSample & result) const;
/** Contribution to computePDF on a 3D grid */
void addPDFOn3DGrid(const Indices & pointNumber, const NumericalPoint & h, const NumericalPoint & tau, NumericalSample & result) const;
public:
/** Get the CDF of the RandomMixture */
using DistributionImplementation::computeCDF;
NumericalScalar computeCDF(const NumericalPoint & point) const;
using DistributionImplementation::computeComplementaryCDF;
NumericalScalar computeComplementaryCDF(const NumericalPoint & point) const;
/** Compute the CDF over a regular grid */
NumericalSample computeCDF(const NumericalScalar xMin,
const NumericalScalar xMax,
const UnsignedInteger pointNumber,
NumericalSample & grid) const;
/** Get the probability content of an interval */
NumericalScalar computeProbability(const Interval & interval) const;
/** Compute the quantile over a regular grid */
using DistributionImplementation::computeQuantile;
NumericalSample computeQuantile(const NumericalScalar qMin,
const NumericalScalar qMax,
const UnsignedInteger pointNumber,
const Bool tail = false) const;
/** Get the characteristic function of the distribution, i.e. phi(u) = E(exp(I*u*X)) */
using DistributionImplementation::computeCharacteristicFunction;
NumericalComplex computeCharacteristicFunction(const NumericalScalar x) const;
NumericalComplex computeCharacteristicFunction(const NumericalPoint & x) const;
using DistributionImplementation::computeLogCharacteristicFunction;
NumericalComplex computeLogCharacteristicFunction(const NumericalScalar x) const;
NumericalComplex computeLogCharacteristicFunction(const NumericalPoint & x) const;
/** Get the PDF gradient of the distribution */
using DistributionImplementation::computePDFGradient;
NumericalPoint computePDFGradient(const NumericalPoint & point) const;
/** Get the CDF gradient of the distribution */
using DistributionImplementation::computeCDFGradient;
NumericalPoint computeCDFGradient(const NumericalPoint & point) const;
/** Parameters value and description accessor */
NumericalPointWithDescriptionCollection getParametersCollection() const;
/** Weights distribution accessor */
protected:
void setWeights(const Matrix & weights);
void setDistributionCollection(const DistributionCollection & coll);
public:
Matrix getWeights() const;
/** Get a positon indicator for a 1D distribution */
NumericalScalar getPositionIndicator() const;
/** Get a dispersion indicator for a 1D distribution */
NumericalScalar getDispersionIndicator() const;
/** BlockMin accessor */
void setBlockMin(const UnsignedInteger blockMin);
UnsignedInteger getBlockMin() const;
/** BlockMax accessor */
void setBlockMax(const UnsignedInteger blockMax);
UnsignedInteger getBlockMax() const;
/** MaxSize accessor */
void setMaxSize(const UnsignedInteger maxSize);
UnsignedInteger getMaxSize() const;
/** Alpha accessor */
void setAlpha(const NumericalScalar alpha);
NumericalScalar getAlpha() const;
/** Beta accessor */
void setBeta(const NumericalScalar beta);
NumericalScalar getBeta() const;
/** Reference bandwidth accessor */
void setReferenceBandwidth(const NumericalPoint & bandwidth);
NumericalPoint getReferenceBandwidth() const;
/** PDF epsilon accessor. For other distributions, it is a read-only attribute. */
void setPDFPrecision(const NumericalScalar pdfPrecision);
/** CDF epsilon accessor. For other distributions, it is a read-only attribute. */
void setCDFPrecision(const NumericalScalar cdfPrecision);
/** Project a RandomMixture distribution over a collection of DistributionFactory by using sampling and Kolmogorov distance. */
DistributionCollection project(const DistributionFactoryCollection & factoryCollection,
NumericalPoint & kolmogorovNorm,
const UnsignedInteger size = ResourceMap::GetAsUnsignedInteger( "RandomMixture-ProjectionDefaultSize" )) const;
/** Tell if the distribution has independent copula */
Bool hasIndependentCopula() const;
/** Tell if the distribution has elliptical copula */
Bool hasEllipticalCopula() const;
/** Check if the distribution is elliptical */
Bool isElliptical() const;
/** Check if the distribution is continuous */
Bool isContinuous() const;
/** Check if the distribution is discrete */
Bool isDiscrete() const;
/** Tell if the distribution is integer valued */
Bool isIntegral() const;
/** Method save() stores the object through the StorageManager */
void save(Advocate & adv) const;
/** Method load() reloads the object from the StorageManager */
void load(Advocate & adv);
private:
class KolmogorovProjection
{
public:
/** Constructor from a distribution and a data set */
KolmogorovProjection(const NumericalSample & dataX,
const NumericalSample & dataY,
const DistributionFactory & factory):
dataX_(dataX),
dataY_(dataY),
factory_(factory) {};
/** Compute the Kolmogorov distance based on the given data, for a given parameter set */
NumericalPoint computeNorm(const NumericalPoint & parameters) const
{
NumericalScalar norm(0.0);
try
{
const Distribution candidate(factory_.build(NumericalPointCollection(1, parameters)));
for (UnsignedInteger i = 0; i < dataX_.getSize(); ++i)
norm += std::pow(candidate.computeCDF(dataX_[i][0]) - dataY_[i][0], 2);
return NumericalPoint(1, norm);
}
catch(...)
{
return NumericalPoint(1, SpecFunc::MaxNumericalScalar);
}
}
/** factory accessor */
void setDistributionFactory(const DistributionFactory & factory)
{
factory_ = factory;
}
private:
NumericalSample dataX_;
NumericalSample dataY_;
DistributionFactory factory_;
};
protected:
/** Compute the numerical range of the distribution given the parameters values */
void computeRange();
/** Default constructor for save/load mechanism */
RandomMixture() {};
friend class Factory<RandomMixture>;
/** Get the mean of a randomMixture */
void computeMean() const;
/** Get the covariance of a randomMixture */
void computeCovariance() const;
private:
/** Compute the left-hand sum in Poisson's summation formula for the equivalent normal */
NumericalScalar computeEquivalentNormalPDFSum(const NumericalScalar x) const;
NumericalScalar computeEquivalentNormalCDFSum(const NumericalScalar s, const NumericalScalar t) const;
friend struct EquivalentNormalPDFSumPolicy;
NumericalScalar computeEquivalentNormalPDFSum(const NumericalPoint & y, const NumericalPoint & gridStep,
UnsignedInteger imax, UnsignedInteger & levelMax) const;
public:
/** Get the standard deviation of the distribution */
NumericalPoint getStandardDeviation() const;
/** Get the skewness of the distribution */
NumericalPoint getSkewness() const;
/** Get the kurtosis of the distribution */
NumericalPoint getKurtosis() const;
private:
/** Compute the position indicator */
void computePositionIndicator() const;
/** Compute the dispersion indicator */
void computeDispersionIndicator() const;
/** Compute the reference bandwidth. It is defined as the maximum bandwidth
that allow a precise computation of the PDF over the range
[positionIndicator_ +/- beta * dispersionIndicator_] */
void computeReferenceBandwidth();
/** Compute the equivalent normal distribution, i.e. with the same mean and
the same standard deviation */
void computeEquivalentNormal();
/** The collection of distribution of the randomMixture */
DistributionPersistentCollection distributionCollection_;
/** The constant term of the mixture */
NumericalPoint constant_;
/** The Weight matrix */
Matrix weights_;
/** inverse weight matrix if defined */
Matrix inverseWeights_;
/** Determinant of inverse weights */
NumericalScalar detWeightsInverse_;
/** FFT algorithm */
FFT fftAlgorithm_;
/** The RandomMixture is analytic if size of collection = dimension */
Bool isAnalytical_;
/** Position indicator */
mutable NumericalScalar positionIndicator_;
mutable Bool isAlreadyComputedPositionIndicator_;
/** Dispersion indicator */
mutable NumericalScalar dispersionIndicator_;
mutable Bool isAlreadyComputedDispersionIndicator_;
/** Minimum number of blocks to consider for PDF and CDF computation */
UnsignedInteger blockMin_;
/** Maximum number of blocks to consider for PDF and CDF computation */
UnsignedInteger blockMax_;
/** Reference bandwidth */
NumericalPoint referenceBandwidth_;
/** Reference bandwidth factor */
NumericalScalar referenceBandwidthFactor_;
/** Maximum size of the cache for the CharacteristicFunction values */
UnsignedInteger maxSize_;
/** Index of the top of the cache */
mutable UnsignedInteger storedSize_;
/** Cache for the characteristic function values */
mutable NumericalComplexPersistentCollection characteristicValuesCache_;
/** A priori range of PDF and CDF argument expressed in dispersionIndicator units */
NumericalScalar alpha_;
/** Distance from the boundary of the a priori range at which the PDF is negligible */
NumericalScalar beta_;
/** Requested precision for PDF computation */
mutable NumericalScalar pdfPrecision_;
/** Requested precision for CDF computation */
mutable NumericalScalar cdfPrecision_;
/** Normal distribution with the same mean and standard deviation than the RandomMixture */
Normal equivalentNormal_;
/** Helper object to retrieve points on a regular grid */
SphereUniformNorm gridMesher_;
}; /* class RandomMixture */
END_NAMESPACE_OPENTURNS
#endif /* OPENTURNS_RANDOMMIXTURE_HXX */
|