pyphase package¶
Submodules¶
pyphase.phase module¶
Module pyphase.phase.
This module allows you to work with Phase-Type distributions.
The CDF for PH variable is given by
where \(\boldsymbol{\alpha}\) is a probability vector and the matrix \(\boldsymbol{A}\) has the transition rates between the phases.
To build a PH variable you need the vectoe alpha
and matrix A
>>> from pyphase import *
>>> alpha = [0.1 , 0.9]
>>> A = [[-2.0 , 1.0], [1.5, -3.0]]
>>> v = phase(alpha, A)
>>> print(v)
PhaseType:
alpha = [[0.1 0.9]]
A = [[-2. 1. ]
[ 1.5 -3. ]]
After you have the variable you can do all operations that are typical with random variables in scipy.stats:
>>> print(f"The mean is {v.mean():.3f}")
The mean is 0.789
>>> print(f"v.cdf(1.0)={v.cdf(1.0):.3f}")
v.cdf(1.0)=0.721
-
class
pyphase.phase.
PhaseType
(alpha, A, dist, *args, **kwds)[source]¶ Bases:
scipy.stats._distn_infrastructure.rv_frozen
Represent a Phase-Type distribution.
Users should not call it directly but rather call
phase(alpha, A)
-
equilibrium_pi
()[source]¶ Return the equilibrium distribution of the associated PH distribution.
In other word, it finds the vector pi that solves
\[\pmb \pi = \pmb\pi(\pmb A + \pmb \alpha \pmb a), \qquad \pmb\pi\pmb 1=1\]Returns: vector :math”pmbpi that solves the equilibrium equations. Return type: array
-
-
pyphase.phase.
ph_erlang
(n, lambd=None, mean=None)[source]¶ Builds an Erlang(n,lmbda).
If mean is provided then lambda = n/mean.
Parameters: - n (int) – The order of this Erlang
- lambd (float, optional) – Provide only one between lambd or mean
- mean (float, optional) – Provide only one between lambd or mean
Returns: PH representation for an Erlang
Return type: PH
-
pyphase.phase.
ph_expon
(lambd=None, mean=None)[source]¶ Builds an exponential distribution represented as PH.
If mean is provided then lambda = 1/mean.
Parameters: - lambd (float, optional) – Rate value. One between lambd an mean must be given.
- mean (float, optional) – Mean value. One between lambd an mean must be given.
Returns: PH object.
Return type: PH
-
pyphase.phase.
ph_mix
(ph1, ph2, p1)[source]¶ Produces a PH variable thet is a mixture of the two given PH variables.
Parameters: - ph1 (PH) – The first variable.
- ph2 (PH) – The second variable.
- p1 (float) – Probability of choosing the first variable. 0 <= p1 <= 1
Returns: The resulting PH variable.
Return type: PH
-
pyphase.phase.
ph_sum
(ph1, ph2)[source]¶ Produces a new PH that is the sum of the given PH variables.
Parameters: - ph1 (PH) – The first variable.
- ph2 (PH) – The second variable.
Returns: The resulting PH variable.
Return type: PH
-
pyphase.phase.
phase
(alpha, A)[source]¶ Creates a new PH variable.
This method builds a PhaseType object by given the array \(\pmb\alpha\) and matrix \(\pmb A\). The CDF for PH variable is given
\[F(t) = 1 - \boldsymbol{\alpha} e^{\boldsymbol{A} t} \boldsymbol{1} \qquad x \geq 0\]Parameters: - alpha (array of float) – The initial probabilities vector. It must satisfy \(\sum_i \alpha_i \leq 1\).
- A (matrix of float) – The transition matrix between phases.
Returns: An object representing this distribution.
Return type: PH