ParetoFactory¶
(Source code, svg)
- class ParetoFactory(*args)¶
Pareto factory.
Methods
build(*args)Build the distribution.
buildAsPareto(*args)Estimate the distribution as native distribution.
buildEstimator(*args)Build the distribution and the parameter distribution.
buildMethodOfLeastSquares(*args)Method of least-squares.
Method of likelihood maximization.
buildMethodOfMoments(sample)Method of moments estimator.
Accessor to the bootstrap size.
Accessor to the object's name.
Accessor to the known parameters indices.
Accessor to the known parameters values.
getName()Accessor to the object's name.
hasName()Test if the object is named.
setBootstrapSize(bootstrapSize)Accessor to the bootstrap size.
setKnownParameter(*args)Accessor to the known parameters.
setName(name)Accessor to the object's name.
See also
Notes
Several estimators to build a Pareto distribution from a scalar sample are proposed. The default strategy is to use the least squares estimator. We make the assumption that
is an i.i.d. sample from the Pareto random variable where
is the sample size.
Moments based estimator:
Let us define the sample statistics required for the estimation. The empirical mean
is calculated as:
The associated empirical standard deviation
is:
Finally, the distribution of the sample is characterized by its empirical skewness, denoted as
.
The estimator
of
is defined as follows. The parameter
is solution of the equation:
The previous nonlinear equation is solved using a numerical method. If
, then an exception is raised. If
, then we compute
as follows:
Least squares estimator:
Before introducing the equations, let us present the overall methodology. When
is known, then we solve a linear least squares problem to estimate
and
.
When
is unknown, then two problems are involved:
in the outer loop, a non-linear least squares problem is solved to estimate
;
in the inner loop, for a given value of
, a linear least squares problem is solved to estimate
and
.
Let us now introduce the methods in more details. Let
be the empirical survival function. If
is known, then we solve the following linear least-squares problem:
(1)¶
To do this, let
be the vector equal to the value of the empirical survival function at each observation:
for
. Moreover, let
be the vector of logarithm of the shifted observations:
for
. Then the linear least squares problem is:
See
LinearLeastSquaresfor more details.Once the vector
is computed, we compute
and
from the equations:
When
is unknown, it is estimated using non-linear least squares. More precisely, the parameter
is the solution of:
where
are computed from linear least-squares at each optimization evaluation.
Maximum likelihood based estimator:
The log-likelihood of the sample is:
The maximum likelihood based estimator
of
maximizes the log-likelihood:
In the current implementation, all parameters are estimated simultaneously.
However, another method could be used, which can be described as follows. For a given value of
, the log-likelihood of the sample is defined by:
We compute
which maximizes
:
where
is the smallest observation in the sample:
We get:
Then the parameter
is computed by maximizing the log-likelihood of the sample
:
The starting point of the optimization algorithm is:
Examples
In the first example, we estimate all the parameters, that is,
,
and
.
>>> import openturns as ot >>> real_distribution = ot.Pareto(2.5, 1.0, 0.0) >>> sample = real_distribution.getSample(1000) >>> factory = ot.ParetoFactory() >>> estimated_distribution_full = factory.build(sample)
In the second example, we assume that the
parameter is known and estimate
and
. The user sets the value of
(index 2 in the order
,
and
).
>>> known_gamma = 0.0 >>> factory.setKnownParameter([2], [known_gamma]) >>> estimated_distribution_fixed = factory.build(sample)
- __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:
- dist
Distribution The estimated distribution.
In the first usage, the default native distribution is built.
- dist
- buildAsPareto(*args)¶
Estimate the distribution as native distribution.
Available usages:
buildAsPareto()
buildAsPareto(sample)
buildAsPareto(param)
- buildEstimator(*args)¶
Build the distribution and the parameter distribution.
- Parameters:
- sample2-d sequence of float
Data.
- parameters
DistributionParameters Optional, the parametrization.
- Returns:
- resDist
DistributionFactoryResult The results.
- resDist
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.
- buildMethodOfLeastSquares(*args)¶
Method of least-squares.
- Parameters:
- sample2-d sequence of float
Data.
- gammafloat, optional
Location parameter. If provided, the estimation of
and
is performed via linear least squares with
fixed. If not specified,
is first estimated using a non-linear least squares routine, followed by a linear least squares estimation for the remaining parameters.
- Returns:
- distribution
Pareto The estimated distribution.
- distribution
Examples
In the following example, the parameters of a
Paretoare estimated from a sample. We create a simulated sample from a Pareto distribution with parameters beta=2.5, alpha=1.0 and gamma=0.0.>>> import openturns as ot >>> real_distribution = ot.Pareto(2.5, 1.0, 0.0) >>> sample = real_distribution.getSample(1000) >>> factory = ot.ParetoFactory()
Example 1: When gamma is known. In this case, we estimate the parameters beta and alpha using linear least squares.
>>> known_gamma = 0.0 >>> estimated_distribution_fixed = factory.buildMethodOfLeastSquares(sample, known_gamma) >>> print(estimated_distribution_fixed.getParameter()) [2.53...,1.03...,0]
Example 2: When gamma is unknown. In this case, we perform a full estimation by non-linear least squares (for gamma) combined with linear least squares (for beta and alpha).
>>> estimated_distribution_full = factory.buildMethodOfLeastSquares(sample) >>> print(estimated_distribution_full.getParameter()) [2.61...,1.05...,-0.10...]
- buildMethodOfLikelihoodMaximization(sample)¶
Method of likelihood maximization.
Refer to
MaximumLikelihoodFactory.- Parameters:
- sample2-d sequence of float
Data.
- Returns:
- distribution
Pareto The estimated distribution
- distribution
Notes
When this method is used, all parameters are estimated simultaneously.
- buildMethodOfMoments(sample)¶
Method of moments estimator.
- Parameters:
- sample2-d sequence of float
Data.
- Returns:
- distribution
Pareto The estimated distribution
- 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__).
- getKnownParameterIndices()¶
Accessor to the known parameters indices.
- Returns:
- indices
Indices Indices of the known parameters.
- indices
- getKnownParameterValues()¶
Accessor to the known parameters values.
- Returns:
- values
Point Values of known parameters.
- values
- 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.
- setKnownParameter(*args)¶
Accessor to the known parameters.
- Parameters:
- positionssequence of int
Indices of known parameters.
- valuessequence of float
Values of known parameters.
Examples
When a subset of the parameter vector is known, the other parameters only have to be estimated from data.
In the following example, we consider a sample and want to fit a
Betadistribution. We assume that theand
parameters are known beforehand. In this case, we set the third parameter (at index 2) to -1 and the fourth parameter (at index 3) to 1.
>>> import openturns as ot >>> ot.RandomGenerator.SetSeed(0) >>> distribution = ot.Beta(2.3, 2.2, -1.0, 1.0) >>> sample = distribution.getSample(10) >>> factory = ot.BetaFactory() >>> # set (a,b) out of (r, t, a, b) >>> factory.setKnownParameter([2, 3], [-1.0, 1.0]) >>> inf_distribution = factory.build(sample)
- setName(name)¶
Accessor to the object’s name.
- Parameters:
- namestr
The name of the object.
OpenTURNS