Package craterdog.primitives
Class Probability
- All Implemented Interfaces:
Atomic<Probability>
,Comparable<Probability>
This class implements a mathematical probability as a primitive type. The allowed values
are double precision floating point numbers in the range [0.0..1.0]. Instances of this
class are immutable.
- Author:
- Derk Norton
-
Constructor Summary
ConstructorsConstructorDescriptionThis constructor creates a new instance of a probability with a random value between [0.0..1.0).Probability(double value)
This constructor creates a new instance of a probability with the specified value.Probability(String string)
This constructor creates a new instance of a probability with the specified value. -
Method Summary
Modifier and TypeMethodDescriptionstatic Probability
and(Probability probability1, Probability probability2)
This function returns the logical conjunction of the specified probabilities.static boolean
coinToss(Probability probability)
This function returns the result of a coin toss that is weighted with the specified probability.int
compareTo(Probability probability)
boolean
int
hashCode()
static Probability
not(Probability probability)
This function returns the logical inverse of the specified probability.static Probability
or(Probability probability1, Probability probability2)
This function returns the logical disjunction of the specified probabilities.static Probability
sans(Probability probability1, Probability probability2)
This function returns the material nonimplication of the specified probabilities.boolean
This method converts this probability into a boolean value.double
toDouble()
This method converts this probability into a double value.toString()
static Probability
xor(Probability probability1, Probability probability2)
This function returns the logical exclusive disjunction of the specified probabilities.
-
Constructor Details
-
Probability
public Probability()This constructor creates a new instance of a probability with a random value between [0.0..1.0). Notice that the random value can never be 1.0. -
Probability
public Probability(double value)This constructor creates a new instance of a probability with the specified value.- Parameters:
value
- The value of the new probability [0.0..1.0].
-
Probability
This constructor creates a new instance of a probability with the specified value.- Parameters:
string
- The string value of the new probability [0.0..1.0].
-
-
Method Details
-
toString
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Probability>
- Overrides:
compareTo
in classPrimitive<Probability>
-
equals
- Overrides:
equals
in classPrimitive<Probability>
-
hashCode
public int hashCode()- Overrides:
hashCode
in classPrimitive<Probability>
-
toBoolean
public boolean toBoolean()This method converts this probability into a boolean value. If the value is greater than 0.5 then the result is true, and false otherwise.- Returns:
- The boolean value of this probability.
-
toDouble
public double toDouble()This method converts this probability into a double value.- Returns:
- The double value of this probability.
-
coinToss
This function returns the result of a coin toss that is weighted with the specified probability. A probability of zero will always return false and a probability of one will always return true.- Parameters:
probability
- The probability of the weighted coin.- Returns:
- The result of the coin toss.
-
not
This function returns the logical inverse of the specified probability. The value of the logical inverse of a probability is 1.0 - P.- Parameters:
probability
- The probability whose inverse is being determined.- Returns:
- The logical inverse of the probability.
-
and
This function returns the logical conjunction of the specified probabilities. The value of the logical conjunction of two probabilities is P * Q.- Parameters:
probability1
- The first probability.probability2
- The second probability.- Returns:
- The logical conjunction of the two probabilities.
-
sans
This function returns the material nonimplication of the specified probabilities. The value of the material nonimplication of two probabilities is P and not(Q).- Parameters:
probability1
- The first probability.probability2
- The second probability.- Returns:
- The material nonimplication of the two probabilities.
-
or
This function returns the logical disjunction of the specified probabilities. The value of the logical disjunction of two probabilities is P + Q - and(P, Q).- Parameters:
probability1
- The first probability.probability2
- The second probability.- Returns:
- The logical disjunction of the two probabilities.
-
xor
This function returns the logical exclusive disjunction of the specified probabilities. The value of the logical exclusive disjunction of two probabilities is sans(P, Q) + sans(Q, P).- Parameters:
probability1
- The first probability.probability2
- The second probability.- Returns:
- The logical exclusive disjunction of the two probabilities.
-