etomica.data
Class AccumulatorAverageCollapsingLog

java.lang.Object
  extended by etomica.data.DataProcessor
      extended by etomica.data.DataProcessorForked
          extended by etomica.data.DataAccumulator
              extended by etomica.data.AccumulatorAverageCollapsingLog
All Implemented Interfaces:
DataPipe, DataPipeForked, DataSourceIndependent, IDataSink, IDataSource, IEtomicaDataSource, Serializable

public class AccumulatorAverageCollapsingLog
extends DataAccumulator
implements DataSourceIndependent

AccumulatorAverage that keeps track of block averages and standard deviations corresponding to all block sizes from 1 to the n where n is the largest power of 2 less than the current number of samples. In addition to block averages and standard deviations of the sampled quantity, the natural log of the block averages and standard deviation of the natural log is also calculated (this is what makes this class actually useful). getData returns the average natural log values for all block sizes as a DataFunction.

This class also uses a method to improve the block statistics for large. All block averages are kept for a particular block size (n1 blocks of size b1). Statistics for that block are computed from that data. Block averages for blocks of the next larger size (2*n1) are computed by randomly selecting n1/2 pairs of block values from the b1 set (without including any block value more than once). After using all block values, n1/2 additional pairs are taken from the full b1 set, such that n1 blocks of size b1*2 are obtained, instead of n1/2 blocks that would normally exist. Statistics for block size b1*2 are computed from these n1 blocks. This process is repeated for each block size such that the largest block size (which would normally have 1 block) has n1 blocks.

This accumulator can only operate on Data with a single value.

See Also:
Serialized Form

Field Summary
protected  DataFunction averages
           
protected  DataFunction.DataInfoFunction avgDataInfo
           
protected  double[] blockSums
           
protected  long count
           
protected  ArrayList<Integer> intArrayList
           
protected  double[][] lSums
           
protected  DataDoubleArray nData
           
protected  DataDoubleArray.DataInfoDoubleArray nDataInfo
           
protected  int nRawData
           
protected  int nRawDataDoubles
           
protected  DataTag nTag
           
protected  IRandom random
           
protected  double[] rawData
           
protected  double[] rawData2
           
protected  double[] rawData3
           
protected  int rawDataBlockSize
           
protected  DataFunction stdev
           
protected  double[][] sums
           
 
Fields inherited from class etomica.data.DataAccumulator
active, putCount
 
Fields inherited from class etomica.data.DataProcessor
dataInfo, dataSink, tag, trueDataSink
 
Constructor Summary
AccumulatorAverageCollapsingLog(IRandom random)
           
 
Method Summary
 void addData(IData data)
          Add the given values to the sums and block sums.
protected  void doSums(double[] subSums, double v)
          Performs the block sum after
protected  void ensureHappyIntArrayList()
          Refills inArrayList if it's empty.
 IData getAverageLogs()
          Returns the average natural logs of the block averages, for all block sizes.
 IData getAverages()
          Returns the averages for all block sizes
 IData getData()
          Returns the Data generated by accumulating the Data previously given to this instance.
 DataPipe getDataCaster(IEtomicaDataInfo incomingDataInfo)
          Checks that incoming Data implements Data, and returns null if this is so.
 int getIndependentArrayDimension()
          Returns the number of independent data dimensions
 DataDoubleArray getIndependentData(int i)
          Returns the X data for the given dimension
 DataDoubleArray.DataInfoDoubleArray getIndependentDataInfo(int i)
          Returns the DataInfo for the given dimension
 DataTag getIndependentTag()
          Returns the tag associated with this DataSource.
 IData getStdev()
          Returns the standard deviation of the block averages, for all block sizes.
 IData getStdevLog()
          Returns the standard deviation of the log of the block averages, for all block sizes.
static void main(String[] args)
           
 IData processData(IData inputData)
          Implementation of DataProcessor interface.
 IEtomicaDataInfo processDataInfo(IEtomicaDataInfo incomingDataInfo)
          Informs this DataProcessor of the DataInfo for the Data it will be processing.
protected  void reblockData()
          Reblock data from rawData2 into rawData3, then copy it back to rawData2
 void reset()
          Resets all sums to zero.
protected  void resizeData(int newSize)
           
 void setNumRawDataDoubles(int newNumRawDataDoubles)
          Sets the number of times the random block generation method is used.
 
Methods inherited from class etomica.data.DataAccumulator
getPushInterval, isActive, setActive, setPushInterval, toString
 
Methods inherited from class etomica.data.DataProcessorForked
addDataSink, getDataSink, getDataSinks, removeDataSink, setDataSink, setDataSinks
 
Methods inherited from class etomica.data.DataProcessor
getDataInfo, getTag, insertTransformerIfNeeded, putData, putDataInfo
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface etomica.data.IEtomicaDataSource
getDataInfo, getTag
 
Methods inherited from interface etomica.data.DataPipe
getTag
 
Methods inherited from interface etomica.data.IDataSink
putData, putDataInfo
 

Field Detail

count

protected long count

blockSums

protected double[] blockSums

sums

protected double[][] sums

lSums

protected double[][] lSums

averages

protected DataFunction averages

stdev

protected DataFunction stdev

avgDataInfo

protected DataFunction.DataInfoFunction avgDataInfo

nDataInfo

protected DataDoubleArray.DataInfoDoubleArray nDataInfo

nData

protected DataDoubleArray nData

nTag

protected final DataTag nTag

rawData

protected double[] rawData

rawData2

protected double[] rawData2

rawData3

protected double[] rawData3

nRawData

protected int nRawData

rawDataBlockSize

protected int rawDataBlockSize

nRawDataDoubles

protected int nRawDataDoubles

intArrayList

protected ArrayList<Integer> intArrayList

random

protected final IRandom random
Constructor Detail

AccumulatorAverageCollapsingLog

public AccumulatorAverageCollapsingLog(IRandom random)
Method Detail

setNumRawDataDoubles

public void setNumRawDataDoubles(int newNumRawDataDoubles)
Sets the number of times the random block generation method is used. The number of blocks used will be 2^numRawDataDoubles.


getDataCaster

public DataPipe getDataCaster(IEtomicaDataInfo incomingDataInfo)
Checks that incoming Data implements Data, and returns null if this is so. Otherwise throws a ClassCastException, as there is no data caster to Data.

Specified by:
getDataCaster in interface IDataSink
Parameters:
incomingDataInfo - the DataInfo for the Data that will fed to the sink's putData method

processData

public IData processData(IData inputData)
Description copied from class: DataAccumulator
Implementation of DataProcessor interface. Returns getData() every pushInterval times it is invoked, otherwise returns null (thereby preventing transmission of data to the next DataSinks). If isActive is false, data is not accumulated and no action is performed.

Overrides:
processData in class DataAccumulator
Parameters:
inputData - the Data for processing
Returns:
the processed Data, for sending downstream (if not null)

addData

public void addData(IData data)
Add the given values to the sums and block sums. If any of the given data values is NaN, method returns with no effect on accumulation sums.

Specified by:
addData in class DataAccumulator

resizeData

protected void resizeData(int newSize)

getData

public IData getData()
Description copied from class: DataAccumulator
Returns the Data generated by accumulating the Data previously given to this instance. Part of the DataSource interface.

Specified by:
getData in interface IDataSource
Specified by:
getData in class DataAccumulator
Returns:
the data given by this source

getAverages

public IData getAverages()
Returns the averages for all block sizes


getAverageLogs

public IData getAverageLogs()
Returns the average natural logs of the block averages, for all block sizes.


reblockData

protected void reblockData()
Reblock data from rawData2 into rawData3, then copy it back to rawData2


ensureHappyIntArrayList

protected void ensureHappyIntArrayList()
Refills inArrayList if it's empty.


getStdev

public IData getStdev()
Returns the standard deviation of the block averages, for all block sizes.


getStdevLog

public IData getStdevLog()
Returns the standard deviation of the log of the block averages, for all block sizes.


doSums

protected void doSums(double[] subSums,
                      double v)
Performs the block sum after


reset

public void reset()
Resets all sums to zero. All statistics are cleared.

Specified by:
reset in class DataAccumulator

processDataInfo

public IEtomicaDataInfo processDataInfo(IEtomicaDataInfo incomingDataInfo)
Description copied from class: DataProcessor
Informs this DataProcessor of the DataInfo for the Data it will be processing. Typically the subclass will use this information to make any objects or otherwise prepare for calls to processData.

Specified by:
processDataInfo in class DataProcessor
Returns:
the DataInfo of the Data that will be output by this DataProcessor

getIndependentArrayDimension

public int getIndependentArrayDimension()
Description copied from interface: DataSourceIndependent
Returns the number of independent data dimensions

Specified by:
getIndependentArrayDimension in interface DataSourceIndependent

getIndependentData

public DataDoubleArray getIndependentData(int i)
Description copied from interface: DataSourceIndependent
Returns the X data for the given dimension

Specified by:
getIndependentData in interface DataSourceIndependent

getIndependentDataInfo

public DataDoubleArray.DataInfoDoubleArray getIndependentDataInfo(int i)
Description copied from interface: DataSourceIndependent
Returns the DataInfo for the given dimension

Specified by:
getIndependentDataInfo in interface DataSourceIndependent

getIndependentTag

public DataTag getIndependentTag()
Description copied from interface: DataSourceIndependent
Returns the tag associated with this DataSource.

Specified by:
getIndependentTag in interface DataSourceIndependent

main

public static void main(String[] args)