org.omegahat.Simulation.MCMC
Class MultiDoubleState

java.lang.Object
  |
  +--org.omegahat.Simulation.MCMC.MultiState
        |
        +--org.omegahat.Simulation.MCMC.MultiDoubleState
All Implemented Interfaces:
MCMCState

public class MultiDoubleState
extends MultiState

MCMCState that can hold several Double[] states. Its purpose is to allow a multi-chain sampler to easily store and retrieve the states of individual chains.


Inner Class Summary
 class MultiDoubleState.CovAccumulator
           
 
Field Summary
 double[][] covCacheMat
           
 boolean DEBUG
           
 double[][] distanceCacheMat
           
static int Euclidean
           
static int Mahalanobis
           
 double[] maxCache
           
 double[] meanCacheVec
           
 double[] minCache
           
 double[] rangeCache
           
 MultiDoubleState.CovAccumulator[] sumSqrSubsetCache
           
 
Fields inherited from class org.omegahat.Simulation.MCMC.MultiState
attributes, contents
 
Constructor Summary
MultiDoubleState()
           
MultiDoubleState(int size)
           
MultiDoubleState(int size, double[] oneValue)
           
MultiDoubleState(int size, java.lang.Double[] oneValue)
           
MultiDoubleState(MultiState state)
          This constructor creates a new MultDoubleState by duplicating the contents of the provided MultiState, checking that each non-null component is a Double[].
 
Method Summary
static double[][] accumToVar(MultiDoubleState.CovAccumulator accum)
          Compute the covariance matrix
 void add(java.lang.Object value)
           
 double[] computeDistances(int from, int method)
           
protected  void computeMinMaxRange()
           
 MultiState copy()
          creat a new MultiState object by copying the contents of this one.
 MultiDoubleState copyFromTo(MultiDoubleState source, MultiDoubleState target)
           
 MultiDoubleState copyFromTo(MultiState source, MultiDoubleState target)
           
 double[][] correctedVar()
          This function checks if the number of component states used to estimate the covariance matrix is less than or equal to the number of dimensions.
 double[] cumsum()
           
 double[] cumsum(double[] cumsum)
          Compute accumulated sums
 MultiDoubleState.CovAccumulator cumSumSqr()
           
 MultiDoubleState.CovAccumulator cumSumSqr(MultiDoubleState.CovAccumulator retval)
           
 MultiDoubleState.CovAccumulator cumSumSqrSubset(int[] closest)
           
 MultiDoubleState.CovAccumulator cumSumSqrSubsetCache(int which, int[] closest)
           
 double[][] diagVar()
          Compute the diagonal of the covariance matrix
 double distance(int from, int to, int method)
           
 double distanceCache(int from, int to, int method)
           
 int[] findClosest(int which, int howmany, int method)
          Find closest howmany points to state which using distance method .
 Histogram[] histogram(double min, double max, int bins)
           
 Histogram[] histogram(Histogram[] hist)
           
 void invalidateCache()
           
 void invalidateCache(int index)
           
 double[] max()
           
 double[] mean()
          Compute the mean
 java.lang.Double[] Mean()
           
 double[] min()
          Compute the minimum 2-way variance vector between a specified state and the other states
 double[][] nearestNeighborDiagVar(int which, int howmany, int method)
           
 double[] nearestNeighborMean(int which, int howmany, int method)
           
 double[][] nearestNeighborVar(int which, int howmany, int method)
          Compute the (local) covariance matrix at one state using a specified number of nearest neighbors
 double[] range()
           
 void remove(int which)
           
 void set(int index, java.lang.Object value)
           
 double[][] var()
          Compute the covariance matrix
 java.lang.Double[][] Var()
          Compute the covariance matrix
 
Methods inherited from class org.omegahat.Simulation.MCMC.MultiState
attr, attr, attributeNames, copyTo, get, size, toString
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

Mahalanobis

public static final int Mahalanobis

Euclidean

public static final int Euclidean

DEBUG

public boolean DEBUG

distanceCacheMat

public double[][] distanceCacheMat

covCacheMat

public double[][] covCacheMat

meanCacheVec

public double[] meanCacheVec

sumSqrSubsetCache

public MultiDoubleState.CovAccumulator[] sumSqrSubsetCache

minCache

public double[] minCache

maxCache

public double[] maxCache

rangeCache

public double[] rangeCache
Constructor Detail

MultiDoubleState

public MultiDoubleState(int size)

MultiDoubleState

public MultiDoubleState(int size,
                        java.lang.Double[] oneValue)

MultiDoubleState

public MultiDoubleState(int size,
                        double[] oneValue)

MultiDoubleState

public MultiDoubleState()

MultiDoubleState

public MultiDoubleState(MultiState state)
This constructor creates a new MultDoubleState by duplicating the contents of the provided MultiState, checking that each non-null component is a Double[]. (If the component is a double[] convert it.)
Method Detail

invalidateCache

public void invalidateCache()

invalidateCache

public void invalidateCache(int index)

set

public void set(int index,
                java.lang.Object value)
Overrides:
set in class MultiState

add

public void add(java.lang.Object value)
Overrides:
add in class MultiState

remove

public void remove(int which)
Overrides:
remove in class MultiState

copy

public MultiState copy()
creat a new MultiState object by copying the contents of this one.
Overrides:
copy in class MultiState

copyFromTo

public MultiDoubleState copyFromTo(MultiDoubleState source,
                                   MultiDoubleState target)

copyFromTo

public MultiDoubleState copyFromTo(MultiState source,
                                   MultiDoubleState target)

nearestNeighborVar

public double[][] nearestNeighborVar(int which,
                                     int howmany,
                                     int method)
Compute the (local) covariance matrix at one state using a specified number of nearest neighbors
Parameters:
which - index of state around which covariance is computed
howmany - number of neighbors to use (Use nn=0 for all neighbors).

nearestNeighborDiagVar

public double[][] nearestNeighborDiagVar(int which,
                                         int howmany,
                                         int method)

nearestNeighborMean

public double[] nearestNeighborMean(int which,
                                    int howmany,
                                    int method)

findClosest

public int[] findClosest(int which,
                         int howmany,
                         int method)
Find closest howmany points to state which using distance method . Note that the state which will be included in the returned list as the first element.
Parameters:
which - index of state from which distances are computed.
howmany - number of points (including which) to return, must be >= 2.
method - distance method to use. 0=Mahalanobis, 1=Euclidean.

computeDistances

public double[] computeDistances(int from,
                                 int method)

distanceCache

public double distanceCache(int from,
                            int to,
                            int method)

distance

public double distance(int from,
                       int to,
                       int method)

cumSumSqrSubset

public MultiDoubleState.CovAccumulator cumSumSqrSubset(int[] closest)

cumSumSqrSubsetCache

public MultiDoubleState.CovAccumulator cumSumSqrSubsetCache(int which,
                                                            int[] closest)

min

public double[] min()
Compute the minimum 2-way variance vector between a specified state and the other states

max

public double[] max()

range

public double[] range()

computeMinMaxRange

protected void computeMinMaxRange()

cumsum

public double[] cumsum(double[] cumsum)
Compute accumulated sums

cumsum

public double[] cumsum()

mean

public double[] mean()
Compute the mean

Mean

public java.lang.Double[] Mean()

cumSumSqr

public MultiDoubleState.CovAccumulator cumSumSqr()

cumSumSqr

public MultiDoubleState.CovAccumulator cumSumSqr(MultiDoubleState.CovAccumulator retval)

diagVar

public double[][] diagVar()
Compute the diagonal of the covariance matrix

var

public double[][] var()
Compute the covariance matrix

correctedVar

public double[][] correctedVar()
This function checks if the number of component states used to estimate the covariance matrix is less than or equal to the number of dimensions. If so, it inflates the diagonal elements by 5% so that the covariance matrix will be invertible.

accumToVar

public static double[][] accumToVar(MultiDoubleState.CovAccumulator accum)
Compute the covariance matrix

Var

public java.lang.Double[][] Var()
Compute the covariance matrix

histogram

public Histogram[] histogram(Histogram[] hist)

histogram

public Histogram[] histogram(double min,
                             double max,
                             int bins)