Class Expression

All Implemented Interfaces:
Serializable, OptionHandler, Randomizable, RevisionHandler

public class Expression extends MexicanHat
A data generator for generating y according to a given expression out of randomly generated x.
E.g., the mexican hat can be generated like this:
sin(abs(a1)) / abs(a1)
In addition to this function, the amplitude can be changed and gaussian noise can be added.

Valid options are:

 -h
  Prints this help.
 
 -o <file>
  The name of the output file, otherwise the generated data is
  printed to stdout.
 
 -r <name>
  The name of the relation.
 
 -d
  Whether to print debug informations.
 
 -S
  The seed for random function (default 1)
 
 -n <num>
  The number of examples to generate (default 100)
 
 -A <num>
  The amplitude multiplier (default 1.0).
 
 -R <num>..<num>
  The range x is randomly drawn from (default -10.0..10.0).
 
 -N <num>
  The noise rate (default 0.0).
 
 -V <num>
  The noise variance (default 1.0).
 
 -E <expression>
  The expression to use for generating y out of x 
  (default sin(abs(a1)) / abs(a1)).
 
Version:
$Revision: 11504 $
Author:
FracPete (fracpete at waikato dot ac dot nz)
See Also:
  • Constructor Details

    • Expression

      public Expression()
      initializes the generator
  • Method Details

    • globalInfo

      public String globalInfo()
      Returns a string describing this data generator.
      Overrides:
      globalInfo in class MexicanHat
      Returns:
      a description of the data generator suitable for displaying in the explorer/experimenter gui
    • listOptions

      public Enumeration<Option> listOptions()
      Returns an enumeration describing the available options.
      Specified by:
      listOptions in interface OptionHandler
      Overrides:
      listOptions in class MexicanHat
      Returns:
      an enumeration of all the available options
    • setOptions

      public void setOptions(String[] options) throws Exception
      Parses a list of options for this object.

      Valid options are:

       -h
        Prints this help.
       
       -o <file>
        The name of the output file, otherwise the generated data is
        printed to stdout.
       
       -r <name>
        The name of the relation.
       
       -d
        Whether to print debug informations.
       
       -S
        The seed for random function (default 1)
       
       -n <num>
        The number of examples to generate (default 100)
       
       -A <num>
        The amplitude multiplier (default 1.0).
       
       -R <num>..<num>
        The range x is randomly drawn from (default -10.0..10.0).
       
       -N <num>
        The noise rate (default 0.0).
       
       -V <num>
        The noise variance (default 1.0).
       
       -E <expression>
        The expression to use for generating y out of x 
        (default sin(abs(a1)) / abs(a1)).
       
      Specified by:
      setOptions in interface OptionHandler
      Overrides:
      setOptions in class MexicanHat
      Parameters:
      options - the list of options as an array of strings
      Throws:
      Exception - if an option is not supported
    • getOptions

      public String[] getOptions()
      Gets the current settings of the datagenerator BIRCHCluster.
      Specified by:
      getOptions in interface OptionHandler
      Overrides:
      getOptions in class MexicanHat
      Returns:
      an array of strings suitable for passing to setOptions
      See Also:
      • DataGenerator.removeBlacklist(String[])
    • amplitudeTipText

      public String amplitudeTipText()
      Returns the tip text for this property
      Overrides:
      amplitudeTipText in class MexicanHat
      Returns:
      tip text for this property suitable for displaying in the explorer/experimenter gui
    • getExpression

      public String getExpression()
      Gets the mathematical expression for generating y out of x
      Returns:
      the expression for computing y
    • setExpression

      public void setExpression(String value)
      Sets the mathematical expression to generate y out of x.
      Parameters:
      value - the expression for computing y
    • expressionTipText

      public String expressionTipText()
      Returns the tip text for this property
      Returns:
      tip text for this property suitable for displaying in the explorer/experimenter gui
    • getSingleModeFlag

      public boolean getSingleModeFlag() throws Exception
      Return if single mode is set for the given data generator mode depends on option setting and or generator type.
      Overrides:
      getSingleModeFlag in class MexicanHat
      Returns:
      single mode flag
      Throws:
      Exception - if mode is not set yet
    • defineDataFormat

      public Instances defineDataFormat() throws Exception
      Initializes the format for the dataset produced. Must be called before the generateExample or generateExamples methods are used. Re-initializes the random number generator with the given seed.
      Overrides:
      defineDataFormat in class MexicanHat
      Returns:
      the format for the dataset
      Throws:
      Exception - if the generating of the format failed
      See Also:
    • generateExample

      public Instance generateExample() throws Exception
      Generates one example of the dataset.
      Overrides:
      generateExample in class MexicanHat
      Returns:
      the generated example
      Throws:
      Exception - if the format of the dataset is not yet defined
      Exception - if the generator only works with generateExamples which means in non single mode
    • generateExamples

      public Instances generateExamples() throws Exception
      Generates all examples of the dataset. Re-initializes the random number generator with the given seed, before generating instances.
      Overrides:
      generateExamples in class MexicanHat
      Returns:
      the generated dataset
      Throws:
      Exception - if the format of the dataset is not yet defined
      Exception - if the generator only works with generateExample, which means in single mode
      See Also:
    • generateStart

      public String generateStart()
      Generates a comment string that documentates the data generator. By default this string is added at the beginning of the produced output as ARFF file type, next after the options.
      Overrides:
      generateStart in class MexicanHat
      Returns:
      string contains info about the generated rules
    • generateFinished

      public String generateFinished() throws Exception
      Generates a comment string that documentats the data generator. By default this string is added at the end of theproduces output as ARFF file type.
      Overrides:
      generateFinished in class MexicanHat
      Returns:
      string contains info about the generated rules
      Throws:
      Exception - if the generating of the documentaion fails
    • getRevision

      public String getRevision()
      Returns the revision string.
      Specified by:
      getRevision in interface RevisionHandler
      Overrides:
      getRevision in class MexicanHat
      Returns:
      the revision
    • main

      public static void main(String[] args)
      Main method for testing this class.
      Parameters:
      args - should contain arguments for the data producer: