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
  • 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 interface IProbabilityMassFunction
      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 interface IProbabilityMassFunction
      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 interface IProbabilityMassFunction
      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 interface IProbabilityMassFunction
      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 interface IProbabilityMassFunction
      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 interface IProbabilityMassFunction
      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 interface IProbabilityMassFunction
      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 interface IProbabilityMassFunction
      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 interface IProbabilityMassFunction
      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 interface IProbabilityMassFunction
      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 interface IProbabilityFunction
      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 interface IProbabilityFunction
      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 interface IProbabilityFunction
      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 interface IProbabilityMassFunction
      Returns:
      A sample of the PMF's domain.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
      See Also:
    • 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 interface IProbabilityFunction
      Returns:
      Sum of all probabilities in the function.
    • checkConstrains

      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 interface IProbabilityFunction
      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 interface IProbabilityMassFunction
      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 interface IProbabilityMassFunction
      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 interface IProbabilityMassFunction
      Returns:
      Throws:
      DomainNotNumbersException