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