/usr/include/openturns/swig/Distribution.i 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 | // SWIG file Distribution.i
// @author schueller
// @date 2012-01-02 11:44:01 +0100 (Mon, 02 Jan 2012)
%{
#include "Distribution.hxx"
#include "PythonDistributionImplementation.hxx"
%}
%include Distribution_doc.i
%pythoncode %{
from openturns.typ import Interval
class PythonDistribution(object):
"""
Allow to override Distribution from Python.
Parameters
----------
dim : positive int
the distribution dimension
"""
def __init__(self, dim=0):
self.__dim = dim
def __str__(self):
return 'PythonDistribution -> #%d' % self.__dim
def __repr__(self):
return self.__str__()
def getDimension(self):
return self.__dim
def computeCDF(self, X):
raise RuntimeError('You must define a method computePDF(x) -> cdf, where cdf is a float')
def computePDFGradient(self, X):
raise RuntimeError('You must define a method computePDFGradient(x) -> dpdf, where dpdf is a sequence')
def computeCDFGradient(self, X):
raise RuntimeError('You must define a method computeCDFGradient(x) -> dcdf, where dcdf is a sequence')
def getRoughness(self):
raise RuntimeError('You must define a method getRoughness() -> r, where r is a float')
class SciPyDistribution(PythonDistribution):
"""
Allow to override Distribution from a scipy distribution.
Parameters
----------
dist : a scipy.stats distribution
the distribution to wrap
"""
def __init__(self, dist):
super(SciPyDistribution, self).__init__(1)
if dist.__class__.__name__ != 'rv_frozen':
raise TypeError('Argument is not a scipy distribution')
self._dist = dist
# compute range
lb = dist.ppf(0.)
ub = dist.ppf(1.)
flb = lb != float('-inf')
fub = ub != float('+inf')
self.__range = Interval([lb], [ub])
self.__range.setFiniteLowerBound([int(flb)])
self.__range.setFiniteUpperBound([int(fub)])
def getRange(self):
return self.__range
def getRealization(self):
rvs = self._dist.rvs()
return [rvs]
def getSample(self, size):
rvs = self._dist.rvs(size)
return rvs.reshape(size, 1)
def computePDF(self, X):
pdf = self._dist.pdf(X[0])
return pdf
def computeCDF(self, X):
cdf = self._dist.cdf(X[0])
return cdf
def getMean(self):
mean = float(self._dist.stats('m'))
return [mean]
def getStandardDeviation(self):
var = float(self._dist.stats('v'))
std = var ** 0.5
return [std]
def getSkewness(self):
skewness = float(self._dist.stats('s'))
return [skewness]
def getKurtosis(self):
kurtosis = float(self._dist.stats('k'))
return [kurtosis]
def getMoment(self, n):
moment = self._dist.moment(n)
return [moment]
%}
%include UncertaintyModelCopulaCollection.i
OTTypedInterfaceObjectHelper(Distribution)
OTTypedCollectionInterfaceObjectHelper(Distribution)
%include Distribution.hxx
//%copyctor Distribution;
namespace OT {
%extend Distribution {
Distribution(const Distribution & other)
{
return new OT::Distribution(other);
}
Distribution(PyObject * pyObj)
{
return new OT::Distribution( new OT::PythonDistributionImplementation( pyObj ) );
}
} // class Distribution
} // namespace OT
|