KrawtchoukFactory

(Source code, png)

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

Krawtchouk specific orthonormal univariate polynomial family.

For the Binomial distribution.

Parameters:
nint, n > 0

Number of experiment parameter of the Binomial distribution.

pfloat, 0 < p < 1

Success probability parameter of the Binomial distribution.

Notes

Any sequence of orthogonal polynomials has a recurrence formula relating any three consecutive polynomials as follows:

P_{i + 1} = (a_i x + b_i) P_i + c_i P_{i - 1}, \quad 1 < i < n

The recurrence coefficients for the Krawtchouk polynomials come analytically and read:

\begin{array}{rcl}
    a_i & = & \displaystyle - \frac{1}
                                   {\sqrt{(i + 1) (n - i) p (1 - p)}} \\
    b_i & = & \displaystyle \frac{p (n - i) + i (1 - p)}
                                 {\sqrt{(i + 1) (n - i) p (1 - p)}} \\
    c_i & = & \displaystyle - \sqrt{(1 - \frac{1}{i + 1})
                                    (1 + \frac{1}{n - i})}
\end{array}, \quad 1 < i

where n and p are the parameters of the Binomial distribution.

Warning

The Krawtchouk polynomials are only defined up to a degree m equal to n - 1. Indeed, for i = n, some factors in the denominators of the recurrence coefficients would be equal to zero.

Examples

>>> import openturns as ot
>>> polynomial_factory = ot.KrawtchoukFactory(3, 0.5)
>>> for i in range(3):
...     print(polynomial_factory.build(i))
1
-1.73205 + 1.1547 * X
1.73205 - 3.4641 * X + 1.1547 * X^2

Methods

build(degree)

Build the k-th order orthogonal univariate polynomial.

buildCoefficients(degree)

Build the k-th order orthogonal univariate polynomial coefficients.

buildRecurrenceCoefficientsCollection(degree)

Build the recurrence coefficients.

getClassName()

Accessor to the object's name.

getMeasure()

Accessor to the associated probability measure.

getN()

Accessor to the n parameter.

getName()

Accessor to the object's name.

getNodesAndWeights(n)

Build the k-th order quadrature scheme.

getP()

Accessor to the p parameter.

getRecurrenceCoefficients(n)

Accessor to the recurrence coefficients of the k-th order.

getRoots(n)

Accessor to the recurrence coefficients of the k-th order.

hasName()

Test if the object is named.

setName(name)

Accessor to the object's name.

__init__(*args)
build(degree)

Build the k-th order orthogonal univariate polynomial.

Parameters:
kint, 0 \leq k

Polynomial order.

Returns:
polynomialOrthogonalUniVariatePolynomial

Requested orthogonal univariate polynomial.

Examples

>>> import openturns as ot
>>> polynomial_factory = ot.HermiteFactory()
>>> print(polynomial_factory.build(2))
-0.707107 + 0.707107 * X^2
buildCoefficients(degree)

Build the k-th order orthogonal univariate polynomial coefficients.

Parameters:
kint, 0 \leq k

Polynomial order.

Returns:
coefficientsPoint

Coefficients of the requested orthogonal univariate polynomial.

Examples

>>> import openturns as ot
>>> polynomial_factory = ot.HermiteFactory()
>>> print(polynomial_factory.buildCoefficients(2))
[-0.707107,0,0.707107]
buildRecurrenceCoefficientsCollection(degree)

Build the recurrence coefficients.

Build the recurrence coefficients of the orthogonal univariate polynomial family up to the k-th order.

Parameters:
kint, 0 \leq k

Polynomial order.

Returns:
recurrence_coefficientslist of Point

All the tecurrence coefficients up to the requested order.

Examples

>>> import openturns as ot
>>> polynomial_factory = ot.HermiteFactory()
>>> print(polynomial_factory.buildRecurrenceCoefficientsCollection(2))
0 : [  1         0         0        ]
1 : [  0.707107  0        -0.707107 ]
getClassName()

Accessor to the object’s name.

Returns:
class_namestr

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

getMeasure()

Accessor to the associated probability measure.

Returns:
measureDistribution

The associated probability measure (according to which the polynomials are orthogonal).

Notes

Two polynomials P and Q are orthogonal with respect to the probability measure w(x) \di{x} if and only if their dot product:

\langle P, Q \rangle = \int_{\alpha}^{\beta} P(x) Q(x) w(x)\di{x}
                     = 0

where \alpha \in \Rset \cup \{-\infty\} and \beta \in \Rset \cup \{+\infty\}.

Examples

>>> import openturns as ot
>>> polynomial_factory = ot.HermiteFactory()
>>> print(polynomial_factory.getMeasure())
Normal(mu = 0, sigma = 1)
getN()

Accessor to the n parameter.

Returns:
nint

Number of experiments parameter of the Binomial distribution.

getName()

Accessor to the object’s name.

Returns:
namestr

The name of the object.

getNodesAndWeights(n)

Build the k-th order quadrature scheme.

Associated with the orthogonal univariate polynomials family.

Parameters:
kint, 0 < k

Polynomial order.

Returns:
nodesPoint

The nodes of the k-th order quadrature scheme.

weightsPoint

The weights of the k-th order quadrature scheme.

Examples

>>> import openturns as ot
>>> polynomial_factory = ot.HermiteFactory()
>>> nodes, weights = polynomial_factory.getNodesAndWeights(3)
>>> print(nodes)
[-1.73205,...,1.73205]
>>> print(weights)
[0.166667,0.666667,0.166667]
getP()

Accessor to the p parameter.

Returns:
pfloat

Success probability parameter of the Binomial distribution.

getRecurrenceCoefficients(n)

Accessor to the recurrence coefficients of the k-th order.

Of the orthogonal univariate polynomial.

Parameters:
kint, 0 \leq k

Polynomial order.

Returns:
recurrence_coefficientsPoint

The recurrence coefficients of the k-th order orthogonal univariate polynomial.

Notes

Any sequence of orthogonal polynomials has a recurrence formula relating any three consecutive polynomials as follows:

P_{-1}=0, P_0=1, P_{n + 1} = (a_n x + b_n) P_n + c_n P_{n - 1}, \quad n > 1

Examples

>>> import openturns as ot
>>> polynomial_factory = ot.HermiteFactory()
>>> print(polynomial_factory.getRecurrenceCoefficients(3))
[0.5,0,-0.866025]
getRoots(n)

Accessor to the recurrence coefficients of the k-th order.

Of the orthogonal univariate polynomial.

Parameters:
kint, k > 0

Polynomial order.

Returns:
rootsPoint

The roots of the k-th order orthogonal univariate polynomial.

Examples

>>> import openturns as ot
>>> polynomial_factory = ot.HermiteFactory()
>>> print(polynomial_factory.getRoots(3))
[-1.73205,...,1.73205]
hasName()

Test if the object is named.

Returns:
hasNamebool

True if the name is not empty.

setName(name)

Accessor to the object’s name.

Parameters:
namestr

The name of the object.

Examples using the class

Advanced polynomial chaos construction

Advanced polynomial chaos construction