Package net.sf.tweety.math.probability
Class Probability
- java.lang.Object
-
- java.lang.Number
-
- net.sf.tweety.math.probability.Probability
-
- All Implemented Interfaces:
java.io.Serializable
public class Probability extends java.lang.NumberThis class represents a probability, i.e. a double in the interval [0,1].- Author:
- Matthias Thimm
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static ProbabilityONEConstant for probability 1static doublePRECISIONThe precision for probabilities.static ProbabilityZEROConstant for probability 0
-
Constructor Summary
Constructors Constructor Description Probability(java.lang.Double value)Creates a new probability with the given valueProbability(Probability other)Creates a new probability from the given probability
-
Method Summary
Modifier and Type Method Description Probabilityadd(Probability other)Computes the sum of this and the given probability.Probabilitycomplement()Returns the complement of this probability, i.e.Probabilitydivide(java.lang.Double other)Divides this probability by given value returns the result.Probabilitydivide(Probability other)Divides this probability by other and returns the result.doubledoubleValue()booleanequals(java.lang.Object obj)floatfloatValue()java.lang.DoublegetValue()Returns the value of this probability.inthashCode()intintValue()booleanisWithinTolerance(Probability other)Checks whether the given probability is "nearly" the same as this probability (given the actual precision).longlongValue()Probabilitymult(java.lang.Double other)Computes the product of this probability and the given number.Probabilitymult(java.lang.Integer other)Computes the product of this probability and the given number.Probabilitymult(Probability other)Computes the product of this probability and the given probability.booleansample()Returns a sample wrt.java.lang.StringtoString()
-
-
-
Field Detail
-
ONE
public static final Probability ONE
Constant for probability 1
-
ZERO
public static final Probability ZERO
Constant for probability 0
-
PRECISION
public static final double PRECISION
The precision for probabilities. TODO: that should go somewhere else.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Probability
public Probability(java.lang.Double value)
Creates a new probability with the given value- Parameters:
value- a double in the interval [0,1]
-
Probability
public Probability(Probability other)
Creates a new probability from the given probability- Parameters:
other- another probability
-
-
Method Detail
-
complement
public Probability complement()
Returns the complement of this probability, i.e. a probability of one minus the value of this probability.- Returns:
- the complement of this probability.
-
add
public Probability add(Probability other)
Computes the sum of this and the given probability.- Parameters:
other- a probability.- Returns:
- a probability.
-
mult
public Probability mult(java.lang.Double other)
Computes the product of this probability and the given number.- Parameters:
other- a number.- Returns:
- a probability.
-
mult
public Probability mult(java.lang.Integer other)
Computes the product of this probability and the given number.- Parameters:
other- a number.- Returns:
- a probability.
-
mult
public Probability mult(Probability other)
Computes the product of this probability and the given probability.- Parameters:
other- a probability.- Returns:
- a probability.
-
divide
public Probability divide(Probability other)
Divides this probability by other and returns the result.- Parameters:
other- a probability.- Returns:
- a probability.
-
divide
public Probability divide(java.lang.Double other)
Divides this probability by given value returns the result.- Parameters:
other- a double value.- Returns:
- a probability.
-
isWithinTolerance
public boolean isWithinTolerance(Probability other)
Checks whether the given probability is "nearly" the same as this probability (given the actual precision).- Parameters:
other- some probability- Returns:
- "true" if the given probability is "nearly" the same as this one.
-
sample
public boolean sample()
Returns a sample wrt. this probability, i.e. with this probability the value returned is "true", otherwise "false"- Returns:
- "true" with this probability.
-
getValue
public java.lang.Double getValue()
Returns the value of this probability.- Returns:
- the value of this probability.
-
doubleValue
public double doubleValue()
- Specified by:
doubleValuein classjava.lang.Number
-
floatValue
public float floatValue()
- Specified by:
floatValuein classjava.lang.Number
-
intValue
public int intValue()
- Specified by:
intValuein classjava.lang.Number
-
longValue
public long longValue()
- Specified by:
longValuein classjava.lang.Number
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
-