bodhidharma
Class ClassificationPanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by bodhidharma.ClassificationPanel
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class ClassificationPanel
extends javax.swing.JPanel
implements java.awt.event.ActionListener

Part of the Bodhidharma automatic music classification project. This is the panel of the GUI that allows users to train, classify and see the results of classifications.

This panel allows users to assign different functions to buttons with combo box. Each combo box affects the function of the button above it.

The way in which much of the operations are performed here depends greatly on the PreferencesPanel.

The main display area gives reports.

The Train button causes the system to train the classifiers using the currently loaded taxonomy, preferences, features and recordings. Features must have already been extracted from recordings in order for this to work. The particular recordings used for training depends on the the contents of the combo box below the Train button. The Randomly Partitioned Recs option randomly selects a portion of the recordings for training (based on the value of the Fraction of Recordings to use for Training preference) and reserves the rest for testing. The Recs Marked For Training option only uses those recordings marked with a Role of training for training. The All Recs option trains on all currently available recordings. All types of recording auto-generate the training progress and selection / weightings reports (see below). A multi-level progress bar is shown during training which gives an estimate of the training time remaining. Training can be cancelled at any time.

The Classify button causes the system to classify a certain set of recordings based on the contents of the following combo box. The Reserved Recs option classifies any recordings that have been reserved for testing, usually as a result of Randomly Partitioned Recs training (see above). The Recs Marked For Classification option classifies the recordings with a role of classification. The Recs Marked For Testing option classifies the recordings with a role of testing. The All Recs option classifies all currently loaded recordings. All recordings must have had their features already extracted for classification to be performed. Classification only works if training has already been performed. Classification results reports are automatically generated upon completion of training (see below). An overall report is also generated and displayed upon completion of classificaiton. Note that success rates are only shown for the Randomly Partitioned Recs option (although they can still be manually calculated otherwise).

The Cross-Validation Test automatically divides the loaded recordings into different folds (with a number determined by the Fraction of Recordings to use for Training preference. Each fold consists of training and testing partitions, such that each recording serves as a testing recording exactly once accross all folds and as a training recording in the other folds. Each fold is then trained and tested, and the results of each fold are saved to disk. A combined results report is then displayed and saved. Reports of the average feature (one-dimensional and multi-dimensional) weightings and their standard deviations accross folds are also saved for each ensemble. Note that the weightings of individual one-dimensional features are scaled based on the overall weighting of one-dimensional features. The reported weightings have been normalized.

The Report Training Progress, Report Classification Results and Report Selections / Weightings buttons show the auto-generated reports specified by the combo boxes below them. "DD" refers to hierarchal classifiers and "RR" refers to round robin classifiers.

The Save Reports button saves any currently loaded reports to disk.

The other load and save buttons are used to save classifiers and any reserved recordings to disk.

The clearStoredData and clearMultiFoldStoredData methods are used to reset the classifiers.

The getScaledFeatureValues, getMaxFeatureValueCutoffs, getMinFeatureValueCutoffs and getOneDimFeatureNames methods provide information about the scaling of the features.

The saveClassifierFiles method is used to save classifiers and associated test recordings to disk. The saveReports method is used to save training, classification and selection/weighting reports to disk.

The other public methods are used for training and classification.

See Also:
PreferencesPanel, ClassificationResults_interpereter, NN_BioKNN_Ensemble, MainJFrame, Serialized Form
Author:
Cory McKay

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 javax.swing.JTextArea results_display
           
 ProgressBarTaskTrainMonitor training_monitor
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ClassificationPanel(MainJFrame parent)
          Basic constructor that configures and instantiates the panel.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent event)
          Calls the appropriate methods when the buttons are pressed.
 void classifyFromCommandLine(java.lang.String output_classifications_path)
          Classify all currently loaded recordings and save the results to the specified file.
 void classifyRecordings(Recording[] recordings_to_classify)
          Classifies the specified recordings and displays the classification results.
 void clearMultiFoldStoredData()
          Reset multi-fold fields.
 void clearStoredData()
          Reset stored classifiers and related information (except for mult-fold fields (use clearMultiFoldStoredData method for this)).
 double[] getMaxFeatureValueCutoffs()
          Returns the maximum acceptable one-dimensional feature value for scaling.
 double[] getMinFeatureValueCutoffs()
          Returns the minimum acceptable one-dimensional feature value for scaling.
 java.lang.String[] getOneDimFeatureNames(Recording[] recordings_to_name_one_D_features_from)
          Returns the names of all one-dimensional features in the given recordings in the order that they occur.
 double[][] getScaledFeatureValues(Recording[] recordings_to_scale)
          Returns the scaled values of the given recordings.
 void performAFoldOfTrainingAndClassification(boolean[][] training_keys, int current_fold, int training_time_taken)
          Recursively performs the cross-validation training and classifying.
 void performHierarchicalTraining(Recording[] all_eligible_recordings, boolean[] training_key, boolean report_training_results, ProgressBarTaskTrainMonitor training_monitor)
          Trains the array of NN_BioKNN_Ensembles in the classifier_ensemble field and records the recordings which are reserved for testing them in the testing_recordings and model_testing_classifications fields.
 void recordWeightingsAccrossFolds(int fold)
          Records the names and weightings of all one-dimensional features and classifiers in the given fold.
 void saveClassifierFiles(java.lang.String comments, boolean is_basic_save)
          Saves a classifiers_file XML file with a related folder and the appropriate classifier files within it.
 void saveReports(java.io.File place_to_save)
          Saves all currently available reports in the given new directory.
 void train_with_cross_validation()
          Perorms a multi-fold cross-validation.
 void trainFromCommandLine()
          Train on all currently loaded recordings and save the results in the locations specified in the ConfigureFileLocationsJFrame.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

training_monitor

public ProgressBarTaskTrainMonitor training_monitor

results_display

public javax.swing.JTextArea results_display
Constructor Detail

ClassificationPanel

public ClassificationPanel(MainJFrame parent)
Basic constructor that configures and instantiates the panel.

Parameters:
parent - Name of the MainJFrame window that holds this panel.
See Also:
ConfigureFileLocationsJFrame, MainJFrame
Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent event)
Calls the appropriate methods when the buttons are pressed.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
event - The event that is to be reacted to.

clearStoredData

public void clearStoredData()
Reset stored classifiers and related information (except for mult-fold fields (use clearMultiFoldStoredData method for this)).


clearMultiFoldStoredData

public void clearMultiFoldStoredData()
Reset multi-fold fields.


getScaledFeatureValues

public double[][] getScaledFeatureValues(Recording[] recordings_to_scale)
                                  throws java.lang.Exception
Returns the scaled values of the given recordings. Scaling is performed by a trained one-dimensional classifier. An exception is thrown if no such classifier is available or if there is a problem with the given recordings. Only one-dimensional feature values are returned, so the getScaledFeatureNames method should be called to understand what features the second indice refers to. First indice refers to recording.

Throws:
java.lang.Exception

getMaxFeatureValueCutoffs

public double[] getMaxFeatureValueCutoffs()
                                   throws java.lang.Exception
Returns the maximum acceptable one-dimensional feature value for scaling. All featue values above this are scaled to 1. This is calculated by a trained one-dimensional classifier. An exception is thrown if no such classifier is availables. The getScaledFeatureNames method should be called in order to understand what features the indice refer to.

Throws:
java.lang.Exception

getMinFeatureValueCutoffs

public double[] getMinFeatureValueCutoffs()
                                   throws java.lang.Exception
Returns the minimum acceptable one-dimensional feature value for scaling. All featue values below this are scaled to 0. This is calculated by a trained one-dimensional classifier. An exception is thrown if no such classifier is availables. The getScaledFeatureNames method should be called in order to understand what features the indice refer to.

Throws:
java.lang.Exception

getOneDimFeatureNames

public java.lang.String[] getOneDimFeatureNames(Recording[] recordings_to_name_one_D_features_from)
Returns the names of all one-dimensional features in the given recordings in the order that they occur.


saveClassifierFiles

public void saveClassifierFiles(java.lang.String comments,
                                boolean is_basic_save)
Saves a classifiers_file XML file with a related folder and the appropriate classifier files within it.

If the is_basic_save parameter is true, then the file is saved at the path specified in the ConfigureFileLocationsJFrame object's classifiers_text_field field (automatically overwriting any existing files with the same path). If the is_basic_save parameter is false, then the file is saved at a location chosen by the user with a JFileChooser dialog box.

Displays an infomative error message if a problem occurs.

Parameters:
comments - Any comments to be saved inside the comments element of the XML file.
is_basic_save - Whether this is a save (true) or save as (false) operation.
See Also:
ConfigureFileLocationsJFrame

saveReports

public void saveReports(java.io.File place_to_save)
                 throws java.lang.Exception
Saves all currently available reports in the given new directory.

Throws:
java.lang.Exception

train_with_cross_validation

public void train_with_cross_validation()
Perorms a multi-fold cross-validation. The number of folds depends on the results of the getTrainingFraction method of a PreferencesPanel object.

All reports are saved in a location specified by the user.


performAFoldOfTrainingAndClassification

public void performAFoldOfTrainingAndClassification(boolean[][] training_keys,
                                                    int current_fold,
                                                    int training_time_taken)
                                             throws java.lang.Exception
Recursively performs the cross-validation training and classifying. Saves the reports for each fold and displays and saves an overall report. Also saves the averages and standard deviations of feature and classifier weightings accross all cross-validation folds.

Works through a ProgressBarTaskTrainMonitor object.

Parameters:
training_keys - Which recordings to train for each fold. First indice is fold, second is recording.
current_fold - The current fold.
training_time_taken - The time taken to train the last fold.
Throws:
java.lang.Exception

recordWeightingsAccrossFolds

public void recordWeightingsAccrossFolds(int fold)
                                  throws java.lang.Exception
Records the names and weightings of all one-dimensional features and classifiers in the given fold.

Parameters:
fold - The current fold.
Throws:
java.lang.Exception

performHierarchicalTraining

public void performHierarchicalTraining(Recording[] all_eligible_recordings,
                                        boolean[] training_key,
                                        boolean report_training_results,
                                        ProgressBarTaskTrainMonitor training_monitor)
                                 throws java.lang.Exception
Trains the array of NN_BioKNN_Ensembles in the classifier_ensemble field and records the recordings which are reserved for testing them in the testing_recordings and model_testing_classifications fields. Also stores the names of the recordings used to train each ensemble in the training_recordings_info field and the training errors for each ensemble in the combined_training_errors field. This information can be accessed using the report_training_errors_button and the training_errors_ensemble_selector GUI elements. Information about the trained classifiers can be accessed using the report_selection_weighting_button and selection_weighting_selector fields.

If the training_key parameter is null, then all_eligible_recordings will be randomly partitioned into training and testing sets as specified by the getTrainingFraction method of the PrefencesPanel. If this parameter is not null, it will control this partitioning.

Any combination of four types of ensembles of classifiers will be trained, based on the selections in the PreferencesPanel. The four ensemble types, the order they appear in the arrays mentioned above (including NN_BioKNN_Ensembles) used and the subset of the recordings chosen for training are:

Leaf Classifier: Classifies recordings into one or more of any of the leaf categories. Trained on all available training recordings. Ensemble is labeled "Leaf Classifier". Only one ensemble of this type is generated.
Root Classifier: Classifies recordings into one or more of any of the root categories (the ones at the top of the taxonomy tree). Trained on all available training recordings. Ensemble is labeled "Root Classifier". Only one ensemble of this type is generated.
Direct Descendant Classifiers: Classify recordings into one or more of any of the categories that are the direct descendants of any of a category node with children. Trained only on the subset of training recordings that belong, at least partially, to this parent category. One such ensemble is generated for each category node with children. Ensembles are labeled "DD ".
Round Robin Classifiers: Classify recordings into one or more of any pair of leaf categories. Trained only on the subset of training recordings that belong, at least partially, to one of these two leaf categories. One such ensemble is generated for every possible pair. Ensembles are labeled "RR / ".

Parameters:
all_eligible_recordings - Recordings that will be broken up into training and testing groups.
training_key - Which recordings are to be used for testing and which are to be used for training. Indice corresponds to that of the all_eligible_recordings parameter. Value of true means use for training. A value of null means that breakdown is randomly selected.
report_training_results - Whether or not training errors (i.e. classifier convergence) are reported. Overrides preferences settings.
training_monitor - ProgressBarTaskTrainMonitor that is monitoring progress of training. Can be null if no ProgressBarTaskTrainMonitor is used.
Throws:
java.lang.Exception

classifyRecordings

public void classifyRecordings(Recording[] recordings_to_classify)
Classifies the specified recordings and displays the classification results. Any included model categories are ignored (i.e. no success rates are given). The testing_recordings field is set to the given recordings_to_classify parameter and the model_testing_classifications field is set to null.


trainFromCommandLine

public void trainFromCommandLine()
Train on all currently loaded recordings and save the results in the locations specified in the ConfigureFileLocationsJFrame. This method is designed to be used with the command line interface of Bodhidharma.


classifyFromCommandLine

public void classifyFromCommandLine(java.lang.String output_classifications_path)
                             throws java.lang.Exception
Classify all currently loaded recordings and save the results to the specified file. This method is designed to be used with the command line interface of Bodhidharma.

Parameters:
output_classifications_path - The path to save the output classifications.
Throws:
java.lang.Exception