Class BatchCircularList

java.lang.Object
math.BatchCircularList

public class BatchCircularList extends Object

Title: Batch Circular List data structure

Description: This class provides a data structure used to collect samples with weights in batches. When data structure is full, this is managed as a circular list. Mean value is calculated and updated when a sample is inserted or removed from the list. Structure is optimized to provide O(1) access for insertion of samples, get of batches and mean calculation.

Author:
Bertoli Marco Date: 17-gen-2006 Time: 13.59.14
  • Field Details

    • batchSize

      protected int batchSize
    • maxBatches

      protected int maxBatches
    • maxSamples

      protected int maxSamples
    • samples

      protected double[] samples
    • weights

      protected double[] weights
    • count

      protected int count
    • start

      protected int start
    • discarded

      protected int discarded
    • samplesSum

      protected double samplesSum
    • weightsSum

      protected double weightsSum
    • mean

      protected double mean
  • Constructor Details

    • BatchCircularList

      public BatchCircularList(int batchSize, int maxBatches)
      Construct a new BatchCircularList.
      Parameters:
      batchSize - batch size, must be > 0
      maxBatches - maximum number of batches, must be > 0
  • Method Details

    • add

      public void add(double sample, double weight)
    • getBatchSample

      public double getBatchSample(int index)
      Returns a batch sample
      PRECONDITION: index < getNumBatches()
      Parameters:
      index - position of the sample to be retreived
      Returns:
      requested batch sample getNumBatches()
    • getBatchWeight

      public double getBatchWeight(int index)
      Returns a batch samples' weight
      PRECONDITION: index < getNumBatches()
      Parameters:
      index - position of the sample to be retreived
      Returns:
      requested batch samples' weight getNumBatches()
    • deleteFirstBatches

      public void deleteFirstBatches(int n)
      Deletes first n batches
      PRECONDITION: index < getNumBatches()
      Parameters:
      n - number of batches to be deleted getNumBatches()
    • clean

      public void clean()
      Deallocated all objects
    • getNumBatches

      public int getNumBatches()
      Gets total number of batches
      Returns:
      total number of stored batches
    • getBatchSize

      public int getBatchSize()
      Gets the size of batches
      Returns:
      size of batches
    • getDiscarded

      public int getDiscarded()
      Gets the number of discarded samples (not batches)
      Returns:
      number of discarded samples
    • getMeanValue

      public double getMeanValue()
      Gets the mean value of samples.
      Returns:
      the mean value of the samples in the array