Class ProbabilityFunction<T extends Comparable<T>>
java.lang.Object
org.tweetyproject.math.probability.ProbabilityFunction<T>
- Type Parameters:
T- The class of the objects used.
- All Implemented Interfaces:
Map<T,Probability>
- Direct Known Subclasses:
ProbabilisticExtension,SubgraphProbabilityFunction
public class ProbabilityFunction<T extends Comparable<T>>
extends Object
implements Map<T,Probability>
This class represents a probability distribution over some set of objects
- Author:
- Matthias Thimm
-
Nested Class Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new probability function.ProbabilityFunction(ProbabilityFunction<T> other)Creates a new probability function by copying the given one. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()booleancontainsKey(Object key)booleancontainsValue(Object value)static <S extends Comparable<S>>
ProbabilityFunction<S>convexCombination(double[] factors, ProbabilityFunction<S>[] creators)Computes the convex combination of the given probability distributions P1,...,PN with parameters factors, i.e.convexCombination(double d, ProbabilityFunction<T> other)Computes the convex combination of this P1 and the given probability distribution P2 with parameter d, i.e.Set<Map.Entry<T,Probability>>entrySet()booleanReturns the vector of probabilities, depending on the order of the domain elements (which can be ordered as they implement Comparable).Returns the vector of probabilities, depending on the order of the domain elements (which can be ordered as they implement Comparable).static <S extends Comparable<S>>
ProbabilityFunction<S>getUniformDistribution(Set<S> objects)Returns the uniform distribution on the given interpretations.inthashCode()booleanisEmpty()booleanChecks whether this probability function is normalized, i.e.keySet()linearCombination(double d1, double d2, ProbabilityFunction<T> other)Makes a linear combination of this distribution "p1" and the given distribution "other" and the given parameters, i.e.voidNormalizes this probability function to have mass 1.probability(Collection<? extends T> objects)Gets the probability of the given object.probability(T w)Gets the probability of the given object.put(T key, Probability value)voidputAll(Map<? extends T,? extends Probability> m)sample()Samples one element from the domain of this probability function, depending on its probability.Samples one element from the domain of this probability function, depending on its probability.intsize()toString()values()Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
ProbabilityFunction
public ProbabilityFunction()Creates a new probability function. -
ProbabilityFunction
Creates a new probability function by copying the given one.- Parameters:
other- another probability function
-
-
Method Details
-
probability
Gets the probability of the given object.- Parameters:
w- some object.- Returns:
- the probability of the given object.
- Throws:
IllegalArgumentException- if the given object has no probability
-
probability
Gets the probability of the given object.- Parameters:
objects- some object.- Returns:
- the probability of the given object.
- Throws:
IllegalArgumentException- if the given object has no probability
-
isNormalized
public boolean isNormalized()Checks whether this probability function is normalized, i.e. the sum of all probabilities is 1.- Returns:
- "true" if this probability function is normalized.
-
normalize
public void normalize()Normalizes this probability function to have mass 1. -
convexCombination
Computes the convex combination of this P1 and the given probability distribution P2 with parameter d, i.e. it returns a P with P(i)=d P1(i) + (1-d) P2(i) for every interpretation i.- Parameters:
d- a doubleother- a probability distribution- Returns:
- the convex combination of this P1 and the given probability distribution P2 with parameter d.
- Throws:
IllegalArgumentException- if either d is not in [0,1] or this and the given probability distribution are not defined on the same set of interpretations.
-
linearCombination
public ProbabilityFunction<T> linearCombination(double d1, double d2, ProbabilityFunction<T> other)Makes a linear combination of this distribution "p1" and the given distribution "other" and the given parameters, i.e. it returns a P with P(i)=d1 P1(i) + d2 P2(i) for every interpretation i. NOTE: P is normalized after combination.- Parameters:
d1- a double.d2- a double.other- a probability distribution.- Returns:
- a probability distribution.
-
convexCombination
public static <S extends Comparable<S>> ProbabilityFunction<S> convexCombination(double[] factors, ProbabilityFunction<S>[] creators) throws IllegalArgumentExceptionComputes the convex combination of the given probability distributions P1,...,PN with parameters factors, i.e. it returns a P with P(i)=d1 P1(i) + d2 P2(i)+ ... + dN PN(i) for every object i (with d1,...,dN=factors).- Type Parameters:
S- The object class- Parameters:
factors- a vector of doubles.creators- a vector of probability distributions.- Returns:
- the convex combination of the given distributions with parameters factors.
- Throws:
IllegalArgumentException- if either the sum of factors d is not in 1, or this and the given probability distributions are not defined on the same set of objects, or the lengths of creators and factors differ.
-
getUniformDistribution
public static <S extends Comparable<S>> ProbabilityFunction<S> getUniformDistribution(Set<S> objects)Returns the uniform distribution on the given interpretations.- Type Parameters:
S- The interpretation class- Parameters:
objects- set of interpretations of type S.- Returns:
- the uniform distribution on the given interpretations.
-
sample
Samples one element from the domain of this probability function, depending on its probability.- Returns:
- a sample from this probability function.
-
sample
Samples one element from the domain of this probability function, depending on its probability.- Parameters:
random- the number generator used.- Returns:
- a sample from this probability function.
-
toString
-
clear
public void clear()- Specified by:
clearin interfaceMap<T extends Comparable<T>,Probability>
-
containsKey
- Specified by:
containsKeyin interfaceMap<T extends Comparable<T>,Probability>
-
containsValue
- Specified by:
containsValuein interfaceMap<T extends Comparable<T>,Probability>
-
entrySet
- Specified by:
entrySetin interfaceMap<T extends Comparable<T>,Probability>
-
get
- Specified by:
getin interfaceMap<T extends Comparable<T>,Probability>
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceMap<T extends Comparable<T>,Probability>
-
put
- Specified by:
putin interfaceMap<T extends Comparable<T>,Probability>
-
putAll
- Specified by:
putAllin interfaceMap<T extends Comparable<T>,Probability>
-
remove
- Specified by:
removein interfaceMap<T extends Comparable<T>,Probability>
-
size
public int size()- Specified by:
sizein interfaceMap<T extends Comparable<T>,Probability>
-
values
- Specified by:
valuesin interfaceMap<T extends Comparable<T>,Probability>
-
keySet
- Specified by:
keySetin interfaceMap<T extends Comparable<T>,Probability>
-
hashCode
public int hashCode()- Specified by:
hashCodein interfaceMap<T extends Comparable<T>,Probability>- Overrides:
hashCodein classObject
-
getProbabilityVector
Returns the vector of probabilities, depending on the order of the domain elements (which can be ordered as they implement Comparable).- Returns:
- the vector of probabilities
-
getProbabilityVectorAsDoubles
Returns the vector of probabilities, depending on the order of the domain elements (which can be ordered as they implement Comparable).- Returns:
- the vector of probabilities as doubles
-
equals
- Specified by:
equalsin interfaceMap<T extends Comparable<T>,Probability>- Overrides:
equalsin classObject
-