Package de.uka.ipd.sdq.probfunction.math
Interface IProbabilityMassFunction
-
- All Superinterfaces:
IProbabilityFunction
- All Known Implementing Classes:
ProbabilityMassFunctionImpl
public interface IProbabilityMassFunction extends IProbabilityFunction
A probability mass function (abbreviated pmf) gives the probability that a discrete random variable is exactly equal to some value. A probability mass function differs from a probability density function in that the values of the latter, defined only for continuous random variables, are not probabilities; rather, its integral over a set of possible values of the random variable is a probability. Note that the operations defined here are not suitable to add and multiply random numbers in general (e.g. in the DependencySolver). They are defined per-value and are required for internal computations (e.g. Fourier Transformation).
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description IProbabilityMassFunction
add(IProbabilityMassFunction pmf)
Adds the probabilities of two probability mass functions (pmf) on a 'per value' basis.
h(x) = f(x) + g(x) (f = this, g = parameter pmf)
For the addition, the domains of both pmfs have to be equal.IProbabilityMassFunction
div(IProbabilityMassFunction pmf)
Divides the probabilities of two probability mass functions (pmf) on a 'per value' basis.
h(x) = f(x) / g(x) (f = this, g = parameter pmf)
For the division, the domains of both pmfs have to be equal.Object
drawSample()
Generates a random number of the probability function's domain, whose distribution is defined by the probability function.IProbabilityMassFunction
getCumulativeFunction()
returns the cumulative probability function associated with this probability function.IProbabilityMassFunction
getFourierTramsform()
Computes the Fourier transform of the probability mass function.IProbabilityMassFunction
getInverseFourierTransform()
Computes the inverse Fourier transform of the probability mass function.List<ISample>
getSamples()
List of samples describing the pmf.boolean
haveSameDomain(IProbabilityMassFunction pmf)
Check whether the two PMFs have compatible domains.IProbabilityMassFunction
mult(IProbabilityMassFunction pmf)
Multiplies the probabilities of two probability mass functions (pmf) on a 'per value' basis.
h(x) = f(x) * g(x) (f = this, g = parameter pmf)
For the multiplication, the domains of both pmfs have to be equal.IProbabilityMassFunction
scale(double scalar)
Scales the probabilities of a probability mass functions (pmf) on a 'per value' basis.
h(x) = a * f(x) (f = this, a = parameter scalar)void
setSamples(List<ISample> samples)
List of samples describing the pmf.IProbabilityMassFunction
shiftDomain(double scalar)
Shifts each value of the PMF by the given scalar (i.e., adds the given scalar to each value).IProbabilityMassFunction
stretchDomain(double scalar)
Stretches the domain of the PMF by the given scalar (i.e, multiplies each value with the given scalar).IProbabilityMassFunction
sub(IProbabilityMassFunction pmf)
Substracts the probabilities of two probability mass functions (pmf) on a 'per value' basis.
h(x) = f(x) - g(x) (f = this, g = parameter pmf)
For the substraction, the domains of both pmfs have to be equal.-
Methods inherited from interface de.uka.ipd.sdq.probfunction.math.IProbabilityFunction
checkConstrains, getArithmeticMeanValue, getMedian, getPercentile, getProbabilitySum, getUnit, hasOrderedDomain, isInFrequencyDomain, isInTimeDomain
-
-
-
-
Method Detail
-
drawSample
Object drawSample()
Generates a random number of the probability function's domain, whose distribution is defined by the probability function.- Returns:
- A sample of the PMF's domain.
-
add
IProbabilityMassFunction add(IProbabilityMassFunction pmf) throws DifferentDomainsException
Adds the probabilities of two probability mass functions (pmf) on a 'per value' basis.
h(x) = f(x) + g(x) (f = this, g = parameter pmf)
For the addition, the domains of both pmfs have to be equal. This means that- * the value objects of the pmf's samples have to be of the same class and
- * for each value object of the samples in function f (this) there is exactly one equal value object in the samples of function g (pmf) and vice versa. Here, equal means that Object.equal(...) returns true for both objects.
If the domain of both functions are not equal, a DifferentDomainsException is thrown.- Parameters:
pmf
- Function to add.- Returns:
- A new pmf that contains the sum of both.
- Throws:
DifferentDomainsException
- if the domains of both function differ.
-
sub
IProbabilityMassFunction sub(IProbabilityMassFunction pmf) throws DifferentDomainsException
Substracts the probabilities of two probability mass functions (pmf) on a 'per value' basis.
h(x) = f(x) - g(x) (f = this, g = parameter pmf)
For the substraction, the domains of both pmfs have to be equal. This means that- * the value objects of the pmf's samples have to be of the same class and
- * for each value object of the samples in function f (this) there is exactly one equal value object in the samples of function g (pmf) and vice versa. Here, equal means that Object.equal(...) returns true for both objects.
If the domain of both functions are not equal, a DifferentDomainsException is thrown.- Parameters:
pmf
- Function to substract.- Returns:
- A new pmf that contains the difference of both.
- Throws:
DifferentDomainsException
- if the domains of both function differ.
-
mult
IProbabilityMassFunction mult(IProbabilityMassFunction pmf) throws DifferentDomainsException
Multiplies the probabilities of two probability mass functions (pmf) on a 'per value' basis.
h(x) = f(x) * g(x) (f = this, g = parameter pmf)
For the multiplication, the domains of both pmfs have to be equal. This means that- * the value objects of the pmf's samples have to be of the same class and
- * for each value object of the samples in function f (this) there is exactly one equal value object in the samples of function g (pmf) and vice versa. Here, equal means that Object.equal(...) returns true for both objects.
If the domain of both functions are not equal, a DifferentDomainsException is thrown.- Parameters:
pmf
- Function to multiply with.- Returns:
- A new pmf that contains the product of both.
- Throws:
DifferentDomainsException
- if the domains of both function differ.
-
div
IProbabilityMassFunction div(IProbabilityMassFunction pmf) throws DifferentDomainsException
Divides the probabilities of two probability mass functions (pmf) on a 'per value' basis.
h(x) = f(x) / g(x) (f = this, g = parameter pmf)
For the division, the domains of both pmfs have to be equal. This means that- * the value objects of the pmf's samples have to be of the same class and
- * for each value object of the samples in function f (this) there is exactly one equal value object in the samples of function g (pmf) and vice versa. Here, equal means that Object.equal(...) returns true for both objects.
If the domain of both functions are not equal, a DifferentDomainsException is thrown.- Parameters:
pmf
- Function to divide by.- Returns:
- A new pmf that contains the fraction of both.
- Throws:
DifferentDomainsException
- if the domains of both function differ.
-
scale
IProbabilityMassFunction scale(double scalar)
Scales the probabilities of a probability mass functions (pmf) on a 'per value' basis.
h(x) = a * f(x) (f = this, a = parameter scalar)- Parameters:
scalar
- the value to scale the probabilities.- Returns:
- A new pmf that contains the scaled probabilities.
-
shiftDomain
IProbabilityMassFunction shiftDomain(double scalar) throws DomainNotNumbersException
Shifts each value of the PMF by the given scalar (i.e., adds the given scalar to each value). If the scalar is larger than zero, the PMF gets shifted to the right, otherwise it gets shifted to the left.- Parameters:
scalar
-- Returns:
- Throws:
DomainNotNumbersException
-
stretchDomain
IProbabilityMassFunction stretchDomain(double scalar) throws DomainNotNumbersException
Stretches the domain of the PMF by the given scalar (i.e, multiplies each value with the given scalar). If the scalar is larger than 1, the PMF gets stretched. If the scalar is between zero and 1, the PMF gets compressed.- Parameters:
scalar
-- Returns:
- Throws:
DomainNotNumbersException
-
getFourierTramsform
IProbabilityMassFunction getFourierTramsform() throws FunctionNotInTimeDomainException
Computes the Fourier transform of the probability mass function. Note, that you should only use this function if you really know what you are doing, as this doesn't make sense in many cases for pmfs!
Can only be applied if 'isInTimeDomain()' is true, otherwise a FunctionNotInTimeDomainException is thrown.- Returns:
- Fourier transform of pmf (in time domain).
- Throws:
FunctionNotInTimeDomainException
-
getInverseFourierTransform
IProbabilityMassFunction getInverseFourierTransform() throws FunctionNotInFrequencyDomainException
Computes the inverse Fourier transform of the probability mass function. Note, that you should only use this function if you really know what you are doing, as this doesn't make sense in many cases for pmfs!
Can only be applied if 'isInFrequencyDomain()' is true, otherwise a FunctionNotInFrequencyDomainException is thrown.- Returns:
- Fourier transform of pmf (in time domain).
- Throws:
FunctionNotInFrequencyDomainException
-
getSamples
List<ISample> getSamples()
List of samples describing the pmf. They associate a value (x axis) with a probability (y axis). In case 'hasOrderedDomain' is true, they are sorted. Note: The function returns only a copy of the sample list.- Returns:
- A Copy of the list of (ordered) samples describing the pmf.
-
setSamples
void setSamples(List<ISample> samples)
List of samples describing the pmf. They associate a value (x axis) with a probability (y axis). In case the values can be ordered, they will be sorted. Note: The sum of all probabilities has to be one!- Parameters:
samples
- New list of samples describing the pmf.- Throws:
ProbabilitySumNotOneException
- Thrown if the sum of the samples probabilities is not one.
-
haveSameDomain
boolean haveSameDomain(IProbabilityMassFunction pmf)
Check whether the two PMFs have compatible domains. Integers are casted to doubles if one of the PMFs is a DoublePMF. TODO: check whether this behaviour is fine for the rest of the tools, because other classes may expect exactly the same type.- Parameters:
pmf
-- Returns:
-
getCumulativeFunction
IProbabilityMassFunction getCumulativeFunction()
returns the cumulative probability function associated with this probability function.- Returns:
- the computed cumulative probability function.
-
-