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 Summary
ConstructorDescriptionSamples
(ParameterSet parameterSet) Constructs an empty collection of samples.Samples
(ParameterSet parameterSet, Iterable<Sample> samples) Constructs an empty collection of samples.Samples
(ParameterSet parameterSet, Collection<Sample> samples) Constructs an empty collection of samples. -
Method Summary
Modifier and TypeMethodDescriptionReturns the contents of this object as aTabularData
instance, which can be used to save, print, or format the data in various ways.boolean
<T> SampledResults<T>
evaluateAll
(Function<Sample, T> function) Evaluates each sample, collecting the results in aSampledResults
.void
get
(int index) Returns the sample at the given index.That parameter set defining the parameters included in these samples.int
hashCode()
iterator()
static Samples
load
(File file, ParameterSet parameterSet) Loads the samples from a file.static Samples
load
(Reader reader, ParameterSet parameterSet) Loads the samples from a file.void
Saves the samples to a file.void
Saves the samples to a file.int
size()
Returns the number of samples.stream()
Returns aStream
of the values in this data stream.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.moeaframework.analysis.stream.DataStream
any, distinct, enumerate, filter, first, groupBy, isEmpty, keyedOn, map, measure, reduce, reduce, single, singleOrDefault, skip, sorted, sorted, values, values
Methods inherited from interface org.moeaframework.util.format.Displayable
display
Methods inherited from interface org.moeaframework.util.format.Formattable
display, display, display, save, save, save
Methods inherited from interface java.lang.Iterable
spliterator
-
Constructor Details
-
Samples
Constructs an empty collection of samples.- Parameters:
parameterSet
- the parameter set defining the parameters included in each sample
-
Samples
Constructs an empty collection of samples.- Parameters:
parameterSet
- the parameter set defining the parameters included in each samplesamples
- the collection of samples
-
Samples
Constructs an empty collection of samples.- Parameters:
parameterSet
- the parameter set defining the parameters included in each samplesamples
- the collection of samples
-
-
Method Details
-
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 interfaceDataStream<Sample>
- Returns:
- the number of samples
-
get
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
Evaluates each sample, collecting the results in aSampledResults
.- Type Parameters:
T
- the return type of the function- Parameters:
function
- the function used to evaluate each sample- Returns:
- the results
-
iterator
-
hashCode
public int hashCode() -
equals
-
asTabularData
Description copied from interface:Formattable
Returns the contents of this object as aTabularData
instance, which can be used to save, print, or format the data in various ways.- Specified by:
asTabularData
in interfaceDataStream<Sample>
- Specified by:
asTabularData
in interfaceFormattable<Sample>
- Returns:
- the
TabularData
instance
-
stream
Description copied from interface:DataStream
Returns aStream
of the values in this data stream.- Specified by:
stream
in interfaceDataStream<Sample>
- Returns:
- the stream
-
forEach
-
load
Loads the samples from a file.- Parameters:
file
- the source fileparameterSet
- the parameter set- Returns:
- the loaded samples
- Throws:
IOException
- if an I/O error occurred
-
load
Loads the samples from a file.- Parameters:
reader
- the readerparameterSet
- the parameter set- Returns:
- the loaded samples
- Throws:
IOException
- if an I/O error occurred
-
save
Saves the samples to a file.- Parameters:
file
- the destination file- Throws:
IOException
- if an I/O error occurred
-
save
Saves the samples to a file.- Parameters:
writer
- the writer- Throws:
IOException
- if an I/O error occurred
-