TruncatedNormalFactory

(Source code, png)

../../_images/openturns-TruncatedNormalFactory-1.png
class TruncatedNormalFactory(*args)

Truncated Normal factory.

Notes

Several estimators to build a TruncatedNormal distribution from a scalar sample are available. The default strategy is using the maximum likelihood estimators with scaling.

Maximum likelihood estimator:

The parameters are estimated by numerical maximum likelihood estimation with scaling. The starting point of the optimization algorithm is based on the moment based estimator.

Let n be the sample sample size. Let x_{min} be the sample minimum and x_{max} be the sample maximum.

We compute the scaling parameters \alpha and \beta from the equations:

\begin{eqnarray*}
  \displaystyle \alpha = \frac{2}{x_{min} - x_{max}}, \\
  \displaystyle \beta = \frac{1}{2} (x_{min} + x_{max}).
\end{eqnarray*}

Then the sample \{x_i\}_{i=1,...,n} is scaled into \{u_i\}_{i=1,...,n} from the equation:

\begin{eqnarray*}
  \displaystyle u_i = \alpha (x_i - \beta)
\end{eqnarray*}

for i=1,...,n. Hence, the scaled sample is so that u_i\in[-1,1] for i=1,...,n.

The starting point of the likelihood maximization algorithm is based on the scaled sample. Let

\begin{eqnarray*}
  \displaystyle \mu_0^u = \bar{u}, \\
  \displaystyle \sigma_0^u = \sigma_{u, n}
\end{eqnarray*}

where \bar{u} is the sample mean of the scaled sample and \sigma_{u, n} is the sample standard deviation of the scaled sample.

Then the likelihood maximization optimization algorithm is used to fit the scaled truncated normal distribution. The TruncatedNormalFactory-SigmaLowerBound key in the ResourceMap is used as a lower bound for the scaled standard deviation.

Let \epsilon be computed from the sample size:

\begin{eqnarray*}
  \displaystyle \epsilon = 1 + \frac{1}{n}.
\end{eqnarray*}

The lower and upper bounds of the scaled truncated normal distribution are set to -\epsilon and \epsilon and are not optimized. This leads to a maximum likelihood optimization problem in 2 dimensions only, where the solution is the optimum scaled mean \mu_u^\star and the optimum scaled standard deviation \sigma_u^\star.

Finally, the parameters of the truncated normal distribution are computed from the parameters of the scaled truncated normal distribution. The inverse scaling equation is x = \beta + \frac{u}{\beta}, which leads to:

\begin{eqnarray*}
  \displaystyle \mu = \beta + \frac{\mu_u^\star}{\alpha}, \\
  \displaystyle \sigma = \frac{\sigma_u^\star}{\alpha}, \\
  \displaystyle a = \beta - \frac{\epsilon}{\alpha}, \\
  \displaystyle b = \beta + \frac{\epsilon}{\alpha}.
\end{eqnarray*}

Moment based estimator:

Let x_{min} be the sample minimum and x_{max} be the sample maximum. Let \delta = x_{max} - x_{min} be the sample range.

The distribution bounds are computed from the equations:

\begin{eqnarray*}
  \displaystyle\Hat{a}_n = x_{min} - \frac{\delta}{n + 2}\\
  \displaystyle\Hat{b}_n = x_{max} + \frac{\delta}{n + 2}
\end{eqnarray*}

Then the \mu and \sigma parameters are estimated from the methods of moments.

Examples

In the following example, the parameters of a TruncatedNormal are estimated from a sample.

>>> import openturns as ot
>>> ot.RandomGenerator.SetSeed(0)
>>> size = 10000
>>> distribution = ot.TruncatedNormal(2.0, 3.0, -1.0, 4.0)
>>> sample = distribution.getSample(size)
>>> factory = ot.TruncatedNormalFactory()
>>> estimated = factory.build(sample)
>>> estimated = factory.buildMethodOfMoments(sample)
>>> estimated = factory.buildMethodOfLikelihoodMaximization(sample)

Methods

build(*args)

Build the distribution.

buildAsTruncatedNormal(*args)

Estimate the distribution as native distribution.

buildEstimator(*args)

Build the distribution and the parameter distribution.

buildMethodOfLikelihoodMaximization(sample)

Method of likelihood maximization.

buildMethodOfMoments(sample)

Method of moments estimator.

getBootstrapSize()

Accessor to the bootstrap size.

getClassName()

Accessor to the object's name.

getName()

Accessor to the object's name.

hasName()

Test if the object is named.

setBootstrapSize(bootstrapSize)

Accessor to the bootstrap size.

setName(name)

Accessor to the object's name.

__init__(*args)
build(*args)

Build the distribution.

Available usages:

build()

build(sample)

build(param)

Parameters:
sample2-d sequence of float

Data.

paramsequence of float

The parameters of the distribution.

Returns:
distDistribution

The estimated distribution.

In the first usage, the default native distribution is built.

buildAsTruncatedNormal(*args)

Estimate the distribution as native distribution.

Available usages:

buildAsTruncatedNormal()

buildAsTruncatedNormal(sample)

buildAsTruncatedNormal(param)

Parameters:
sample2-d sequence of float

Data.

paramsequence of float

The parameters of the TruncatedNormal.

Returns:
distTruncatedNormal

The estimated distribution as a TruncatedNormal.

In the first usage, the default TruncatedNormal distribution is built.

buildEstimator(*args)

Build the distribution and the parameter distribution.

Parameters:
sample2-d sequence of float

Data.

parametersDistributionParameters

Optional, the parametrization.

Returns:
resDistDistributionFactoryResult

The results.

Notes

According to the way the native parameters of the distribution are estimated, the parameters distribution differs:

  • Moments method: the asymptotic parameters distribution is normal and estimated by Bootstrap on the initial data;

  • Maximum likelihood method with a regular model: the asymptotic parameters distribution is normal and its covariance matrix is the inverse Fisher information matrix;

  • Other methods: the asymptotic parameters distribution is estimated by Bootstrap on the initial data and kernel fitting (see KernelSmoothing).

If another set of parameters is specified, the native parameters distribution is first estimated and the new distribution is determined from it:

  • if the native parameters distribution is normal and the transformation regular at the estimated parameters values: the asymptotic parameters distribution is normal and its covariance matrix determined from the inverse Fisher information matrix of the native parameters and the transformation;

  • in the other cases, the asymptotic parameters distribution is estimated by Bootstrap on the initial data and kernel fitting.

buildMethodOfLikelihoodMaximization(sample)

Method of likelihood maximization.

Parameters:
sample2-d sequence of float

Data.

Returns:
distributionTruncatedNormal

The estimated distribution

buildMethodOfMoments(sample)

Method of moments estimator.

Parameters:
sample2-d sequence of float

Data.

Returns:
distributionTruncatedNormal

The estimated distribution.

getBootstrapSize()

Accessor to the bootstrap size.

Returns:
sizeint

Size of the bootstrap.

getClassName()

Accessor to the object’s name.

Returns:
class_namestr

The object class name (object.__class__.__name__).

getName()

Accessor to the object’s name.

Returns:
namestr

The name of the object.

hasName()

Test if the object is named.

Returns:
hasNamebool

True if the name is not empty.

setBootstrapSize(bootstrapSize)

Accessor to the bootstrap size.

Parameters:
sizeint

The size of the bootstrap.

setName(name)

Accessor to the object’s name.

Parameters:
namestr

The name of the object.

Examples using the class

Fitting a distribution with customized maximum likelihood

Fitting a distribution with customized maximum likelihood