📄 experiment.java
字号:
determineAdditionalResultMeasures(); // } m_ResultProducer.setResultListener(m_ResultListener); m_ResultProducer.setAdditionalMeasures(m_AdditionalMeasures); m_ResultProducer.preProcess(); // constrain the additional measures to be only those allowable // by the ResultListener String [] columnConstraints = m_ResultListener. determineColumnConstraints(m_ResultProducer); if (columnConstraints != null) { m_ResultProducer.setAdditionalMeasures(columnConstraints); } } /** * Iterate over the objects in the property array to determine what * (if any) additional measures they support * * @throws Exception if additional measures don't comply to the naming * convention (starting with "measure") */ private void determineAdditionalResultMeasures() throws Exception { m_AdditionalMeasures = null; FastVector measureNames = new FastVector(); // first try the result producer, then property array if applicable if (m_ResultProducer instanceof AdditionalMeasureProducer) { Enumeration am = ((AdditionalMeasureProducer)m_ResultProducer). enumerateMeasures(); while (am.hasMoreElements()) { String mname = (String)am.nextElement(); if (mname.startsWith("measure")) { if (measureNames.indexOf(mname) == -1) { measureNames.addElement(mname); } } else { throw new Exception ("Additional measures in " + m_ResultProducer.getClass().getName() +" must obey the naming convention" +" of starting with \"measure\""); } } } if (m_UsePropertyIterator && (m_PropertyArray != null)) { for (int i = 0; i < Array.getLength(m_PropertyArray); i++) { Object current = Array.get(m_PropertyArray, i); if (current instanceof AdditionalMeasureProducer) { Enumeration am = ((AdditionalMeasureProducer)current). enumerateMeasures(); while (am.hasMoreElements()) { String mname = (String)am.nextElement(); if (mname.startsWith("measure")) { if (measureNames.indexOf(mname) == -1) { measureNames.addElement(mname); } } else { throw new Exception ("Additional measures in " + current.getClass().getName() +" must obey the naming convention" +" of starting with \"measure\""); } } } } } if (measureNames.size() > 0) { m_AdditionalMeasures = new String [measureNames.size()]; for (int i=0;i<measureNames.size();i++) { m_AdditionalMeasures[i] = (String)measureNames.elementAt(i); } } } /** * Recursively sets the custom property value, by setting all values * along the property path. * * @param propertyDepth the current position along the property path * @param origValue the value to set the property to * @throws Exception if an error occurs */ protected void setProperty(int propertyDepth, Object origValue) throws Exception { PropertyDescriptor current = m_PropertyPath[propertyDepth].property; Object subVal = null; if (propertyDepth < m_PropertyPath.length - 1) { Method getter = current.getReadMethod(); Object getArgs [] = { }; subVal = getter.invoke(origValue, getArgs); setProperty(propertyDepth + 1, subVal); } else { subVal = Array.get(m_PropertyArray, m_PropertyNumber); } Method setter = current.getWriteMethod(); Object [] args = { subVal }; setter.invoke(origValue, args); } /** * Returns true if there are more iterations to carry out in the experiment. * * @return true if so */ public boolean hasMoreIterations() { return !m_Finished; } /** * Carries out the next iteration of the experiment. * * @throws Exception if an error occurs */ public void nextIteration() throws Exception { if (m_UsePropertyIterator) { if (m_CurrentProperty != m_PropertyNumber) { setProperty(0, m_ResultProducer); m_CurrentProperty = m_PropertyNumber; } } if (m_CurrentInstances == null) { File currentFile = (File) getDatasets().elementAt(m_DatasetNumber); Reader reader = new FileReader(currentFile); Instances data = new Instances(new BufferedReader(reader)); if (m_ClassFirst) { data.setClassIndex(0); } else { data.setClassIndex(data.numAttributes() - 1); } m_CurrentInstances = data; m_ResultProducer.setInstances(m_CurrentInstances); } m_ResultProducer.doRun(m_RunNumber); advanceCounters(); } /** * Increments iteration counters appropriately. */ public void advanceCounters() { if (m_AdvanceDataSetFirst) { m_RunNumber ++; if (m_RunNumber > getRunUpper()) { m_RunNumber = getRunLower(); m_DatasetNumber ++; m_CurrentInstances = null; if (m_DatasetNumber >= getDatasets().size()) { m_DatasetNumber = 0; if (m_UsePropertyIterator) { m_PropertyNumber ++; if (m_PropertyNumber >= Array.getLength(m_PropertyArray)) { m_Finished = true; } } else { m_Finished = true; } } } } else { // advance by custom iterator before data set m_RunNumber ++; if (m_RunNumber > getRunUpper()) { m_RunNumber = getRunLower(); if (m_UsePropertyIterator) { m_PropertyNumber ++; if (m_PropertyNumber >= Array.getLength(m_PropertyArray)) { m_PropertyNumber = 0; m_DatasetNumber ++; m_CurrentInstances = null; if (m_DatasetNumber >= getDatasets().size()) { m_Finished = true; } } } else { m_DatasetNumber ++; m_CurrentInstances = null; if (m_DatasetNumber >= getDatasets().size()) { m_Finished = true; } } } } } /** * Runs all iterations of the experiment, continuing past errors. */ public void runExperiment() { while (hasMoreIterations()) { try { nextIteration(); } catch (Exception ex) { ex.printStackTrace(); System.err.println(ex.getMessage()); advanceCounters(); // Try to keep plowing through } } } /** * Signals that the experiment is finished running, so that cleanup * can be done. * * @throws Exception if an error occurs */ public void postProcess() throws Exception { m_ResultProducer.postProcess(); } /** * Gets the datasets in the experiment. * * @return the datasets in the experiment. */ public DefaultListModel getDatasets() { return m_Datasets; } /** * Set the datasets to use in the experiment * @param ds the list of datasets to use */ public void setDatasets(DefaultListModel ds) { m_Datasets = ds; } /** * Gets the result listener where results will be sent. * * @return the result listener where results will be sent. */ public ResultListener getResultListener() { return m_ResultListener; } /** * Sets the result listener where results will be sent. * * @param newResultListener the result listener where results will be sent. */ public void setResultListener(ResultListener newResultListener) { m_ResultListener = newResultListener; } /** * Get the result producer used for the current experiment. * * @return the result producer used for the current experiment. */ public ResultProducer getResultProducer() { return m_ResultProducer; } /** * Set the result producer used for the current experiment. * * @param newResultProducer result producer to use for the current * experiment. */ public void setResultProducer(ResultProducer newResultProducer) { m_ResultProducer = newResultProducer; } /** * Get the upper run number for the experiment. * * @return the upper run number for the experiment. */ public int getRunUpper() { return m_RunUpper; } /** * Set the upper run number for the experiment. * * @param newRunUpper the upper run number for the experiment. */ public void setRunUpper(int newRunUpper) { m_RunUpper = newRunUpper; } /** * Get the lower run number for the experiment. * * @return the lower run number for the experiment. */ public int getRunLower() { return m_RunLower; } /** * Set the lower run number for the experiment. * * @param newRunLower the lower run number for the experiment. */ public void setRunLower(int newRunLower) { m_RunLower = newRunLower; } /** * Get the user notes. * * @return User notes associated with the experiment. */ public String getNotes() { return m_Notes; } /** * Set the user notes. * * @param newNotes New user notes. */ public void setNotes(String newNotes) { m_Notes = newNotes; } /** * Returns an enumeration describing the available options.. * * @return an enumeration of all the available options. */ public Enumeration listOptions() { Vector newVector = new Vector(6); newVector.addElement(new Option( "\tThe lower run number to start the experiment from.\n" +"\t(default 1)", "L", 1, "-L <num>")); newVector.addElement(new Option( "\tThe upper run number to end the experiment at (inclusive).\n" +"\t(default 10)", "U", 1, "-U <num>")); newVector.addElement(new Option( "\tThe dataset to run the experiment on.\n" + "\t(required, may be specified multiple times)", "T", 1, "-T <arff file>")); newVector.addElement(new Option( "\tThe full class name of a ResultProducer (required).\n" +"\teg: weka.experiment.RandomSplitResultProducer", "P", 1, "-P <class name>")); newVector.addElement(new Option( "\tThe full class name of a ResultListener (required).\n" +"\teg: weka.experiment.CSVResultListener", "D", 1, "-D <class name>")); newVector.addElement(new Option( "\tA string containing any notes about the experiment.\n" +"\t(default none)", "N", 1, "-N <string>")); if ((m_ResultProducer != null) && (m_ResultProducer instanceof OptionHandler)) { newVector.addElement(new Option( "", "", 0, "\nOptions specific to result producer " + m_ResultProducer.getClass().getName() + ":")); Enumeration enm = ((OptionHandler)m_ResultProducer).listOptions(); while (enm.hasMoreElements()) { newVector.addElement(enm.nextElement()); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -