Class SampleBuffer<T>

java.lang.Object
io.jenetics.prog.regression.SampleBuffer<T>
All Implemented Interfaces:
Sampling<T>

public final class SampleBuffer<T> extends Object implements Sampling<T>
This class holds the actual sample values which are used for the symbolic regression example. This class is thread-safe and can be used in a producer-consumer setup. You can add single sample values (add(Sample)) or a list (addAll(Collection)) of new values. These values will be made available for evaluation after an explicit call of the publish() method.
Since:
6.0
Version:
6.0
Implementation Note:
This class is thread-safe.
  • Constructor Details

  • Method Details

    • add

      public void add(Sample<T> sample)
      Adding a new sample point to the buffer. You need to explicitly call publish() to make it available for the eval(Tree) method.
      Parameters:
      sample - the sample point to add
      Throws:
      NullPointerException - if the given sample point is null
    • addAll

      public void addAll(Collection<? extends Sample<T>> samples)
      The the given sample points to the buffer. You need to explicitly call publish() to make it available for the eval(Tree) method.
      Parameters:
      samples - the samples to add to the buffer
      Throws:
      NullPointerException - if the given samples is null
    • publish

      public int publish()
      Making the current sample points available for the eval(Tree) function.
      Returns:
      the number of published sample points
    • eval

      public Sampling.Result<T> eval(Tree<? extends Op<T>,?> program)
      Description copied from interface: Sampling
      Evaluates the given program tree with its sample points. The returned result object may be null if no sample point has been added to the sampling when calling the eval method.
      Specified by:
      eval in interface Sampling<T>
      Parameters:
      program - the program to evaluate
      Returns:
      the evaluated sample result. May be null if the sampling is empty and contains no sample points.
    • eval

      public Sampling.Result<T> eval(Function<? super T[],? extends T> function)
      Description copied from interface: Sampling
      Evaluates the given function tree with its sample points. The returned result object may be null if no sample point has been added to the sampling when calling the eval method.
      Specified by:
      eval in interface Sampling<T>
      Parameters:
      function - the function to evaluate
      Returns:
      the evaluated sample result. May be null if the sampling is empty and contains no sample points.