Dist_cubicSpline¶
-
class
stats.
Dist_cubicSpline
(x, y, N_cs=1000)¶ Bases:
stats.Dist_qilum
Distribution for (x,y): cubic splaine approximation for both cumulative ans values
- Parameters
x (array like) –
y (array like) –
N_cs (int) – number of point to set up the cubic spline
Examples
>>> import qilum.stats as qs >>> # test function: truncated gaussian >>> def f_f(xs): ... return 3.*np.exp(-np.square(xs)/10.) >>> >>> # initialize class >>> x = np.linspace(-12, 12, 51) >>> y = f_f(x) >>> dist = qs.Dist_cubicSpline(x, y, N_cs=1000)
Methods Summary
F_tot
()Cumulative of the function f() on the whole valid range x
cdf
(x)Cumulative distribution function.
f
(x)Cubic spline of (x,y) Approximation: should be 1/F’(F_inverse(x)), but very small error
name
()Name of the class
pdf
(x)Probability density function.
ppf
(q)Percent point function (inverse of cdf) at q
rvs
(size)random numbers in ndarray of lenght size
rvs_xy
(size)random numbers rans in ndarray of lenght size and function(rans)
Methods Documentation
-
F_tot
()¶ Cumulative of the function f() on the whole valid range x
- Returns
- Return type
int
Examples
>>> x = np.linspace(-12, 12, 51) >>> dist = qs.Dist_cubicSpline(x, y= 3.*np.exp(-np.square(x)/10.), N_cs=1000) >>> print(dist.F_tot()) 16.81497238763992
-
cdf
(x)¶ Cumulative distribution function.
- Parameters
x (array_like of type(values)) –
- Returns
Cumulative distribution function evaluated at x
- Return type
ndarray
Examples
>>> x = np.linspace(-12, 12, 51) >>> dist = qs.Dist_cubicSpline(x, y= 3.*np.exp(-np.square(x)/10.), N_cs=1000) >>> x = [-3,1,2,3] >>> print('cdf(x)=',dist.cdf(x)) cdf(x)= [0.09161441 0.67650553 0.81730869 0.91187099]
-
f
(x)¶ Cubic spline of (x,y) Approximation: should be 1/F’(F_inverse(x)), but very small error
- Parameters
x (array_like of type(values)) –
- Returns
f(x)
- Return type
ndarray
Examples
>>> x = np.linspace(-12, 12, 51) >>> dist = qs.Dist_cubicSpline(x, y= 3.*np.exp(-np.square(x)/10.), N_cs=1000) >>> x = [-3,1,2,3] >>> print('f(x)=',dist.f(x)) f(x)= [1.21972729 2.71451285 2.01096922 1.21972729]
-
name
()¶ Name of the class
- Returns
‘Dist_reject’
- Return type
string
Examples
>>> x = np.linspace(-12, 12, 51) >>> dist = qs.Dist_cubicSpline(x, y= 3.*np.exp(-np.square(x)/10.), N_cs=1000) >>> dist.name() 'Dist_cubicSpline'
-
pdf
(x)¶ Probability density function. Cubic spline of (x,y)
- Parameters
x (array_like of type(values)) –
- Returns
f(x)/F_tot()
- Return type
ndarray
Examples
>>> x = np.linspace(-12, 12, 51) >>> dist = qs.Dist_cubicSpline(x, y= 3.*np.exp(-np.square(x)/10.), N_cs=1000) >>> x = [-3,1,2,3] >>> print('pdf(x)=',dist.pdf(x)) pdf(x)= [0.07253817 0.16143427 0.11959396 0.07253817]
-
ppf
(q)¶ Percent point function (inverse of cdf) at q
- Parameters
q (array_like of double) – lower tail probability
- Returns
quantile corresponding to the lower tail probability q
- Return type
ndarray
Examples
>>> x = np.linspace(-12, 12, 51) >>> dist = qs.Dist_cubicSpline(x, y= 3.*np.exp(-np.square(x)/10.), N_cs=1000) >>> q = [0, 0.3,0.5,0.7,1] >>> print('ppf(q)=',dist.ppf(q)) ppf(q)= [-12. -1.19663998 -0.02402402 1.14859193 11.97597598]
-
rvs
(size)¶ random numbers in ndarray of lenght size
- Parameters
size (int) – number of random number
- Returns
random numbers
- Return type
ndarray
Examples
>>> x = np.linspace(-12, 12, 51) >>> dist = qs.Dist_cubicSpline(x, y= 3.*np.exp(-np.square(x)/10.), N_cs=1000) >>> print('rans=',dist.rvs(4)) rans= [ 3.1874446 -0.24592411 -2.9817858 -1.65194734]
-
rvs_xy
(size)¶ random numbers rans in ndarray of lenght size and function(rans)
- Parameters
size (int) – number of random number
- Returns
ndarray – random numbers
ndarray – f(random numbers)
Examples
>>> x = np.linspace(-12, 12, 51) >>> dist = qs.Dist_cubicSpline(x, y= 3.*np.exp(-np.square(x)/10.), N_cs=1000) >>> print('rans=',dist.rvs_xy(2)) rans= (array([-0.17748735, 1.35683644]), array([2.9905203 , 2.49554626]))