CrossValidationResultProducer.java
Upload User: rhdiban
Upload Date: 2013-08-09
Package Size: 15085k
Code Size: 22k
Category:

Windows Develop

Development Platform:

Java

  1. /*
  2.  *    This program is free software; you can redistribute it and/or modify
  3.  *    it under the terms of the GNU General Public License as published by
  4.  *    the Free Software Foundation; either version 2 of the License, or
  5.  *    (at your option) any later version.
  6.  *
  7.  *    This program is distributed in the hope that it will be useful,
  8.  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.  *    GNU General Public License for more details.
  11.  *
  12.  *    You should have received a copy of the GNU General Public License
  13.  *    along with this program; if not, write to the Free Software
  14.  *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15.  */
  16. /*
  17.  *    CrossValidationResultProducer.java
  18.  *    Copyright (C) 1999 Len Trigg
  19.  *
  20.  */
  21. package weka.experiment;
  22. import java.util.Enumeration;
  23. import java.util.Calendar;
  24. import java.util.TimeZone;
  25. import java.util.Random;
  26. import java.util.Vector;
  27. import java.io.File;
  28. import weka.core.Instances;
  29. import weka.core.OptionHandler;
  30. import weka.core.Option;
  31. import weka.core.Utils;
  32. import weka.core.AdditionalMeasureProducer;
  33. /**
  34.  * Generates for each run, carries out an n-fold cross-validation,
  35.  * using the set SplitEvaluator to generate some results. If the class
  36.  * attribute is nominal, the dataset is stratified. Results for each fold
  37.  * are generated, so you may wish to use this in addition with an
  38.  * AveragingResultProducer to obtain averages for each run.
  39.  *
  40.  * @author Len Trigg (trigg@cs.waikato.ac.nz)
  41.  * @version $Revision: 1.11 $
  42.  */
  43. public class CrossValidationResultProducer 
  44.   implements ResultProducer, OptionHandler, AdditionalMeasureProducer {
  45.   
  46.   /** The dataset of interest */
  47.   protected Instances m_Instances;
  48.   /** The ResultListener to send results to */
  49.   protected ResultListener m_ResultListener = new CSVResultListener();
  50.   /** The number of folds in the cross-validation */
  51.   protected int m_NumFolds = 10;
  52.   /** Save raw output of split evaluators --- for debugging purposes */
  53.   protected boolean m_debugOutput = false;
  54.   /** The output zipper to use for saving raw splitEvaluator output */
  55.   protected OutputZipper m_ZipDest = null;
  56.   /** The destination output file/directory for raw output */
  57.   protected File m_OutputFile = new File(
  58. new File(System.getProperty("user.dir")), 
  59. "splitEvalutorOut.zip");
  60.   /** The SplitEvaluator used to generate results */
  61.   protected SplitEvaluator m_SplitEvaluator = new ClassifierSplitEvaluator();
  62.   /** The names of any additional measures to look for in SplitEvaluators */
  63.   protected String [] m_AdditionalMeasures = null;
  64.   /* The name of the key field containing the dataset name */
  65.   public static String DATASET_FIELD_NAME = "Dataset";
  66.   /* The name of the key field containing the run number */
  67.   public static String RUN_FIELD_NAME = "Run";
  68.   /* The name of the key field containing the fold number */
  69.   public static String FOLD_FIELD_NAME = "Fold";
  70.   /* The name of the result field containing the timestamp */
  71.   public static String TIMESTAMP_FIELD_NAME = "Date_time";
  72.   /**
  73.    * Returns a string describing this result producer
  74.    * @return a description of the result producer suitable for
  75.    * displaying in the explorer/experimenter gui
  76.    */
  77.   public String globalInfo() {
  78.     return "Performs a cross validation run using a supplied "
  79.       +"evaluator.";
  80.   }
  81.   /**
  82.    * Sets the dataset that results will be obtained for.
  83.    *
  84.    * @param instances a value of type 'Instances'.
  85.    */
  86.   public void setInstances(Instances instances) {
  87.     
  88.     m_Instances = instances;
  89.   }
  90.   /**
  91.    * Sets the object to send results of each run to.
  92.    *
  93.    * @param listener a value of type 'ResultListener'
  94.    */
  95.   public void setResultListener(ResultListener listener) {
  96.     m_ResultListener = listener;
  97.   }
  98.   /**
  99.    * Set a list of method names for additional measures to look for
  100.    * in SplitEvaluators. This could contain many measures (of which only a
  101.    * subset may be produceable by the current SplitEvaluator) if an experiment
  102.    * is the type that iterates over a set of properties.
  103.    * @param additionalMeasures an array of measure names, null if none
  104.    */
  105.   public void setAdditionalMeasures(String [] additionalMeasures) {
  106.     m_AdditionalMeasures = additionalMeasures;
  107.     if (m_SplitEvaluator != null) {
  108.       System.err.println("CrossValidationResultProducer: setting additional "
  109.  +"measures for "
  110.  +"split evaluator");
  111.       m_SplitEvaluator.setAdditionalMeasures(m_AdditionalMeasures);
  112.     }
  113.   }
  114.   /**
  115.    * Returns an enumeration of any additional measure names that might be
  116.    * in the SplitEvaluator
  117.    * @return an enumeration of the measure names
  118.    */
  119.   public Enumeration enumerateMeasures() {
  120.     Vector newVector = new Vector();
  121.     if (m_SplitEvaluator instanceof AdditionalMeasureProducer) {
  122.       Enumeration en = ((AdditionalMeasureProducer)m_SplitEvaluator).
  123. enumerateMeasures();
  124.       while (en.hasMoreElements()) {
  125. String mname = (String)en.nextElement();
  126. newVector.addElement(mname);
  127.       }
  128.     }
  129.     return newVector.elements();
  130.   }
  131.   
  132.   /**
  133.    * Returns the value of the named measure
  134.    * @param measureName the name of the measure to query for its value
  135.    * @return the value of the named measure
  136.    * @exception IllegalArgumentException if the named measure is not supported
  137.    */
  138.   public double getMeasure(String additionalMeasureName) {
  139.     if (m_SplitEvaluator instanceof AdditionalMeasureProducer) {
  140.       return ((AdditionalMeasureProducer)m_SplitEvaluator).
  141. getMeasure(additionalMeasureName);
  142.     } else {
  143.       throw new IllegalArgumentException("CrossValidationResultProducer: "
  144.   +"Can't return value for : "+additionalMeasureName
  145.   +". "+m_SplitEvaluator.getClass().getName()+" "
  146.   +"is not an AdditionalMeasureProducer");
  147.     }
  148.   }
  149.   
  150.   /**
  151.    * Gets a Double representing the current date and time.
  152.    * eg: 1:46pm on 20/5/1999 -> 19990520.1346
  153.    *
  154.    * @return a value of type Double
  155.    */
  156.   public static Double getTimestamp() {
  157.     Calendar now = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
  158.     double timestamp = now.get(Calendar.YEAR) * 10000
  159.       + (now.get(Calendar.MONTH) + 1) * 100
  160.       + now.get(Calendar.DAY_OF_MONTH)
  161.       + now.get(Calendar.HOUR_OF_DAY) / 100.0
  162.       + now.get(Calendar.MINUTE) / 10000.0;
  163.     return new Double(timestamp);
  164.   }
  165.   
  166.   /**
  167.    * Prepare to generate results.
  168.    *
  169.    * @exception Exception if an error occurs during preprocessing.
  170.    */
  171.   public void preProcess() throws Exception {
  172.     if (m_SplitEvaluator == null) {
  173.       throw new Exception("No SplitEvalutor set");
  174.     }
  175.     if (m_ResultListener == null) {
  176.       throw new Exception("No ResultListener set");
  177.     }
  178.     m_ResultListener.preProcess(this);
  179.   }
  180.   
  181.   /**
  182.    * Perform any postprocessing. When this method is called, it indicates
  183.    * that no more requests to generate results for the current experiment
  184.    * will be sent.
  185.    *
  186.    * @exception Exception if an error occurs
  187.    */
  188.   public void postProcess() throws Exception {
  189.     m_ResultListener.postProcess(this);
  190.     if (m_debugOutput) {
  191.       if (m_ZipDest != null) {
  192. m_ZipDest.finished();
  193. m_ZipDest = null;
  194.       }
  195.     }
  196.   }
  197.   
  198.   /**
  199.    * Gets the keys for a specified run number. Different run
  200.    * numbers correspond to different randomizations of the data. Keys
  201.    * produced should be sent to the current ResultListener
  202.    *
  203.    * @param run the run number to get keys for.
  204.    * @exception Exception if a problem occurs while getting the keys
  205.    */
  206.   public void doRunKeys(int run) throws Exception {
  207.     if (m_Instances == null) {
  208.       throw new Exception("No Instances set");
  209.     }
  210.     /*    // Randomize on a copy of the original dataset
  211.     Instances runInstances = new Instances(m_Instances);
  212.     runInstances.randomize(new Random(run));
  213.     if (runInstances.classAttribute().isNominal()) {
  214.       runInstances.stratify(m_NumFolds);
  215.       } */
  216.     for (int fold = 0; fold < m_NumFolds; fold++) {
  217.       // Add in some fields to the key like run and fold number, dataset name
  218.       Object [] seKey = m_SplitEvaluator.getKey();
  219.       Object [] key = new Object [seKey.length + 3];
  220.       key[0] = Utils.backQuoteChars(m_Instances.relationName());
  221.       key[1] = "" + run;
  222.       key[2] = "" + (fold + 1);
  223.       System.arraycopy(seKey, 0, key, 3, seKey.length);
  224.       if (m_ResultListener.isResultRequired(this, key)) {
  225. try {
  226.   m_ResultListener.acceptResult(this, key, null);
  227. } catch (Exception ex) {
  228.   // Save the train and test datasets for debugging purposes?
  229.   throw ex;
  230. }
  231.       }
  232.     }
  233.   }
  234.   /**
  235.    * Gets the results for a specified run number. Different run
  236.    * numbers correspond to different randomizations of the data. Results
  237.    * produced should be sent to the current ResultListener
  238.    *
  239.    * @param run the run number to get results for.
  240.    * @exception Exception if a problem occurs while getting the results
  241.    */
  242.   public void doRun(int run) throws Exception {
  243.     if (getRawOutput()) {
  244.       if (m_ZipDest == null) {
  245. m_ZipDest = new OutputZipper(m_OutputFile);
  246.       }
  247.     }
  248.     if (m_Instances == null) {
  249.       throw new Exception("No Instances set");
  250.     }
  251.     // Randomize on a copy of the original dataset
  252.     Instances runInstances = new Instances(m_Instances);
  253.     runInstances.randomize(new Random(run));
  254.     if (runInstances.classAttribute().isNominal()) {
  255.       runInstances.stratify(m_NumFolds);
  256.     }
  257.     for (int fold = 0; fold < m_NumFolds; fold++) {
  258.       // Add in some fields to the key like run and fold number, dataset name
  259.       Object [] seKey = m_SplitEvaluator.getKey();
  260.       Object [] key = new Object [seKey.length + 3];
  261.       key[0] =  Utils.backQuoteChars(m_Instances.relationName());
  262.       key[1] = "" + run;
  263.       key[2] = "" + (fold + 1);
  264.       System.arraycopy(seKey, 0, key, 3, seKey.length);
  265.       if (m_ResultListener.isResultRequired(this, key)) {
  266. Instances train = runInstances.trainCV(m_NumFolds, fold);
  267. Instances test = runInstances.testCV(m_NumFolds, fold);
  268. try {
  269.   Object [] seResults = m_SplitEvaluator.getResult(train, test);
  270.   Object [] results = new Object [seResults.length + 1];
  271.   results[0] = getTimestamp();
  272.   System.arraycopy(seResults, 0, results, 1,
  273.    seResults.length);
  274.   if (m_debugOutput) {
  275.     String resultName = (""+run+"."+(fold+1)+"."
  276.       + Utils.backQuoteChars(runInstances.relationName())
  277.       +"."
  278.       +m_SplitEvaluator.toString()).replace(' ','_');
  279.     resultName = Utils.removeSubstring(resultName, 
  280.        "weka.classifiers.");
  281.     resultName = Utils.removeSubstring(resultName, 
  282.        "weka.filters.");
  283.     resultName = Utils.removeSubstring(resultName, 
  284.        "weka.attributeSelection.");
  285.     m_ZipDest.zipit(m_SplitEvaluator.getRawResultOutput(), resultName);
  286.   }
  287.   m_ResultListener.acceptResult(this, key, results);
  288. } catch (Exception ex) {
  289.   // Save the train and test datasets for debugging purposes?
  290.   throw ex;
  291. }
  292.       }
  293.     }
  294.   }
  295.   /**
  296.    * Gets the names of each of the columns produced for a single run.
  297.    * This method should really be static.
  298.    *
  299.    * @return an array containing the name of each column
  300.    */
  301.   public String [] getKeyNames() {
  302.     String [] keyNames = m_SplitEvaluator.getKeyNames();
  303.     // Add in the names of our extra key fields
  304.     String [] newKeyNames = new String [keyNames.length + 3];
  305.     newKeyNames[0] = DATASET_FIELD_NAME;
  306.     newKeyNames[1] = RUN_FIELD_NAME;
  307.     newKeyNames[2] = FOLD_FIELD_NAME;
  308.     System.arraycopy(keyNames, 0, newKeyNames, 3, keyNames.length);
  309.     return newKeyNames;
  310.   }
  311.   /**
  312.    * Gets the data types of each of the columns produced for a single run.
  313.    * This method should really be static.
  314.    *
  315.    * @return an array containing objects of the type of each column. The 
  316.    * objects should be Strings, or Doubles.
  317.    */
  318.   public Object [] getKeyTypes() {
  319.     Object [] keyTypes = m_SplitEvaluator.getKeyTypes();
  320.     // Add in the types of our extra fields
  321.     Object [] newKeyTypes = new String [keyTypes.length + 3];
  322.     newKeyTypes[0] = new String();
  323.     newKeyTypes[1] = new String();
  324.     newKeyTypes[2] = new String();
  325.     System.arraycopy(keyTypes, 0, newKeyTypes, 3, keyTypes.length);
  326.     return newKeyTypes;
  327.   }
  328.   /**
  329.    * Gets the names of each of the columns produced for a single run.
  330.    * This method should really be static.
  331.    *
  332.    * @return an array containing the name of each column
  333.    */
  334.   public String [] getResultNames() {
  335.     String [] resultNames = m_SplitEvaluator.getResultNames();
  336.     // Add in the names of our extra Result fields
  337.     String [] newResultNames = new String [resultNames.length + 1];
  338.     newResultNames[0] = TIMESTAMP_FIELD_NAME;
  339.     System.arraycopy(resultNames, 0, newResultNames, 1, resultNames.length);
  340.     return newResultNames;
  341.   }
  342.   /**
  343.    * Gets the data types of each of the columns produced for a single run.
  344.    * This method should really be static.
  345.    *
  346.    * @return an array containing objects of the type of each column. The 
  347.    * objects should be Strings, or Doubles.
  348.    */
  349.   public Object [] getResultTypes() {
  350.     Object [] resultTypes = m_SplitEvaluator.getResultTypes();
  351.     // Add in the types of our extra Result fields
  352.     Object [] newResultTypes = new Object [resultTypes.length + 1];
  353.     newResultTypes[0] = new Double(0);
  354.     System.arraycopy(resultTypes, 0, newResultTypes, 1, resultTypes.length);
  355.     return newResultTypes;
  356.   }
  357.   /**
  358.    * Gets a description of the internal settings of the result
  359.    * producer, sufficient for distinguishing a ResultProducer
  360.    * instance from another with different settings (ignoring
  361.    * those settings set through this interface). For example,
  362.    * a cross-validation ResultProducer may have a setting for the
  363.    * number of folds. For a given state, the results produced should
  364.    * be compatible. Typically if a ResultProducer is an OptionHandler,
  365.    * this string will represent the command line arguments required
  366.    * to set the ResultProducer to that state.
  367.    *
  368.    * @return the description of the ResultProducer state, or null
  369.    * if no state is defined
  370.    */
  371.   public String getCompatibilityState() {
  372.     String result = "-X " + m_NumFolds + " " ;
  373.     if (m_SplitEvaluator == null) {
  374.       result += "<null SplitEvaluator>";
  375.     } else {
  376.       result += "-W " + m_SplitEvaluator.getClass().getName();
  377.     }
  378.     return result + " --";
  379.   }
  380.   /**
  381.    * Returns the tip text for this property
  382.    * @return tip text for this property suitable for
  383.    * displaying in the explorer/experimenter gui
  384.    */
  385.   public String outputFileTipText() {
  386.     return "Set the destination for saving raw output. If the rawOutput "
  387.       +"option is selected, then output from the splitEvaluator for "
  388.       +"individual folds is saved. If the destination is a directory, "
  389.       +"then each output is saved to an individual gzip file; if the "
  390.       +"destination is a file, then each output is saved as an entry "
  391.       +"in a zip file.";
  392.   }
  393.   /**
  394.    * Get the value of OutputFile.
  395.    *
  396.    * @return Value of OutputFile.
  397.    */
  398.   public File getOutputFile() {
  399.     
  400.     return m_OutputFile;
  401.   }
  402.   
  403.   /**
  404.    * Set the value of OutputFile.
  405.    *
  406.    * @param newOutputFile Value to assign to OutputFile.
  407.    */
  408.   public void setOutputFile(File newOutputFile) {
  409.     
  410.     m_OutputFile = newOutputFile;
  411.   }  
  412.   /**
  413.    * Returns the tip text for this property
  414.    * @return tip text for this property suitable for
  415.    * displaying in the explorer/experimenter gui
  416.    */
  417.   public String numFoldsTipText() {
  418.     return "Number of folds to use in cross validation.";
  419.   }
  420.   /**
  421.    * Get the value of NumFolds.
  422.    *
  423.    * @return Value of NumFolds.
  424.    */
  425.   public int getNumFolds() {
  426.     
  427.     return m_NumFolds;
  428.   }
  429.   
  430.   /**
  431.    * Set the value of NumFolds.
  432.    *
  433.    * @param newNumFolds Value to assign to NumFolds.
  434.    */
  435.   public void setNumFolds(int newNumFolds) {
  436.     
  437.     m_NumFolds = newNumFolds;
  438.   }
  439.   /**
  440.    * Returns the tip text for this property
  441.    * @return tip text for this property suitable for
  442.    * displaying in the explorer/experimenter gui
  443.    */
  444.   public String rawOutputTipText() {
  445.     return "Save raw output (useful for debugging). If set, then output is "
  446.       +"sent to the destination specified by outputFile";
  447.   }
  448.   /**
  449.    * Get if raw split evaluator output is to be saved
  450.    * @return true if raw split evalutor output is to be saved
  451.    */
  452.   public boolean getRawOutput() {
  453.     return m_debugOutput;
  454.   }
  455.   
  456.   /**
  457.    * Set to true if raw split evaluator output is to be saved
  458.    * @param d true if output is to be saved
  459.    */
  460.   public void setRawOutput(boolean d) {
  461.     m_debugOutput = d;
  462.   }
  463.   /**
  464.    * Returns the tip text for this property
  465.    * @return tip text for this property suitable for
  466.    * displaying in the explorer/experimenter gui
  467.    */
  468.   public String splitEvaluatorTipText() {
  469.     return "The evaluator to apply to the cross validation folds. "
  470.       +"This may be a classifier, regression scheme etc.";
  471.   }
  472.  
  473.   /**
  474.    * Get the SplitEvaluator.
  475.    *
  476.    * @return the SplitEvaluator.
  477.    */
  478.   public SplitEvaluator getSplitEvaluator() {
  479.     
  480.     return m_SplitEvaluator;
  481.   }
  482.   
  483.   /**
  484.    * Set the SplitEvaluator.
  485.    *
  486.    * @param newSplitEvaluator new SplitEvaluator to use.
  487.    */
  488.   public void setSplitEvaluator(SplitEvaluator newSplitEvaluator) {
  489.     
  490.     m_SplitEvaluator = newSplitEvaluator;
  491.     m_SplitEvaluator.setAdditionalMeasures(m_AdditionalMeasures);
  492.   }
  493.   /**
  494.    * Returns an enumeration describing the available options.
  495.    *
  496.    * @return an enumeration of all the available options
  497.    */
  498.   public Enumeration listOptions() {
  499.     Vector newVector = new Vector(4);
  500.     newVector.addElement(new Option(
  501.      "tThe number of folds to use for the cross-validation.n"
  502.       +"t(default 10)", 
  503.      "X", 1, 
  504.      "-X <number of folds>"));
  505.     newVector.addElement(new Option(
  506.      "Save raw split evaluator output.",
  507.      "D",0,"-D"));
  508.     newVector.addElement(new Option(
  509.      "tThe filename where raw output will be stored.n"
  510.      +"tIf a directory name is specified then then individualn"
  511.      +"toutputs will be gzipped, otherwise all output will ben"
  512.      +"tzipped to the named file. Use in conjuction with -D."
  513.      +"t(default splitEvalutorOut.zip)", 
  514.      "O", 1, 
  515.      "-O <file/directory name/path>"));
  516.     newVector.addElement(new Option(
  517.      "tThe full class name of a SplitEvaluator.n"
  518.       +"teg: weka.experiment.ClassifierSplitEvaluator", 
  519.      "W", 1, 
  520.      "-W <class name>"));
  521.     if ((m_SplitEvaluator != null) &&
  522. (m_SplitEvaluator instanceof OptionHandler)) {
  523.       newVector.addElement(new Option(
  524.      "",
  525.      "", 0, "nOptions specific to split evaluator "
  526.      + m_SplitEvaluator.getClass().getName() + ":"));
  527.       Enumeration enum = ((OptionHandler)m_SplitEvaluator).listOptions();
  528.       while (enum.hasMoreElements()) {
  529. newVector.addElement(enum.nextElement());
  530.       }
  531.     }
  532.     return newVector.elements();
  533.   }
  534.   /**
  535.    * Parses a given list of options. Valid options are:<p>
  536.    *
  537.    * -X num_folds <br>
  538.    * The number of folds to use for the cross-validation. <p>
  539.    *
  540.    * -D <br>
  541.    * Specify that raw split evaluator output is to be saved. <p>
  542.    *
  543.    * -O file/directory name <br>
  544.    * Specify the file or directory to which raw split evaluator output
  545.    * is to be saved. If a directory is specified, then each output string
  546.    * is saved as an individual gzip file. If a file is specified, then
  547.    * each output string is saved as an entry in a zip file. <p>
  548.    *
  549.    * -W classname <br>
  550.    * Specify the full class name of the split evaluator. <p>
  551.    *
  552.    * All option after -- will be passed to the split evaluator.
  553.    *
  554.    * @param options the list of options as an array of strings
  555.    * @exception Exception if an option is not supported
  556.    */
  557.   public void setOptions(String[] options) throws Exception {
  558.     
  559.     setRawOutput(Utils.getFlag('D', options));
  560.     String fName = Utils.getOption('O', options);
  561.     if (fName.length() != 0) {
  562.       setOutputFile(new File(fName));
  563.     }
  564.     String numFolds = Utils.getOption('X', options);
  565.     if (numFolds.length() != 0) {
  566.       setNumFolds(Integer.parseInt(numFolds));
  567.     } else {
  568.       setNumFolds(10);
  569.     }
  570.     String seName = Utils.getOption('W', options);
  571.     if (seName.length() == 0) {
  572.       throw new Exception("A SplitEvaluator must be specified with"
  573.   + " the -W option.");
  574.     }
  575.     // Do it first without options, so if an exception is thrown during
  576.     // the option setting, listOptions will contain options for the actual
  577.     // SE.
  578.     setSplitEvaluator((SplitEvaluator)Utils.forName(
  579.       SplitEvaluator.class,
  580.       seName,
  581.       null));
  582.     if (getSplitEvaluator() instanceof OptionHandler) {
  583.       ((OptionHandler) getSplitEvaluator())
  584. .setOptions(Utils.partitionOptions(options));
  585.     }
  586.   }
  587.   /**
  588.    * Gets the current settings of the result producer.
  589.    *
  590.    * @return an array of strings suitable for passing to setOptions
  591.    */
  592.   public String [] getOptions() {
  593.     String [] seOptions = new String [0];
  594.     if ((m_SplitEvaluator != null) && 
  595. (m_SplitEvaluator instanceof OptionHandler)) {
  596.       seOptions = ((OptionHandler)m_SplitEvaluator).getOptions();
  597.     }
  598.     
  599.     String [] options = new String [seOptions.length + 8];
  600.     int current = 0;
  601.     options[current++] = "-X"; options[current++] = "" + getNumFolds();
  602.     if (getRawOutput()) {
  603.       options[current++] = "-D";
  604.     }
  605.     options[current++] = "-O"; 
  606.     options[current++] = getOutputFile().getName();
  607.     
  608.     if (getSplitEvaluator() != null) {
  609.       options[current++] = "-W";
  610.       options[current++] = getSplitEvaluator().getClass().getName();
  611.     }
  612.     options[current++] = "--";
  613.     System.arraycopy(seOptions, 0, options, current, 
  614.      seOptions.length);
  615.     current += seOptions.length;
  616.     while (current < options.length) {
  617.       options[current++] = "";
  618.     }
  619.     return options;
  620.   }
  621.   /**
  622.    * Gets a text descrption of the result producer.
  623.    *
  624.    * @return a text description of the result producer.
  625.    */
  626.   public String toString() {
  627.     String result = "CrossValidationResultProducer: ";
  628.     result += getCompatibilityState();
  629.     if (m_Instances == null) {
  630.       result += ": <null Instances>";
  631.     } else {
  632.       result += ": " +  Utils.backQuoteChars(m_Instances.relationName());
  633.     }
  634.     return result;
  635.   }
  636.     
  637.   // Quick test of timestamp
  638.   public static void main(String [] args) {
  639.     
  640.     System.err.println(Utils.doubleToString(getTimestamp().doubleValue(), 4));
  641.   }
  642. } // CrossValidationResultProducer