# Class Probability

java.lang.Object
java.lang.Number
org.tweetyproject.math.probability.Probability
All Implemented Interfaces:
`Serializable`

public class Probability extends Number
This class represents a probability, i.e. a double in the interval [0,1].
Author:
Matthias Thimm
• ## Field Summary

Fields
Modifier and Type
Field
Description
`static final Probability`
`ONE`
Constant for probability 1
`static final double`
`PRECISION`
The precision for probabilities.
`static final Probability`
`ZERO`
Constant for probability 0
• ## Constructor Summary

Constructors
Constructor
Description
`Probability(Double value)`
Creates a new probability with the given value
`Probability(Probability other)`
Creates a new probability from the given probability
• ## Method Summary

Modifier and Type
Method
Description
`Probability`
`add(Probability other)`
Computes the sum of this and the given probability.
`Probability`
`complement()`
Returns the complement of this probability, i.e.
`Probability`
`divide(Double other)`
Divides this probability by given value returns the result.
`Probability`
`divide(Probability other)`
Divides this probability by other and returns the result.
`double`
`doubleValue()`

`boolean`
`equals(Object obj)`

`float`
`floatValue()`

`Double`
`getValue()`
Returns the value of this probability.
`int`
`hashCode()`

`int`
`intValue()`

`boolean`
`isWithinTolerance(Probability other)`
Checks whether the given probability is "nearly" the same as this probability (given the actual precision).
`long`
`longValue()`

`Probability`
`mult(Double other)`
Computes the product of this probability and the given number.
`Probability`
`mult(Integer other)`
Computes the product of this probability and the given number.
`Probability`
`mult(Probability other)`
Computes the product of this probability and the given probability.
`boolean`
`sample()`
Returns a sample wrt.
`String`
`toString()`

### Methods inherited from class java.lang.Number

`byteValue, shortValue`

### Methods inherited from class java.lang.Object

`getClass, notify, notifyAll, wait, wait, wait`
• ## Field Details

• ### 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.
• ## Constructor Details

• ### Probability

public Probability(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 Details

• ### 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.

Computes the sum of this and the given probability.
Parameters:
`other` - a probability.
Returns:
a probability.
• ### mult

public Probability mult(Double other)
Computes the product of this probability and the given number.
Parameters:
`other` - a number.
Returns:
a probability.
• ### mult

public Probability mult(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(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 Double getValue()
Returns the value of this probability.
Returns:
the value of this probability.
• ### doubleValue

public double doubleValue()
Specified by:
`doubleValue` in class `Number`
• ### floatValue

public float floatValue()
Specified by:
`floatValue` in class `Number`
• ### intValue

public int intValue()
Specified by:
`intValue` in class `Number`
• ### longValue

public long longValue()
Specified by:
`longValue` in class `Number`
• ### toString

public String toString()
Overrides:
`toString` in class `Object`
• ### hashCode

public int hashCode()
Overrides:
`hashCode` in class `Object`
• ### equals

public boolean equals(Object obj)
Overrides:
`equals` in class `Object`