xopto.pf.distribution module¶
- class Fractal(alpha: float, range: Tuple[float, float] = (1e-08, 1e-05))[source]¶
Bases:
object
Fractal distribution with one parameter alpha:
p(d) = A*(1/d)**alpha
The value of parameter A is computed so as to normalize the integral of the density function on the specified range to 1:
A = (range[0])**(alpha + 1)/(alpha*(1 - (range[0]/range[1])**(alpha + 1)))
- Parameters
alpha (float) – Parameter alpha of the fractal distribution.
range (Tuple[float, float]) – The nonzero distribution range as a tuple (start, stop), e.g. use (10e-9, 10e-6) for fractal distribution of particles limited to the finite range from 10 nm to 10 um.
Examples
Creates object representing fractal distribution with alpha=2.4.
>>> fd = Fractal(2.4) >>> from matplotlib import pyplot as pp >>> x = np.linspace(10e-9, 10e-6, 1000) >>> pp.semilogy(x, fd(x)) >>>
- property alpha: float¶
Parameter alpha of the fractal distribution (1/d)**alpha.
- property parameters: dict¶
All fractal distribution parameters as a dict object.
- property range: Tuple[float, float]¶
Numerical integration range.
- class Mixture(distributions: Tuple[Callable[[float], float]], weights: Tuple[float])[source]¶
Bases:
object
Create a mixture distribution instance. Distribution objects must be callable as obj(x) and return the value of distribution at x.
- Parameters
distributions (Tuple[Callable[[float], float]]) – Individual distributions of the mixture.
weights (Tuple[float] or np.ndarray) – Weights of the individual distributions. The sum of weights should equal 1.
Examples
Creates object representing normal distribution with mean 1 and standard deviation 0.1.
>>> nd = Normal(1.0, 0.1, clip=5) >>> from matplotlib import pyplot as pp >>> x = np.linspace(0.5, 1.5, 1000) >>> pp.plot(x, nd(x)) >>>
- distribution(index: int) → Callable[[float], float][source]¶
Returns distribution at the specified index or slice.
- property range: Tuple[float, float]¶
Mixture range.
- raw_moment(n: int) → float[source]¶
- Computes the n-th raw moment of the distribution p(x) as:
int(p(x)*x**n) on the interval [range[0], range[1]].
- Parameters
n (int) – The requested raw moment.
- Returns
gn – The n-th raw moment of the distribution defined on the interval on the interval [range[0], range[1]].
- Return type
float
- class Normal(mean: float, sigma: float, clip: float = 5)[source]¶
Bases:
object
Create a Normal distribution instance. The object is callable as obj(x) and returns the value of distribution at x.
- Parameters
mean (float) – Normal distribution mean.
sigma (float) – Normal distribution standard deviation.
clip (float) –
- The range of Normal distribution is clipped to:
[mean - sigma*clip, mean + sigma*clip]
Examples
Creates object representing normal distribution with mean 1 and standard deviation 0.1.
>>> nd = Normal(1.0, 0.1, clip=5) >>> from matplotlib import pyplot as pp >>> x = np.linspace(0.5, 1.5, 1000) >>> pp.plot(x, nd(x)) >>>
- property mean: float¶
Mean value of the Normal distribution.
- property parameters: dict¶
All Normal distribution parameters as a dict object.
- property range: Tuple[float, float]¶
Distribution range.
- raw_moment(n: int) → float[source]¶
- Computes the n-th raw moment of the distribution p(x) as:
int(p(x)*x**n) on the interval [range[0], range[1]].
- Parameters
n (int) – The requested raw moment.
- Returns
n-th raw moment of the distribution defined on the interval
on the interval [range[0], range[1]].
- property sigma: float¶
Standard deviation of the Normal distribution.
- class Uniform(lower: float, upper: float)[source]¶
Bases:
object
Create a uniform distribution instance. The object is callable as obj(x) and returns the value of distribution at x.
- Parameters
lower (float) – Lower bound of the uniform distribution.
upper (float) – Upper bound of the uniform distribution.
Examples
Creates an object representing a uniform distribution on [0, 2].
>>> ud = Uniform(0.0, 2.0) >>> from matplotlib import pyplot as pp >>> x = np.linspace(-1.0, 3.0, 1000) >>> pp.plot(x, ud(x)) >>>
- property lower: float¶
Lower bound of the uniform distribution range.
- property parameters: dict¶
All Uniform distribution parameters as a dict object.
- property range: Tuple[float, float]¶
The range of uniform distribution as (lower, upper).
- raw_moment(n: int) → float[source]¶
- Computes the n-th raw moment of the distribution p(x) as:
int(p(x)*x**n) on the interval [range[0], range[1]].
- Parameters
n (int) – The requested raw moment.
- Returns
n-th raw moment of the distribution defined on the interval
on the interval [range[0], range[1]].
- property upper: float¶
Upper bound of the uniform distribution range.