|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.stanford.nlp.stats.Distribution<E>
public class Distribution<E>
Immutable class for representing normalized, smoothed discrete distributions
from Counters
. Smoothed counters reserve probability mass for unseen
items, so queries for the probability of unseen items will return a small
positive amount. totalCount()
should always return 1.
Field Summary | |
---|---|
protected Counter<E> |
counter
|
Method Summary | ||
---|---|---|
static
|
absolutelyDiscountedDistribution(GenericCounter<E> counter,
int numberOfKeys,
double discount)
|
|
void |
addToKeySet(E o)
Insures that object is in keyset (with possibly zero value) |
|
E |
argmax()
|
|
boolean |
containsKey(E key)
|
|
static
|
distributionFromLogisticCounter(GenericCounter<E> cntr)
Maps a counter representing the linear weights of a multiclass logistic regression model to the probabilities of each class. |
|
static
|
distributionWithDirichletPrior(GenericCounter<E> c,
Distribution<E> prior,
double weight)
Returns a Distribution that uses prior as a Dirichlet prior weighted by weight. |
|
static
|
dynamicCounterWithDirichletPrior(GenericCounter<E> c,
Distribution<E> prior,
double weight)
Like normalizedCounterWithDirichletPrior except probabilities are computed dynamically from the counter and prior instead of all at once up front. |
|
boolean |
equals(Distribution distribution)
|
|
boolean |
equals(Object o)
|
|
double |
getCount(E key)
Returns the current count for the given key, which is 0 if it hasn't been seen before. |
|
Counter<E> |
getCounter()
|
|
static
|
getDistribution(GenericCounter<E> counter)
Creates a Distribution from the given counter, ie makes an internal copy of the counter and divides all counts by the total count. |
|
static
|
getDistributionFromLogValues(GenericCounter<E> counter)
Creates a Distribution from the given counter, ie makes an internal copy of the counter and divides all counts by the total count. |
|
static
|
getDistributionFromPartiallySpecifiedCounter(Counter<E> c,
int numKeys)
Assuming that c has a total count < 1, returns a new Distribution using the counts in c as probabilities. |
|
static
|
getDistributionWithReservedMass(GenericCounter<E> counter,
double reservedMass)
|
|
int |
getNumberOfKeys()
|
|
static
|
getPerturbedDistribution(GenericCounter<E> wordCounter,
Random r)
|
|
static
|
getPerturbedUniformDistribution(Set<E> s,
Random r)
|
|
double |
getReservedMass()
|
|
static
|
getUniformDistribution(Set<E> s)
|
|
static
|
goodTuringSmoothedCounter(GenericCounter<E> counter,
int numberOfKeys)
Creates a Good-Turing smoothed Distribution from the given counter. |
|
static
|
goodTuringWithExplicitUnknown(GenericCounter<E> counter,
E UNK)
Creates a Good-Turing smoothed Distribution from the given counter without creating any reserved mass-- instead, the special object UNK in the counter is assumed to be the count of "UNSEEN" items. |
|
int |
hashCode()
|
|
Set<E> |
keySet()
|
|
static
|
laplaceSmoothedDistribution(GenericCounter<E> counter,
int numberOfKeys)
Creates an Laplace smoothed Distribution from the given counter, ie adds one count to every item, including unseen ones, and divides by the total count. |
|
static
|
laplaceSmoothedDistribution(GenericCounter<E> counter,
int numberOfKeys,
double lambda)
Creates a smoothed Distribution using Lidstone's law, ie adds lambda (typically between 0 and 1) to every item, including unseen ones, and divides by the total count. |
|
static
|
laplaceWithExplicitUnknown(GenericCounter<E> counter,
double lambda,
E UNK)
Creates a smoothed Distribution with Laplace smoothing, but assumes an explicit count of "UNKNOWN" items. |
|
static void |
main(String[] args)
For internal testing purposes only. |
|
double |
probabilityOf(E key)
Returns the normalized count of the given object. |
|
E |
sampleFrom()
Returns an object sampled from the distribution. |
|
String |
toString()
|
|
String |
toString(NumberFormat nf)
|
|
double |
totalCount()
|
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected Counter<E> counter
Method Detail |
---|
public Counter<E> getCounter()
public String toString(NumberFormat nf)
public double getReservedMass()
public int getNumberOfKeys()
public Set<E> keySet()
public boolean containsKey(E key)
public double getCount(E key)
get
that casts
and extracts the primitive value.
public static <E> Distribution<E> getDistributionFromPartiallySpecifiedCounter(Counter<E> c, int numKeys)
public static <E> Distribution<E> getUniformDistribution(Set<E> s)
s
- a Set of keys.
public static <E> Distribution<E> getPerturbedUniformDistribution(Set<E> s, Random r)
s
- a Set of keys.
public static <E> Distribution<E> getPerturbedDistribution(GenericCounter<E> wordCounter, Random r)
public static <E> Distribution<E> getDistribution(GenericCounter<E> counter)
counter
-
public static <E> Distribution<E> getDistributionWithReservedMass(GenericCounter<E> counter, double reservedMass)
public static <E> Distribution<E> getDistributionFromLogValues(GenericCounter<E> counter)
counter
-
public static <E> Distribution<E> absolutelyDiscountedDistribution(GenericCounter<E> counter, int numberOfKeys, double discount)
public static <E> Distribution<E> laplaceSmoothedDistribution(GenericCounter<E> counter, int numberOfKeys)
counter
- numberOfKeys
-
public static <E> Distribution<E> laplaceSmoothedDistribution(GenericCounter<E> counter, int numberOfKeys, double lambda)
counter
- numberOfKeys
- lambda
-
public static <E> Distribution<E> laplaceWithExplicitUnknown(GenericCounter<E> counter, double lambda, E UNK)
counter
- the counter to normalizelambda
- the value to add to each countUNK
- the UNKNOWN symbol
public static <E> Distribution<E> goodTuringSmoothedCounter(GenericCounter<E> counter, int numberOfKeys)
counter
- numberOfKeys
-
public static <E> Distribution<E> goodTuringWithExplicitUnknown(GenericCounter<E> counter, E UNK)
counter
- the counterUNK
- the unknown symbol
public static <E> Distribution<E> distributionWithDirichletPrior(GenericCounter<E> c, Distribution<E> prior, double weight)
c
- prior
- weight
- multiplier of prior to get "pseudo-count"
public static <E> Distribution<E> dynamicCounterWithDirichletPrior(GenericCounter<E> c, Distribution<E> prior, double weight)
c
- prior
- weight
- multiplier of prior to get "pseudo-count"
public static <E> Distribution<E> distributionFromLogisticCounter(GenericCounter<E> cntr)
public E sampleFrom()
public double probabilityOf(E key)
key
-
public E argmax()
public double totalCount()
public void addToKeySet(E o)
o
- object to put in keysetpublic boolean equals(Object o)
equals
in class Object
public boolean equals(Distribution distribution)
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
public static void main(String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |