## org.apache.mahout.math.random
Class Multinomial<T>

    java.lang.Object
      org.apache.mahout.math.random.Multinomial<T>

All Implemented Interfaces:
  Iterable<T>, Sampler<T>

    public final class Multinomial<T>

extends Object
implements Sampler<T>, Iterable<T>

Multinomial sampler that allows updates to element probabilities. The basic idea is that sampling is done by using a simple balanced tree. Probabilities are kept in the tree so that we can navigate to any leaf in log N time. Updates are simple because we can just propagate them upwards.

In order to facilitate access by value, we maintain an additional map from value to tree node.

Constructor Summary
`Multinomial()`
`Multinomial(Iterable<WeightedThing<T>> things)`
`Multinomial(com.google.common.collect.Multiset<T> counts)`

Method Summary
`void` `add(T value, double w)`
`void` `delete(T value)`
`double` `getProbability(T value)`
`double` `getWeight()`
`double` `getWeight(T value)`
`Iterator<T>` `iterator()`
`T` `sample()`
`T` `sample(double u)`
`void` `set(T value, double newP)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### Multinomial

    public Multinomial()

### Multinomial

    public Multinomial(com.google.common.collect.Multiset<T> counts)

### Multinomial

    public Multinomial(Iterable<WeightedThing<T>> things)

Method Detail

### add

    public void add(T value,
                    double w)

### getWeight

    public double getWeight(T value)

### getProbability

    public double getProbability(T value)

### getWeight

    public double getWeight()

### delete

    public void delete(T value)

### set

    public void set(T value,
                    double newP)

### sample

    public T sample()

  Specified by:
    `sample` in interface `Sampler<T>`

### sample

    public T sample(double u)

### iterator

    public Iterator<T> iterator()

  Specified by:
    `iterator` in interface `Iterable<T>`

Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.