Class SamplePDFImpl
- java.lang.Object
-
- de.uka.ipd.sdq.probfunction.math.impl.ProbabilityFunctionImpl
-
- de.uka.ipd.sdq.probfunction.math.impl.ProbabilityDensityFunctionImpl
-
- de.uka.ipd.sdq.probfunction.math.impl.SamplePDFImpl
-
- All Implemented Interfaces:
IProbabilityDensityFunction
,IProbabilityFunction
,ISamplePDF
public class SamplePDFImpl extends ProbabilityDensityFunctionImpl implements ISamplePDF
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class de.uka.ipd.sdq.probfunction.math.impl.ProbabilityDensityFunctionImpl
ProbabilityDensityFunctionImpl.CompareOperation
-
-
Field Summary
-
Fields inherited from class de.uka.ipd.sdq.probfunction.math.impl.ProbabilityFunctionImpl
pfFactory, randomGenerator
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SamplePDFImpl(double distance, IUnit unit, boolean isInFrequencyDomain, IRandomGenerator generator)
protected
SamplePDFImpl(double distance, IUnit unit, IRandomGenerator generator)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description IProbabilityDensityFunction
add(IProbabilityDensityFunction pdf)
Adds two ProbabilityDensityFunctions on a "per value" basis:
h(x) = f(x) + g(x)
An addition can only be performed if both functions are in the same domain (frequency or time).void
checkConstrains()
checks whether the following constraints are fulfilled : the sum of all probabilities is one.protected static List<ISamplePDF>
createFunctionsWithEqualDistance(ISamplePDF pdf1, ISamplePDF pdf2)
Creates two functions with an equal distance, if both functions are in the time domain.IProbabilityDensityFunction
div(IProbabilityDensityFunction pdf)
Divides two ProbabilityDensityFunctions on a "per value" basis:
h(x) = f(x) / g(x)
A division can only be performed if both functions are in the same domain (frequency or time).double
drawSample()
Generates a random number of the probability function's domain, whose distribution is defined by the probability function.boolean
equals(Object obj)
void
expand(int newSize)
Increases the number of sampling points.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.IProbabilityDensityFunction
getCumulativeFunction()
returns the cumulative probability function associated with this probability function.double
getDistance()
Returns the distance between the sampling points.org.apache.commons.math.complex.Complex
getFillValue()
Returns the value used to fill unset sampling points at the end of the function.double
getFillValueAsDouble()
Returns the real part of the value used to fill unset sampling points at the end of the function.IProbabilityDensityFunction
getFourierTransform()
Computes the fourier transform of the probability density function.ISamplePDF
getFunctionWithNewDistance(double distance)
Creates a new SamplePDF that describes the same PDF, but whose sampling points are computed according to a new distance.IProbabilityDensityFunction
getInverseFourierTransform()
Computes the inverse fourier transform of the probability density function.double
getLowerDomainBorder()
Returns the smallest values of the domain.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.org.apache.commons.math.complex.Complex
getValue(int pos)
Double
getValueAsDouble(int pos)
List<org.apache.commons.math.complex.Complex>
getValues()
Returns the sampling points of the function as complex numbers.List<Double>
getValuesAsDouble()
Returns the real part of the function's samples.double
greaterThan(IProbabilityDensityFunction pdf)
Computes the probability that the random variable specified by this PDF is greater than the random variable specified by pdf.int
hashCode()
double
lessThan(IProbabilityDensityFunction pdf)
Computes the probability that the random variable specified by this PDF is less than the random variable specified by pdf.IProbabilityDensityFunction
mult(IProbabilityDensityFunction pdf)
Multiplies two ProbabilityDensityFunctions on a "per value" basis:
h(x) = f(x) * g(x)
A multiplication can only be performed if both functions are in the same domain (frequency or time).int
numberOfSamples()
The number of samples used to approximate the pdf.double
probabilisticEquals(IProbabilityDensityFunction pdf)
Computes the probability that two random variables characterised by the given PDFs are equal.IProbabilityDensityFunction
scale(double scalar)
Scales a ProbabilityDensityFunctions on a "per value" basis:
h(x) = a * f(x)void
setFillValue(double fillValue)
Sets the real part of the fill value to fillValue and the imaginary part to zero.void
setFillValue(org.apache.commons.math.complex.Complex fillValue)
Sets the new fill value.void
setValues(List<org.apache.commons.math.complex.Complex> values, boolean isInFrequencyDomain)
Sets the sampling points of the function.void
setValuesAsDouble(List<Double> values)
/** Sets the sampling points of the function.IProbabilityDensityFunction
shiftDomain(double scalar)
Shifts the domain values of the PDF by the given scalarIProbabilityDensityFunction
stretchDomain(double scalar)
Stretches the domain values of the PDF.IProbabilityDensityFunction
sub(IProbabilityDensityFunction pdf)
Subtracts two ProbabilityDensityFunctions on a "per value" basis:
h(x) = f(x) - g(x)
A substraction can only be performed if both functions are in the same domain (frequency or time).String
toString()
-
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, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface de.uka.ipd.sdq.probfunction.math.IProbabilityFunction
getUnit, hasOrderedDomain, isInFrequencyDomain, isInTimeDomain
-
-
-
-
Constructor Detail
-
SamplePDFImpl
protected SamplePDFImpl(double distance, IUnit unit, IRandomGenerator generator)
-
SamplePDFImpl
protected SamplePDFImpl(double distance, IUnit unit, boolean isInFrequencyDomain, IRandomGenerator generator)
-
-
Method Detail
-
add
public IProbabilityDensityFunction add(IProbabilityDensityFunction pdf) throws UnknownPDFTypeException, FunctionsInDifferenDomainsException, IncompatibleUnitsException
Description copied from interface:IProbabilityDensityFunction
Adds two ProbabilityDensityFunctions on a "per value" basis:
h(x) = f(x) + g(x)
An addition can only be performed if both functions are in the same domain (frequency or time). If not a FunctionsInDifferenDomainsException is thrown.- Specified by:
add
in interfaceIProbabilityDensityFunction
- Parameters:
pdf
- g(x), probability density function to add.- Returns:
- The sum of this function (f(x)) and pdf (g(x))
- Throws:
UnknownPDFTypeException
- Thrown if one of the function is of an unknown type (not SamplePDf or BoxedPDF).FunctionsInDifferenDomainsException
- Thrown if both functions are in different domains.IncompatibleUnitsException
- Thrown if both functions have units that do not match.
-
mult
public IProbabilityDensityFunction mult(IProbabilityDensityFunction pdf) throws UnknownPDFTypeException, FunctionsInDifferenDomainsException, IncompatibleUnitsException
Description copied from interface:IProbabilityDensityFunction
Multiplies two ProbabilityDensityFunctions on a "per value" basis:
h(x) = f(x) * g(x)
A multiplication can only be performed if both functions are in the same domain (frequency or time). If not a FunctionsInDifferenDomainsException is thrown.- Specified by:
mult
in interfaceIProbabilityDensityFunction
- Parameters:
pdf
- g(x), probability density function to multiply with.- Returns:
- The product of this function (f(x)) and pdf (g(x))
- Throws:
UnknownPDFTypeException
- Thrown if one of the function is of an unknown type (not SamplePDf or BoxedPDF).FunctionsInDifferenDomainsException
- Thrown if both functions are in different domains.IncompatibleUnitsException
- Thrown if both functions have units that do not match.
-
div
public IProbabilityDensityFunction div(IProbabilityDensityFunction pdf) throws FunctionsInDifferenDomainsException, UnknownPDFTypeException, IncompatibleUnitsException
Description copied from interface:IProbabilityDensityFunction
Divides two ProbabilityDensityFunctions on a "per value" basis:
h(x) = f(x) / g(x)
A division can only be performed if both functions are in the same domain (frequency or time). If not a FunctionsInDifferenDomainsException is thrown.- Specified by:
div
in interfaceIProbabilityDensityFunction
- Parameters:
pdf
- g(x), probability density function to divide by.- Returns:
- The fraction of this function (f(x)) and pdf (g(x))
- Throws:
FunctionsInDifferenDomainsException
UnknownPDFTypeException
IncompatibleUnitsException
-
sub
public IProbabilityDensityFunction sub(IProbabilityDensityFunction pdf) throws FunctionsInDifferenDomainsException, UnknownPDFTypeException, IncompatibleUnitsException
Description copied from interface:IProbabilityDensityFunction
Subtracts two ProbabilityDensityFunctions on a "per value" basis:
h(x) = f(x) - g(x)
A substraction can only be performed if both functions are in the same domain (frequency or time). If not a FunctionsInDifferenDomainsException is thrown.- Specified by:
sub
in interfaceIProbabilityDensityFunction
- Parameters:
pdf
- g(x), probability density function to substract.- Returns:
- The difference of this function (f(x)) and pdf (g(x))
- Throws:
FunctionsInDifferenDomainsException
- Thrown if both functions are in different domains.UnknownPDFTypeException
- Thrown if one of the function is of an unknown type (not SamplePDf or BoxedPDF).IncompatibleUnitsException
- Thrown if both functions have units that do not match.
-
scale
public IProbabilityDensityFunction scale(double scalar)
Description copied from interface:IProbabilityDensityFunction
Scales a ProbabilityDensityFunctions on a "per value" basis:
h(x) = a * f(x)- Specified by:
scale
in interfaceIProbabilityDensityFunction
- Parameters:
scalar
- a, value to scale with.- Returns:
- The scaled function a*f(x)
-
getFourierTransform
public IProbabilityDensityFunction getFourierTransform()
Description copied from interface:IProbabilityDensityFunction
Computes the fourier transform of the probability density function. Can only be applied if 'isInTimeDomain()' is true, otherwise a FunctionNotInTimeDomain exception is thrown.- Specified by:
getFourierTransform
in interfaceIProbabilityDensityFunction
- Returns:
- fourier transform of the PDF (in frequency domain)
-
getInverseFourierTransform
public IProbabilityDensityFunction getInverseFourierTransform()
Description copied from interface:IProbabilityDensityFunction
Computes the inverse fourier transform of the probability density function. Can only be applied if 'isInFrequencyDomain()' is true, otherwise a FunctionNotInFrequencyDomainException is thrown.- Specified by:
getInverseFourierTransform
in interfaceIProbabilityDensityFunction
- Returns:
- inverse fourier transform of the PDF (in time domain)
-
expand
public void expand(int newSize) throws SizeTooSmallException
Description copied from interface:ISamplePDF
Increases the number of sampling points. The new enries are filled with the value returned by 'getFillValue()'. The values are added at the end of the pdf.- Specified by:
expand
in interfaceISamplePDF
- Parameters:
newSize
- the new number of sampling points. If newSize is smaller than the original size, an exception is thrown.- Throws:
SizeTooSmallException
- Thrown if newSize is small than the current number of elements.
-
getDistance
public double getDistance()
Description copied from interface:ISamplePDF
Returns the distance between the sampling points.- Specified by:
getDistance
in interfaceISamplePDF
- Returns:
- distance between the sampling points.
-
getValuesAsDouble
public List<Double> getValuesAsDouble()
Description copied from interface:ISamplePDF
Returns the real part of the function's samples. Copy only!- Specified by:
getValuesAsDouble
in interfaceISamplePDF
- Returns:
- Samples of the function.
-
setValuesAsDouble
public void setValuesAsDouble(List<Double> values)
Description copied from interface:ISamplePDF
/** Sets the sampling points of the function. As the values are doubles, only the real part of the complex numbers is set. The imaginary part is set to zero. The function is automatically set to the time domain. Note: The sum of all values has to be one, otherwise a ProbabilitySumNotOneException is thrown.- Specified by:
setValuesAsDouble
in interfaceISamplePDF
- Parameters:
values
- a new list of sampling points.
-
getFillValueAsDouble
public double getFillValueAsDouble()
Description copied from interface:ISamplePDF
Returns the real part of the value used to fill unset sampling points at the end of the function.- Specified by:
getFillValueAsDouble
in interfaceISamplePDF
- Returns:
- the fillValue
-
setFillValue
public void setFillValue(double fillValue)
Description copied from interface:ISamplePDF
Sets the real part of the fill value to fillValue and the imaginary part to zero.- Specified by:
setFillValue
in interfaceISamplePDF
- Parameters:
fillValue
- the fillValue to set
-
getFillValue
public org.apache.commons.math.complex.Complex getFillValue()
Description copied from interface:ISamplePDF
Returns the value used to fill unset sampling points at the end of the function.- Specified by:
getFillValue
in interfaceISamplePDF
- Returns:
- Fill value.
-
getFunctionWithNewDistance
public ISamplePDF getFunctionWithNewDistance(double distance) throws NegativeDistanceException, FunctionNotInTimeDomainException
Description copied from interface:ISamplePDF
Creates a new SamplePDF that describes the same PDF, but whose sampling points are computed according to a new distance.- Specified by:
getFunctionWithNewDistance
in interfaceISamplePDF
- Parameters:
distance
- Distance of the new function.- Returns:
- A new SamplePDF that describes the same PDF, but whose sampling points are adjusted to the new distance.
- Throws:
NegativeDistanceException
FunctionNotInTimeDomainException
-
getValues
public List<org.apache.commons.math.complex.Complex> getValues()
Description copied from interface:ISamplePDF
Returns the sampling points of the function as complex numbers. Copy only!- Specified by:
getValues
in interfaceISamplePDF
- Returns:
- Samples of the function.
-
setFillValue
public void setFillValue(org.apache.commons.math.complex.Complex fillValue)
Description copied from interface:ISamplePDF
Sets the new fill value.- Specified by:
setFillValue
in interfaceISamplePDF
- Parameters:
fillValue
- New fill value.
-
setValues
public void setValues(List<org.apache.commons.math.complex.Complex> values, boolean isInFrequencyDomain)
Description copied from interface:ISamplePDF
Sets the sampling points of the function.- Specified by:
setValues
in interfaceISamplePDF
- Parameters:
values
- a new list of sampling points.
-
getLowerDomainBorder
public double getLowerDomainBorder()
Description copied from interface:IProbabilityDensityFunction
Returns the smallest values of the domain. At the moment this will be zero. However, future implementations might allow arbitrary values here.- Specified by:
getLowerDomainBorder
in interfaceIProbabilityDensityFunction
- Returns:
- Smallest value of the domain.
-
drawSample
public double drawSample()
Description copied from interface:IProbabilityDensityFunction
Generates a random number of the probability function's domain, whose distribution is defined by the probability function.- Specified by:
drawSample
in interfaceIProbabilityDensityFunction
- Returns:
- A sample of the PDF's domain.
-
getArithmeticMeanValue
public double getArithmeticMeanValue() throws DomainNotNumbersException, FunctionNotInTimeDomainException
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
FunctionNotInTimeDomainException
-
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
-
numberOfSamples
public int numberOfSamples()
Description copied from interface:ISamplePDF
The number of samples used to approximate the pdf.- Specified by:
numberOfSamples
in interfaceISamplePDF
- Returns:
- Number of Samples.
-
createFunctionsWithEqualDistance
protected static List<ISamplePDF> createFunctionsWithEqualDistance(ISamplePDF pdf1, ISamplePDF pdf2)
Creates two functions with an equal distance, if both functions are in the time domain. Precondition: Functions are in the same domain.- Parameters:
pdf1
-pdf2
-- Returns:
- Throws:
FunctionNotInTimeDomainException
NegativeDistanceException
FunctionNotInTimeDomainException
- Thrown if one of the input pdfs is not in the time domain.
-
getProbabilitySum
public double getProbabilitySum() throws FunctionNotInTimeDomainException
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.
- Throws:
FunctionNotInTimeDomainException
-
checkConstrains
public void checkConstrains() throws NegativeDistanceException, ProbabilitySumNotOneException, FunctionNotInTimeDomainException, UnitNotSetException, UnitNameNotSetException, InvalidSampleValueException
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.
-
getCumulativeFunction
public IProbabilityDensityFunction getCumulativeFunction() throws FunctionNotInTimeDomainException
Description copied from interface:IProbabilityDensityFunction
returns the cumulative probability function associated with this probability function.- Specified by:
getCumulativeFunction
in interfaceIProbabilityDensityFunction
- Returns:
- the computed cumulative probability function.
- Throws:
FunctionNotInTimeDomainException
-
probabilisticEquals
public double probabilisticEquals(IProbabilityDensityFunction pdf) throws ProbabilityFunctionException
Description copied from interface:IProbabilityDensityFunction
Computes the probability that two random variables characterised by the given PDFs are equal. Note that the randomvariables have to be independent.- Specified by:
probabilisticEquals
in interfaceIProbabilityDensityFunction
- Parameters:
pdf
- PDF to compare to.- Returns:
- Probability that the two random variables characterised by the PDFs are equal.
- Throws:
ProbabilityFunctionException
-
greaterThan
public double greaterThan(IProbabilityDensityFunction pdf) throws ProbabilityFunctionException
Description copied from interface:IProbabilityDensityFunction
Computes the probability that the random variable specified by this PDF is greater than the random variable specified by pdf. Note that the randomvariables have to be independent.- Specified by:
greaterThan
in interfaceIProbabilityDensityFunction
- Parameters:
pdf
- PDF to compare to.- Returns:
- Probability X_this > X_pdf
- Throws:
ProbabilityFunctionException
-
lessThan
public double lessThan(IProbabilityDensityFunction pdf) throws ProbabilityFunctionException
Description copied from interface:IProbabilityDensityFunction
Computes the probability that the random variable specified by this PDF is less than the random variable specified by pdf. Note that the randomvariables have to be independent.- Specified by:
lessThan
in interfaceIProbabilityDensityFunction
- Parameters:
pdf
- PDF to compare to.- Returns:
- Probability X_this < X_pdf
- Throws:
ProbabilityFunctionException
-
stretchDomain
public IProbabilityDensityFunction stretchDomain(double scalar)
Description copied from interface:IProbabilityDensityFunction
Stretches the domain values of the PDF. This is equivalent to the multiplication of the specified random variable by the given scalar.- Specified by:
stretchDomain
in interfaceIProbabilityDensityFunction
- Returns:
-
shiftDomain
public IProbabilityDensityFunction shiftDomain(double scalar) throws DomainNotNumbersException
Description copied from interface:IProbabilityDensityFunction
Shifts the domain values of the PDF by the given scalar- Specified by:
shiftDomain
in interfaceIProbabilityDensityFunction
- Returns:
- Throws:
DomainNotNumbersException
-
getValue
public org.apache.commons.math.complex.Complex getValue(int pos)
- Specified by:
getValue
in interfaceISamplePDF
-
getValueAsDouble
public Double getValueAsDouble(int pos)
- Specified by:
getValueAsDouble
in interfaceISamplePDF
-
-