T
- The class of the objects used.public class ProbabilityFunction<T extends java.lang.Comparable<T>> extends java.lang.Object implements java.util.Map<T,Probability>
Modifier and Type | Field and Description |
---|---|
private java.util.Map<T,Probability> |
probabilities
The probabilities of the objects.
|
private static java.util.Random |
random
For random sampling.
|
Constructor and Description |
---|
ProbabilityFunction()
Creates a new probability function.
|
ProbabilityFunction(ProbabilityFunction<T> other)
Creates a new probability function by copying the given one.
|
Modifier and Type | Method and Description |
---|---|
void |
clear() |
boolean |
containsKey(java.lang.Object key) |
boolean |
containsValue(java.lang.Object value) |
static <S extends java.lang.Comparable<S>> |
convexCombination(double[] factors,
ProbabilityFunction<S>[] creators)
Computes the convex combination of the
given probability distributions P1,...,PN with parameters factors, i.e.
|
ProbabilityFunction<T> |
convexCombination(double d,
ProbabilityFunction<T> other)
Computes the convex combination of this P1 and the
given probability distribution P2 with parameter d, i.e.
|
java.util.Set<java.util.Map.Entry<T,Probability>> |
entrySet() |
boolean |
equals(java.lang.Object obj) |
Probability |
get(java.lang.Object key) |
java.util.Vector<Probability> |
getProbabilityVector()
Returns the vector of probabilities, depending on the order
of the domain elements (which can be ordered as they
implement Comparable).
|
java.util.Vector<java.lang.Double> |
getProbabilityVectorAsDoubles()
Returns the vector of probabilities, depending on the order
of the domain elements (which can be ordered as they
implement Comparable).
|
static <S extends java.lang.Comparable<S>> |
getUniformDistribution(java.util.Set<S> objects)
Returns the uniform distribution on the given interpretations.
|
int |
hashCode() |
boolean |
isEmpty() |
boolean |
isNormalized()
Checks whether this probability function is normalized, i.e.
|
java.util.Set<T> |
keySet() |
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.
|
void |
normalize()
Normalizes this probability function to have mass 1.
|
protected static void |
normalize(java.util.List<java.lang.Double> probabilities)
Normalizes the given list of probabilities, i.e.
|
Probability |
probability(java.util.Collection<? extends T> objects)
Gets the probability of the given object.
|
Probability |
probability(T w)
Gets the probability of the given object.
|
Probability |
put(T key,
Probability value) |
void |
putAll(java.util.Map<? extends T,? extends Probability> m) |
Probability |
remove(java.lang.Object key) |
T |
sample()
Samples one element from the domain of this
probability function, depending on its probability.
|
T |
sample(java.util.Random random)
Samples one element from the domain of this
probability function, depending on its probability.
|
int |
size() |
java.lang.String |
toString() |
java.util.Collection<Probability> |
values() |
private static java.util.Random random
private java.util.Map<T extends java.lang.Comparable<T>,Probability> probabilities
public ProbabilityFunction()
public ProbabilityFunction(ProbabilityFunction<T> other)
public Probability probability(T w) throws java.lang.IllegalArgumentException
w
- some object.java.lang.IllegalArgumentException
public Probability probability(java.util.Collection<? extends T> objects) throws java.lang.IllegalArgumentException
objects
- some object.java.lang.IllegalArgumentException
protected static void normalize(java.util.List<java.lang.Double> probabilities)
public boolean isNormalized()
public void normalize()
public ProbabilityFunction<T> convexCombination(double d, ProbabilityFunction<T> other)
d
- a doubleother
- a probability distributionjava.lang.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.public ProbabilityFunction<T> linearCombination(double d1, double d2, ProbabilityFunction<T> other)
d1
- a double.d2
- a double.other
- a probability distribution.public static <S extends java.lang.Comparable<S>> ProbabilityFunction<S> convexCombination(double[] factors, ProbabilityFunction<S>[] creators) throws java.lang.IllegalArgumentException
S
- The object classfactors
- a vector of doubles.creators
- a vector of probability distributions.java.lang.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.public static <S extends java.lang.Comparable<S>> ProbabilityFunction<S> getUniformDistribution(java.util.Set<S> objects)
S
- The interpretation classobjects
- set of interpretations of type S.public T sample()
public T sample(java.util.Random random)
random
- the number generator used.public java.lang.String toString()
toString
in class java.lang.Object
public void clear()
clear
in interface java.util.Map<T extends java.lang.Comparable<T>,Probability>
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map<T extends java.lang.Comparable<T>,Probability>
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map<T extends java.lang.Comparable<T>,Probability>
public java.util.Set<java.util.Map.Entry<T,Probability>> entrySet()
entrySet
in interface java.util.Map<T extends java.lang.Comparable<T>,Probability>
public Probability get(java.lang.Object key)
get
in interface java.util.Map<T extends java.lang.Comparable<T>,Probability>
public boolean isEmpty()
isEmpty
in interface java.util.Map<T extends java.lang.Comparable<T>,Probability>
public Probability put(T key, Probability value)
put
in interface java.util.Map<T extends java.lang.Comparable<T>,Probability>
public void putAll(java.util.Map<? extends T,? extends Probability> m)
putAll
in interface java.util.Map<T extends java.lang.Comparable<T>,Probability>
public Probability remove(java.lang.Object key)
remove
in interface java.util.Map<T extends java.lang.Comparable<T>,Probability>
public int size()
size
in interface java.util.Map<T extends java.lang.Comparable<T>,Probability>
public java.util.Collection<Probability> values()
values
in interface java.util.Map<T extends java.lang.Comparable<T>,Probability>
public java.util.Set<T> keySet()
keySet
in interface java.util.Map<T extends java.lang.Comparable<T>,Probability>
public int hashCode()
hashCode
in interface java.util.Map<T extends java.lang.Comparable<T>,Probability>
hashCode
in class java.lang.Object
public java.util.Vector<Probability> getProbabilityVector()
public java.util.Vector<java.lang.Double> getProbabilityVectorAsDoubles()
public boolean equals(java.lang.Object obj)
equals
in interface java.util.Map<T extends java.lang.Comparable<T>,Probability>
equals
in class java.lang.Object