Class ParameterSet

java.lang.Object
org.moeaframework.analysis.parameter.ParameterSet
All Implemented Interfaces:
Iterable<Parameter<?>>

public class ParameterSet extends Object implements Iterable<Parameter<?>>
A collection of parameters along with methods to enumerate or generate samples.
  • Constructor Details

    • ParameterSet

      public ParameterSet()
      Constructs a new, empty parameter set.
    • ParameterSet

      @SafeVarargs public ParameterSet(Parameter<?>... parameters)
      Constructs a parameter set with the given parameters.
      Parameters:
      parameters - the parameters
    • ParameterSet

      public ParameterSet(Collection<? extends Parameter<?>> parameters)
      Constructs a parameter set with the given parameters.
      Parameters:
      parameters - the parameters
  • Method Details

    • size

      public int size()
      Returns the number of parameters.
      Returns:
      the number of parameters
    • get

      public Parameter<?> get(int index)
      Returns the parameter at the given index.
      Parameters:
      index - the index
      Returns:
      the parameter
      Throws:
      IndexOutOfBoundsException - if the index is out of bounds
    • get

      public Parameter<?> get(String name)
      Returns the parameter with the given name.
      Parameters:
      name - the parameter name
      Returns:
      the parameter
      Throws:
      NoSuchParameterException - if no parameter matching the name was found
    • indexOf

      public int indexOf(Parameter<?> parameter)
      Returns the index of the given parameter.
      Parameters:
      parameter - the parameter
      Returns:
      the index of the parameter
    • indexOf

      public int indexOf(String name)
      Returns the index of the parameter with the given name.
      Parameters:
      name - the parameter name
      Returns:
      the index of the parameter
    • isEnumerable

      public boolean isEnumerable()
      Returns true if this parameter set supports enumeration; false otherwise. All parameters must be EnumeratedParameter or Constant.
      Returns:
      true if this parameter set supports enumeration; false otherwise.
      See Also:
    • enumerate

      public Samples enumerate()
      Enumerates samples. This is effectively a "cross join" of each enumerated parameter, meaning every possible combination of values is generated. If k is the number of parameters and N is the number of values per enumeration, the result will contain N^k samples.
      Returns:
      the enumerated samples
      Throws:
      IllegalArgumentException - if any parameter is not enumerable or a constant
    • sample

      public Samples sample(int numberOfSamples, Sequence sequence)
      Generates samples according so some sequence. The sequence is used to generate numbers between 0.0 and 1.0, which are then converted to the parameter value by calling SampledParameter.sample(Sample, double).
      Parameters:
      numberOfSamples - the number of samples to generate
      sequence - the sequence generator
      Returns:
      the generated samples
      Throws:
      IllegalArgumentException - if any parameter is not sampled or a constant
    • iterator

      public Iterator<Parameter<?>> iterator()
      Specified by:
      iterator in interface Iterable<Parameter<?>>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • load

      public static ParameterSet load(File file) throws IOException
      Loads the parameter set. See load(Reader) for details.
      Parameters:
      file - the file
      Returns:
      the parameter set
      Throws:
      IOException - if an I/O error occurred
      InvalidParameterException - if any parameter was invalid
    • load

      public static ParameterSet load(Reader reader) throws IOException
      Loads the parameter set. Parameters can be defined in the following formats:
      
         <name> <lb> <ub>                         # Legacy format
         <name> <type> <lb> <ub>                  # Range
         <name> const <val>                       # Constant
         <name> enum <val1> <val2> ... <valN>     # Enumeration
       
      Parameters:
      reader - the reader
      Returns:
      the parameter set
      Throws:
      IOException - if an I/O error occurred
      InvalidParameterException - if any parameter was invalid
      See Also:
    • save

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

      public void save(Writer writer) throws IOException
      Writes the parameter set.
      Parameters:
      writer - the writer
      Throws:
      IOException - if an I/O error occurred