All Packages This Package Class Hierarchy Class Search Index
java.lang.Object | +----aima.stat.rv.FiniteSampler
An abstract utility class to be subclassed by finite RV's. This class provides the basic utility functions needed by simple implementations of finite RV's where sample values are indexed by {0,1,...,n-1}.
public abstract class FiniteSampler extends java.lang.Object { // Constructors 3 public FiniteSampler(); public FiniteSampler(int); public FiniteSampler(int, double[]); // Methods 8 public int getN(); public double[] getProb(); public Random getRandomSource(); protected int indexSample(); public void normalize(); public void setN(int); public void setProb(double[]); public void setRandomSource(Random); }
public FiniteSampler()
Constructor initializing only the random source.
public FiniteSampler(int n)
Constructor initializing the random source and the number of sample values.
Parameter Description n The number of sample values.
public FiniteSampler(int n, double[] p)
Constructor initializing the random source, the number of sample values, and the distribution.
Parameter Description n The number of sample values. p[] The distribution over the sample values. p[i] = probability that indexSample()
returns i.
See Also: indexSample
public void setN(int n)
Sets the number of elements.
public int getN()
Gets the number of elements.
public void setProb(double[] p)
Sets the distribution.
public double[] getProb()
Gets the distribution.
public void setRandomSource(Random randomSource)
Sets the random source.
public Random getRandomSource()
Gets the random source.
public void normalize()
Normalizes the distribution. Does not do any error checking, possible to cause divide-by-zero.
protected int indexSample()
Returns one of {0,1,...,n-1} following the distribution. Simply walks through the distribution, and hence running time is linear in n. In theory, this could be dropped to log(n).
- Returns:
- i with probability prob[i] (0 <= i < n.)
All Packages This Package Class Hierarchy Class Search IndexFreshly brewed Java API Documentation automatically generated with polardoc Version 1.0.4