Interface Sample<T>

Type Parameters:
T - the sample type

public interface Sample<T>
Represents a sample point used for the symbolic regression task. It consists of an argument array and a result value. The sample point is comparable according its result() value.
Since:
5.0
Version:
5.0
Implementation Requirements:
The dimensionality of the sample point must be at least one, which means arity() >= 1.
  • Method Summary

    Modifier and Type
    Method
    Description
    argAt(int index)
    Return the argument value with the given index.
    int
    Return the dimensionality of the sample point arguments.
    static <T> Sample<T>
    of(T[] sample)
    Create a new sample point from the given argument and sample result.
    static Sample<Double>
    ofDouble(double... values)
    Create a new sample point from the given argument and sample result.
    static Sample<Double>
    ofDouble(double x, double y)
    Create a new sample point from the given argument and sample result.
    static Sample<Double>
    ofDouble(double x1, double x2, double y)
    Create a new sample point from the given argument and sample result.
    static Sample<Double>
    ofDouble(double x1, double x2, double x3, double y)
    Create a new sample point from the given argument and sample result.
    static List<Sample<Double>>
    Parses the given CSV string into a list of double sample points.
    Return the result of the sample point.
  • Method Details

    • arity

      int arity()
      Return the dimensionality of the sample point arguments.
      Returns:
      the arity of the sample point
    • argAt

      T argAt(int index)
      Return the argument value with the given index.
      Parameters:
      index - the argument index
      Returns:
      the argument value with the given index
      Throws:
      ArrayIndexOutOfBoundsException - if the given index is not within the given range [0, arity)
      See Also:
    • result

      Return the result of the sample point.
      Returns:
      the result of the sample point
    • of

      static <T> Sample<T> of(T[] sample)
      Create a new sample point from the given argument and sample result. It represents the function arguments with the function value: f: sample[0:sample.length-1] -> sample[sample.length-1]. The last array element contains the result, and the first n-1 elements are function arguments.
      Type Parameters:
      T - the sample type
      Parameters:
      sample - the sample point result
      Returns:
      a new sample point
      Throws:
      IllegalArgumentException - if the argument array is empty
      NullPointerException - if the argument array is null
    • ofDouble

      static Sample<Double> ofDouble(double x, double y)
      Create a new sample point from the given argument and sample result. It represents the function arguments with the function value: f: x -> y
      Parameters:
      x - the argument
      y - the sample point result
      Returns:
      a new sample point
    • ofDouble

      static Sample<Double> ofDouble(double x1, double x2, double y)
      Create a new sample point from the given argument and sample result. It represents the function arguments with the function value: f: (x1, x2) -> y
      Parameters:
      x1 - the first argument
      x2 - the second argument
      y - the sample point result
      Returns:
      a new sample point
    • ofDouble

      static Sample<Double> ofDouble(double x1, double x2, double x3, double y)
      Create a new sample point from the given argument and sample result. It represents the function arguments with the function value: f: (x1, x2, x3) -> y
      Parameters:
      x1 - the first argument
      x2 - the second argument
      x3 - the second argument
      y - the sample point result
      Returns:
      a new sample point
    • ofDouble

      static Sample<Double> ofDouble(double... values)
      Create a new sample point from the given argument and sample result. It represents the function arguments with the function value: f: (x1, x2, x3, xn-1) -> y
      Parameters:
      values - the sample data
      Returns:
      a new sample point
      Since:
      8.1
    • parseDoubles

      Parses the given CSV string into a list of double sample points. The following example shows how to create a list of sample points from a CSV string.
      static final List<Sample<Double>> SAMPLES = Sample.parseDoubles("""
           1.0, -8.0000
           0.9, -6.2460
           0.8, -4.7680
           0.7, -3.5420
           0.6, -2.5440
           0.5, -1.7500
           0.4, -1.1360
           0.3, -0.6780
           0.2, -0.3520
           0.1, -0.1340
           0.0,  0.0000
           0.1,  0.0740
           0.2,  0.1120
           0.3,  0.1380
           0.4,  0.1760
           0.5,  0.2500
           0.6,  0.3840
           0.7,  0.6020
           0.8,  0.9280
           0.9,  1.3860
           1.0,  2.0000
           """
       );
      
      Parameters:
      csv - the CSV string to parse
      Returns:
      the parsed double samples
      Since:
      8.1