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
ConstructorsModifierConstructorDescriptionprotectedProbabilityMassFunctionImpl(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.voidchecks 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.booleandoubleFor 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.doubleComputes the sum of all probabilities specified in the function.List of samples describing the pmf.booleanAdd 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)voidsetSamples(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, setUnitMethods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:IProbabilityMassFunctionAdds 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:
addin 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:IProbabilityMassFunctionMultiplies 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:
multin 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:IProbabilityMassFunctionScales 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:
scalein interfaceIProbabilityMassFunction- Parameters:
scalar- the value to scale the probabilities.- Returns:
- A new pmf that contains the scaled probabilities.
-
div
Description copied from interface:IProbabilityMassFunctionDivides 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:
divin 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:IProbabilityMassFunctionSubstracts 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:
subin 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:
haveSameDomainin interfaceIProbabilityMassFunction- Parameters:
valuesThis-valuesOther-- Returns:
-
getFourierTramsform
Description copied from interface:IProbabilityMassFunctionComputes 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:
getFourierTramsformin interfaceIProbabilityMassFunction- Returns:
- Fourier transform of pmf (in time domain).
-
getInverseFourierTransform
Description copied from interface:IProbabilityMassFunctionComputes 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:
getInverseFourierTransformin interfaceIProbabilityMassFunction- Returns:
- Fourier transform of pmf (in time domain).
-
getSamples
Description copied from interface:IProbabilityMassFunctionList 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:
getSamplesin interfaceIProbabilityMassFunction- Returns:
- the samples
-
setSamples
Description copied from interface:IProbabilityMassFunctionList 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:
setSamplesin interfaceIProbabilityMassFunction- Parameters:
samples- the samples to set- Throws:
ProbabilitySumNotOneException
-
getArithmeticMeanValue
Description copied from interface:IProbabilityFunctionFor 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:
getArithmeticMeanValuein interfaceIProbabilityFunction- Returns:
- The arithmetic mean.
- Throws:
DomainNotNumbersException
-
getMedian
Description copied from interface:IProbabilityFunctionA 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:
getMedianin interfaceIProbabilityFunction- Returns:
- Object that is the border for the median.
- Throws:
UnorderedDomainException
-
getPercentile
Description copied from interface:IProbabilityFunctionIn 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:
getPercentilein 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:
IndexOutOfBoundsExceptionUnorderedDomainException
-
drawSample
Description copied from interface:IProbabilityMassFunctionGenerates a random number of the probability function's domain, whose distribution is defined by the probability function.- Specified by:
drawSamplein interfaceIProbabilityMassFunction- Returns:
- A sample of the PMF's domain.
-
equals
-
getProbabilitySum
public double getProbabilitySum()Description copied from interface:IProbabilityFunctionComputes 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:
getProbabilitySumin interfaceIProbabilityFunction- Returns:
- Sum of all probabilities in the function.
-
checkConstrains
public void checkConstrains() throws ProbabilitySumNotOneException, InvalidSampleValueException, UnitNotSetException, UnitNameNotSetExceptionDescription copied from interface:IProbabilityFunctionchecks whether the following constraints are fulfilled : the sum of all probabilities is one. all values are greater or equal 0.- Specified by:
checkConstrainsin interfaceIProbabilityFunction- Throws:
ProbabilitySumNotOneExceptionInvalidSampleValueExceptionUnitNotSetExceptionUnitNameNotSetException
-
getCumulativeFunction
Description copied from interface:IProbabilityMassFunctionreturns the cumulative probability function associated with this probability function.- Specified by:
getCumulativeFunctionin interfaceIProbabilityMassFunction- Returns:
- the computed cumulative probability function.
-
shiftDomain
Description copied from interface:IProbabilityMassFunctionShifts 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:
shiftDomainin interfaceIProbabilityMassFunction- Returns:
- Throws:
DomainNotNumbersException
-
stretchDomain
Description copied from interface:IProbabilityMassFunctionStretches 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:
stretchDomainin interfaceIProbabilityMassFunction- Returns:
- Throws:
DomainNotNumbersException
-