Class ProbabilityMassFunctionImpl
java.lang.Object
de.uka.ipd.sdq.probfunction.math.impl.ProbabilityFunctionImpl
de.uka.ipd.sdq.probfunction.math.impl.ProbabilityMassFunctionImpl
- All Implemented Interfaces:
IProbabilityFunction
,IProbabilityMassFunction
public class ProbabilityMassFunctionImpl
extends ProbabilityFunctionImpl
implements IProbabilityMassFunction
-
Field Summary
Fields inherited from class de.uka.ipd.sdq.probfunction.math.impl.ProbabilityFunctionImpl
pfFactory, randomGenerator
-
Constructor Summary
ModifierConstructorDescriptionprotected
ProbabilityMassFunctionImpl
(List<ISample> samples, IUnit unit, boolean hasOrderedDomain, boolean isInFrequencyDomain, IRandomGenerator generator) -
Method Summary
Modifier and TypeMethodDescriptionAdds 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.void
checks whether the following constraints are fulfilled : the sum of all probabilities is one.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.Generates a random number of the probability function's domain, whose distribution is defined by the probability function.boolean
double
For a probability function, whose domain is integer or real the arithmetic mean - the sum of all measurements divided by the number of observations in the data set - is returned.returns the cumulative probability function associated with this probability function.Computes the Fourier transform of the probability mass function.Computes the inverse Fourier transform of the probability mass function.A median is a number dividing the higher half of a sample, a population, or a probability distribution from the lower half.getPercentile
(int p) In descriptive statistics, the 'p'th percentile is a scale value for a data series equal to the p/100 quantile.double
Computes the sum of all probabilities specified in the function.List of samples describing the pmf.boolean
Add all values from valuesOther to valuesThis that have not been there before.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.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.shiftDomain
(double scalar) Shifts each value of the PMF by the given scalar (i.e., adds the given scalar to each value).stretchDomain
(double scalar) Stretches the domain of the PMF by the given scalar (i.e, multiplies each value with the given scalar).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 class de.uka.ipd.sdq.probfunction.math.impl.ProbabilityFunctionImpl
getRandomGenerator, getUnit, hasOrderedDomain, isInFrequencyDomain, isInTimeDomain, setInFrequencyDomain, setRandomGenerator, setUnit
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface de.uka.ipd.sdq.probfunction.math.IProbabilityFunction
getUnit, hasOrderedDomain, isInFrequencyDomain, isInTimeDomain
-
Constructor Details
-
ProbabilityMassFunctionImpl
protected ProbabilityMassFunctionImpl(List<ISample> samples, IUnit unit, boolean hasOrderedDomain, boolean isInFrequencyDomain, IRandomGenerator generator)
-
-
Method Details
-
add
Description copied from interface:IProbabilityMassFunction
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.- Specified by:
add
in interfaceIProbabilityMassFunction
- Parameters:
pmf
- Function to add.- Returns:
- A new pmf that contains the sum of both.
- Throws:
DifferentDomainsException
- if the domains of both function differ.
-
mult
Description copied from interface:IProbabilityMassFunction
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.- Specified by:
mult
in interfaceIProbabilityMassFunction
- 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.
-
scale
Description copied from interface:IProbabilityMassFunction
Scales the probabilities of a probability mass functions (pmf) on a 'per value' basis.
h(x) = a * f(x) (f = this, a = parameter scalar)- Specified by:
scale
in interfaceIProbabilityMassFunction
- Parameters:
scalar
- the value to scale the probabilities.- Returns:
- A new pmf that contains the scaled probabilities.
-
div
Description copied from interface:IProbabilityMassFunction
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.- Specified by:
div
in interfaceIProbabilityMassFunction
- 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.
-
sub
Description copied from interface:IProbabilityMassFunction
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.- Specified by:
sub
in interfaceIProbabilityMassFunction
- Parameters:
pmf
- Function to substract.- Returns:
- A new pmf that contains the difference of both.
- Throws:
DifferentDomainsException
- if the domains of both function differ.
-
haveSameDomain
Add all values from valuesOther to valuesThis that have not been there before. Afterwards, valuesThis should contain all values of valuesOther (and possibly more)- Specified by:
haveSameDomain
in interfaceIProbabilityMassFunction
- Parameters:
valuesThis
-valuesOther
-- Returns:
-
getFourierTramsform
Description copied from interface:IProbabilityMassFunction
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.- Specified by:
getFourierTramsform
in interfaceIProbabilityMassFunction
- Returns:
- Fourier transform of pmf (in time domain).
-
getInverseFourierTransform
Description copied from interface:IProbabilityMassFunction
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.- Specified by:
getInverseFourierTransform
in interfaceIProbabilityMassFunction
- Returns:
- Fourier transform of pmf (in time domain).
-
getSamples
Description copied from interface:IProbabilityMassFunction
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.- Specified by:
getSamples
in interfaceIProbabilityMassFunction
- Returns:
- the samples
-
setSamples
Description copied from interface:IProbabilityMassFunction
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!- Specified by:
setSamples
in interfaceIProbabilityMassFunction
- Parameters:
samples
- the samples to set- Throws:
ProbabilitySumNotOneException
-
getArithmeticMeanValue
Description copied from interface:IProbabilityFunction
For a probability function, whose domain is integer or real the arithmetic mean - the sum of all measurements divided by the number of observations in the data set - is returned.- Specified by:
getArithmeticMeanValue
in interfaceIProbabilityFunction
- Returns:
- The arithmetic mean.
- Throws:
DomainNotNumbersException
-
getMedian
Description copied from interface:IProbabilityFunction
A median is a number dividing the higher half of a sample, a population, or a probability distribution from the lower half. The median of a finite list of numbers can be found by arranging all the observations from lowest value to highest value and picking the middle one.- Specified by:
getMedian
in interfaceIProbabilityFunction
- Returns:
- Object that is the border for the median.
- Throws:
UnorderedDomainException
-
getPercentile
Description copied from interface:IProbabilityFunction
In descriptive statistics, the 'p'th percentile is a scale value for a data series equal to the p/100 quantile. Thus:
* The 1st percentile cuts off lowest 1% of data
* The 98th percentile cuts off lowest 98% of data
* The 25th percentile is the first quartile
* The 50th percentile is the median.
One definition is that the pth percentile of n ordered values is obtained by first calculating the rank k = p(n+1)/100, rounded to the nearest integer and then taking the value that corresponds to that rank.- Specified by:
getPercentile
in interfaceIProbabilityFunction
- Parameters:
p
- sets the percentile which shall be computed. p must take values between 0 and 100.- Returns:
- Object that is the border for the 'p'th percentile.
- Throws:
IndexOutOfBoundsException
UnorderedDomainException
-
drawSample
Description copied from interface:IProbabilityMassFunction
Generates a random number of the probability function's domain, whose distribution is defined by the probability function.- Specified by:
drawSample
in interfaceIProbabilityMassFunction
- Returns:
- A sample of the PMF's domain.
-
equals
-
getProbabilitySum
public double getProbabilitySum()Description copied from interface:IProbabilityFunction
Computes the sum of all probabilities specified in the function. For pdfs this is the area under the graph; for pmfs the sum of all probabilities.- Specified by:
getProbabilitySum
in interfaceIProbabilityFunction
- Returns:
- Sum of all probabilities in the function.
-
checkConstrains
public void checkConstrains() throws ProbabilitySumNotOneException, InvalidSampleValueException, UnitNotSetException, UnitNameNotSetExceptionDescription copied from interface:IProbabilityFunction
checks whether the following constraints are fulfilled : the sum of all probabilities is one. all values are greater or equal 0.- Specified by:
checkConstrains
in interfaceIProbabilityFunction
- Throws:
ProbabilitySumNotOneException
InvalidSampleValueException
UnitNotSetException
UnitNameNotSetException
-
getCumulativeFunction
Description copied from interface:IProbabilityMassFunction
returns the cumulative probability function associated with this probability function.- Specified by:
getCumulativeFunction
in interfaceIProbabilityMassFunction
- Returns:
- the computed cumulative probability function.
-
shiftDomain
Description copied from interface:IProbabilityMassFunction
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.- Specified by:
shiftDomain
in interfaceIProbabilityMassFunction
- Returns:
- Throws:
DomainNotNumbersException
-
stretchDomain
Description copied from interface:IProbabilityMassFunction
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.- Specified by:
stretchDomain
in interfaceIProbabilityMassFunction
- Returns:
- Throws:
DomainNotNumbersException
-