Class Samples

java.lang.Object
org.moeaframework.analysis.sample.Samples
All Implemented Interfaces:
Iterable<Sample>, DataStream<Sample>, Displayable, Formattable<Sample>

public class Samples extends Object implements Iterable<Sample>, Formattable<Sample>, DataStream<Sample>
A collection of samples, typically associated with a parameter set that generated the samples.

Samples can be stored in a file using the save(File) and load(File, ParameterSet) methods. The file begins with a header line listing the parameter names. Then, each sample is written on its own line, with the parameter values separated by whitespace. The ordering of parameters must match the provided ParameterSet.

  • Constructor Details

    • Samples

      public Samples(ParameterSet parameterSet)
      Constructs an empty collection of samples.
      Parameters:
      parameterSet - the parameter set defining the parameters included in each sample
    • Samples

      public Samples(ParameterSet parameterSet, Collection<Sample> samples)
      Constructs an empty collection of samples.
      Parameters:
      parameterSet - the parameter set defining the parameters included in each sample
      samples - the collection of samples
    • Samples

      public Samples(ParameterSet parameterSet, Iterable<Sample> samples)
      Constructs an empty collection of samples.
      Parameters:
      parameterSet - the parameter set defining the parameters included in each sample
      samples - the collection of samples
  • Method Details

    • getParameterSet

      public ParameterSet getParameterSet()
      That parameter set defining the parameters included in these samples.
      Returns:
      the parameter set
    • size

      public int size()
      Returns the number of samples.
      Specified by:
      size in interface DataStream<Sample>
      Returns:
      the number of samples
    • get

      public Sample get(int index)
      Returns the sample at the given index.
      Parameters:
      index - the index of the sample
      Returns:
      the sample at the given index
      Throws:
      IndexOutOfBoundsException - if the index is out of bounds
    • evaluateAll

      public <T> SampledResults<T> evaluateAll(Function<Sample,T> function)
      Evaluates each sample, collecting the results in a SampledResults.
      Type Parameters:
      T - the return type of the function
      Parameters:
      function - the function used to evaluate each sample
      Returns:
      the results
    • iterator

      public Iterator<Sample> iterator()
      Specified by:
      iterator in interface Iterable<Sample>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • asTabularData

      public TabularData<Sample> asTabularData()
      Description copied from interface: Formattable
      Returns the contents of this object as a TabularData instance, which can be used to save, print, or format the data in various ways.
      Specified by:
      asTabularData in interface DataStream<Sample>
      Specified by:
      asTabularData in interface Formattable<Sample>
      Returns:
      the TabularData instance
    • stream

      public Stream<Sample> stream()
      Description copied from interface: DataStream
      Returns a Stream of the values in this data stream.
      Specified by:
      stream in interface DataStream<Sample>
      Returns:
      the stream
    • forEach

      public void forEach(Consumer<? super Sample> consumer)
      Specified by:
      forEach in interface Iterable<Sample>
    • load

      public static Samples load(File file, ParameterSet parameterSet) throws IOException
      Loads the samples from a file.
      Parameters:
      file - the source file
      parameterSet - the parameter set
      Returns:
      the loaded samples
      Throws:
      IOException - if an I/O error occurred
    • load

      public static Samples load(Reader reader, ParameterSet parameterSet) throws IOException
      Loads the samples from a file.
      Parameters:
      reader - the reader
      parameterSet - the parameter set
      Returns:
      the loaded samples
      Throws:
      IOException - if an I/O error occurred
    • save

      public void save(File file) throws IOException
      Saves the samples to a file.
      Parameters:
      file - the destination file
      Throws:
      IOException - if an I/O error occurred
    • save

      public void save(Writer writer) throws IOException
      Saves the samples to a file.
      Parameters:
      writer - the writer
      Throws:
      IOException - if an I/O error occurred