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
Constructors Modifier Constructor Description protected
ProbabilityMassFunctionImpl(List<ISample> samples, IUnit unit, boolean hasOrderedDomain, boolean isInFrequencyDomain, IRandomGenerator generator)
-
Method Summary
All Methods Instance Methods Concrete 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.void
checkConstrains()
checks whether the following constraints are fulfilled : the sum of all probabilities is one.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.boolean
equals(Object obj)
double
getArithmeticMeanValue()
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.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.Object
getMedian()
A median is a number dividing the higher half of a sample, a population, or a probability distribution from the lower half.Object
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
getProbabilitySum()
Computes the sum of all probabilities specified in the function.List<ISample>
getSamples()
List of samples describing the pmf.boolean
haveSameDomain(IProbabilityMassFunction pmf)
Add all values from valuesOther to valuesThis that have not been there before.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 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 Detail
-
ProbabilityMassFunctionImpl
protected ProbabilityMassFunctionImpl(List<ISample> samples, IUnit unit, boolean hasOrderedDomain, boolean isInFrequencyDomain, IRandomGenerator generator)
-
-
Method Detail
-
add
public IProbabilityMassFunction add(IProbabilityMassFunction pmf) throws DifferentDomainsException
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
public IProbabilityMassFunction mult(IProbabilityMassFunction pmf) throws DifferentDomainsException
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
public IProbabilityMassFunction scale(double scalar)
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
public IProbabilityMassFunction div(IProbabilityMassFunction pmf) throws DifferentDomainsException
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
public IProbabilityMassFunction sub(IProbabilityMassFunction pmf) throws DifferentDomainsException
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
public boolean haveSameDomain(IProbabilityMassFunction pmf)
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
public IProbabilityMassFunction 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
public IProbabilityMassFunction 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
public List<ISample> 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
public void setSamples(List<ISample> samples)
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
public double getArithmeticMeanValue() throws DomainNotNumbersException
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
public Object getMedian() throws UnorderedDomainException
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
public Object getPercentile(int p) throws IndexOutOfBoundsException, UnorderedDomainException
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
public Object 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
public boolean equals(Object obj)
- Overrides:
equals
in classObject
- See Also:
Object.equals(java.lang.Object)
-
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, UnitNameNotSetException
Description 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
public IProbabilityMassFunction 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
public IProbabilityMassFunction shiftDomain(double scalar) throws DomainNotNumbersException
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
public IProbabilityMassFunction stretchDomain(double scalar) throws DomainNotNumbersException
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
-
-