Class ME
- All Implemented Interfaces:
Serializable,Copyable
- Direct Known Subclasses:
CME
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classOutcome of the density scan: whether a negative value was found, and where. -
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MEfitMoments(double[] moments) Creates an ME distribution by fitting the given moments.static MEfromErlang(int k, double rate) Creates an ME distribution from an Erlang distribution.static MEfromExp(double rate) Creates an ME distribution from an exponential distribution.static MEfromHyperExp(double[] p, double[] rates) Creates an ME distribution from a HyperExponential distribution.getA()Gets the matrix parameter A.getAlpha()Gets the initial vector alpha.doublegetMean()Gets the mean, m1 = -alpha*A^(-1)*e.longGets the number of phases in this Markovian distribution.Gets the matrix representation of this Markovian process.doublegetSCV()Gets the squared coefficient of variation, var/mean^2.doublegetVar()Gets the variance, m2 - m1^2 with m2 = 2*alpha*A^(-2)*e.double[]Generates samples from this ME distribution.static ME.NegativeDensityScanscanNegativeDensity(Matrix alphaRow, Matrix A) Searches the density f(t) = -alpha*expm(A*t)*A*e for a negative value.Methods inherited from class jline.lang.processes.Markovian
acf, D, embedded, embeddedProb, evalCDF, evalCDF, evalLST, evalMeanT, evalVarT, getACF, getACF, getEmbedded, getEmbeddedProb, getIDC, getIDI, getInitProb, getMoments, getMu, getPhi, getRate, getSkewness, getSubgenerator, getVariance, idc, idi, initProb, mean, moments, mu, numberOfPhases, numPhases, phi, process, rate, sample, scv, setMean, setProcess, setRate, skewness, subgenerator, var, varianceMethods inherited from class jline.lang.processes.Distribution
evalProbInterval, getName, getNumParams, getParam, getSupport, isContinuous, isDisabled, isDiscrete, isImmediate, isMarkovian, name, numParams, param, setNumParams, setParam, support
-
Constructor Details
-
ME
Creates a Matrix Exponential distribution with specified initial vector and matrix parameter.- Parameters:
alpha- the initial vector (row vector as Matrix)A- the matrix parameter (must be square with negative real eigenvalues)- Throws:
IllegalArgumentException- if the representation is invalid
-
ME
Creates a Matrix Exponential distribution, optionally skipping the density scan.- Parameters:
alpha- the initial vector (row vector as Matrix)A- the matrix parameter (must be square with negative real eigenvalues)checkDensity- scan the density for a negative value. Set to false only by subclasses whose representation is a density by construction, such asCME, where the scan cannot fire and costs O(1e5) propagations of a large matrix.- Throws:
IllegalArgumentException- if the representation is invalid
-
-
Method Details
-
scanNegativeDensity
Searches the density f(t) = -alpha*expm(A*t)*A*e for a negative value.A negative value found here is a witness: it proves that the representation is not a distribution. Finding none proves nothing, so the caller must not report the converse.
This is used in place of
CheckMEPositiveDensityas the trigger for the construction-time warning. That routine searches for a Markovian monocyclic equivalent, which is a sufficient condition only, and its verdict depends on the representation rather than on the distribution: foralpha = [1,0,0],A = [[-0.5,0,0],[0,-1,w],[0,-w,-1]]the distribution is Exp(0.5) for every w, yet the search fails once w >= 2*pi. It also costs of the order of a second per call at search order 1000, which is far too slow for a constructor.The horizon covers all but
ME_SCAN_TAILof the mass, using the dominant (least negative) eigenvalue of A; the sampling rate resolves the fastest oscillation present, taken from the largest imaginary part.- Parameters:
alphaRow- the initial vector, as a 1 x n rowA- the matrix parameter- Returns:
- the scan outcome
-
getAlpha
Gets the initial vector alpha.- Returns:
- the initial vector as a Matrix
-
getA
Gets the matrix parameter A.- Returns:
- the matrix parameter A
-
getNumberOfPhases
public long getNumberOfPhases()Description copied from class:MarkovianGets the number of phases in this Markovian distribution.- Overrides:
getNumberOfPhasesin classMarkovian- Returns:
- the number of phases
-
getProcess
Description copied from class:MarkovianGets the matrix representation of this Markovian process.- Overrides:
getProcessin classMarkovian- Returns:
- MatrixCell containing D0, D1, ... matrices
-
sample
Generates samples from this ME distribution.Sampling inverts the exact CDF F(t) = 1 - alpha*exp(A*t)*e. The CTMC walk inherited from
Markovian(map_sample) is not used because it presumes a phase-type interpretation of (alpha, A), which fails whenever alpha has negative entries or A has negative off-diagonal entries. -
getMean
public double getMean()Gets the mean, m1 = -alpha*A^(-1)*e.Overrides the Markovian formula 1/map_lambda, which obtains the rate from the stationary vector of D0+D1. That vector is a probabilistic object of a Markovian process, and computing it for an ME means solving a linear system whose conditioning degrades with the oscillation of A: a CME of order 101 came out with a relative error of 4e-8, where the definition below is exact to 1e-13. Native Python ME.getMean already uses the definition.
-
getVar
public double getVar()Gets the variance, m2 - m1^2 with m2 = 2*alpha*A^(-2)*e. -
getSCV
public double getSCV()Gets the squared coefficient of variation, var/mean^2. -
fitMoments
Creates an ME distribution by fitting the given moments. Uses BuTools MEFromMoments algorithm.- Parameters:
moments- array of moments (requires 2*M-1 moments for order M ME distribution)- Returns:
- an ME distribution matching the given moments
- Throws:
IllegalArgumentException- if moments are invalid or fitting fails
-
fromExp
Creates an ME distribution from an exponential distribution. This is a convenience method showing that Exp is a special case of ME.- Parameters:
rate- the rate parameter (lambda)- Returns:
- an ME distribution equivalent to Exp(rate)
-
fromErlang
Creates an ME distribution from an Erlang distribution. This is a convenience method showing that Erlang is a special case of ME.- Parameters:
k- number of phasesrate- rate parameter for each phase- Returns:
- an ME distribution equivalent to Erlang(k, rate)
-
fromHyperExp
Creates an ME distribution from a HyperExponential distribution. This is a convenience method showing that HyperExp is a special case of ME.- Parameters:
p- array of probabilities for each branchrates- array of rates for each branch- Returns:
- an ME distribution equivalent to HyperExp(p, rates)
-