All Packages  This Package  Class Hierarchy  Class Search  Index

Class aima.stat.rv.FiniteSampler

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);
}



Constructors


FiniteSampler

   public FiniteSampler() 

Constructor initializing only the random source.



FiniteSampler

   public FiniteSampler(int n) 

Constructor initializing the random source and the number of sample values.

Parameter Description
n The number of sample values.



FiniteSampler

   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




Methods


setN

   public void setN(int n) 

Sets the number of elements.



getN

   public int getN() 

Gets the number of elements.



setProb

   public void setProb(double[] p) 

Sets the distribution.



getProb

   public double[] getProb() 

Gets the distribution.



setRandomSource

   public void setRandomSource(Random randomSource) 

Sets the random source.



getRandomSource

   public Random getRandomSource() 

Gets the random source.



normalize

   public void normalize() 

Normalizes the distribution. Does not do any error checking, possible to cause divide-by-zero.



indexSample

   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  Index
Freshly brewed Java API Documentation automatically generated with polardoc Version 1.0.4