de.unihalle.informatik.MiToBo.apps.scratchAssay
Class ScratchAssaySVMTrainer

java.lang.Object
  extended by de.unihalle.informatik.Alida.operator.ALDOperator
      extended by de.unihalle.informatik.MiToBo.core.operator.MTBOperator
          extended by de.unihalle.informatik.MiToBo.apps.scratchAssay.ScratchAssaySVMTrainer
All Implemented Interfaces:
de.unihalle.informatik.Alida.datatypes.ALDConfigurationValidator

@ALDAOperator(genericExecutionMode=SWING,
              level=STANDARD,
              allowBatchMode=false)
public class ScratchAssaySVMTrainer
extends MTBOperator

class for training and cross validating a support vector machine for classification of scratch assay
images into images containing a scratch and those that don't

Author:
glass

Nested Class Summary
static class ScratchAssaySVMTrainer.KERNEL_TYPE
           
static class ScratchAssaySVMTrainer.ScratchOrientation
           
static class ScratchAssaySVMTrainer.ValidationMethod
           
 
Nested classes/interfaces inherited from class de.unihalle.informatik.Alida.operator.ALDOperator
de.unihalle.informatik.Alida.operator.ALDOperator.HidingMode
 
Field Summary
private  java.lang.Integer C
           
private  java.lang.Integer degree
           
private  java.lang.Integer entropyFilterSize
           
private  java.lang.String error_msg
           
(package private)  java.lang.StringBuffer falseFileNames
           
(package private)  java.lang.StringBuffer falseNegativeFileNames
           
(package private)  java.lang.StringBuffer falsePositiveFileNames
           
private  int fn
           
private  int fp
           
private  java.lang.Boolean isHorizontal
           
private  java.lang.Integer k
           
private  java.lang.Integer maxIter
           
private  ScratchAssaySVMTrainer.ValidationMethod method
           
private  libsvm.svm_model model
           
private  de.unihalle.informatik.Alida.datatypes.ALDDirectoryString negDir
           
private  ScratchAssaySVMTrainer.ScratchOrientation orientation
           
(package private)  java.lang.String outFile
           
private  libsvm.svm_parameter param
           
private  de.unihalle.informatik.Alida.datatypes.ALDDirectoryString posDir
           
private  libsvm.svm_problem prob
           
private  java.lang.Integer sigma
           
private  int tn
           
private  int tp
           
private  ScratchAssaySVMTrainer.KERNEL_TYPE type
           
private  java.util.Vector<libsvm.svm_node[]> vx
           
private  java.util.Vector<java.lang.Double> vy
           
 
Fields inherited from class de.unihalle.informatik.Alida.operator.ALDOperator
completeDAG, name, portHashAccess, verbose, versionProvider
 
Constructor Summary
ScratchAssaySVMTrainer()
           
ScratchAssaySVMTrainer(java.lang.String posDir, java.lang.String negDir, int sigma, int entropyFilterSize, boolean isHorizontal, int maxIter)
           
 
Method Summary
private  void addFeatures(double label, double[] features)
          add the given patterns (feature arrays) together with their corresponding label to the existing patterns used to train the SVM
private  double classify(double[] features)
           
private  void extract(java.io.File[] samples, double label)
          segment the given images and extract their features for classification
private  void extract(java.util.Vector<java.io.File> samples, double label)
          segment the given images and extract their features for classification
private  void leaveOneOutCrossValidation()
          leave-one-out cross validation, i.e. iteratively one sample is taken as test
sample whereas all others are used for training
private  MTBTableModel makeTable()
           
 void operate()
           
private  MTBImage readImage(java.lang.String path)
           
private  void saveSVM()
          save resulting svm model file
 void setSVMParameters(libsvm.svm_parameter param)
           
private  void stratifiedCrossValidation()
          stratified k-fold cross validation, i.e. training and test tests contain approximately the same proportions of positive and negative samples in every iteration
private  int[] test(java.util.Vector<java.io.File> samples, int label)
           
private  void train()
          the actual svm training
 
Methods inherited from class de.unihalle.informatik.MiToBo.core.operator.MTBOperator
readResolve
 
Methods inherited from class de.unihalle.informatik.Alida.operator.ALDOperator
deserializeFromXmlFile, fieldContained, getALDPortHashAccessKey, getConstructionMode, getInInoutNames, getInInoutNames, getInNames, getInOutNames, getMissingRequiredInputs, getName, getNumParameters, getOutInoutNames, getOutNames, getParameter, getParameterDescriptor, getParameterNames, getSupplementalNames, getVerbose, getVersion, isConfigured, parametersToXmlObject, print, print, print, printInterface, printInterface, readHistory, reinitializeParameterDescriptors, runOp, runOp, runOp, serializeToXmlFile, setConstructionMode, setName, setParameter, setParametersFromXml, setParametersFromXml, setVerbose, toStringVerbose, unconfiguredItems, validate, validateCustom, validateGeneric, writeHistory, writeHistory, writeHistory, writeParametersToXml
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

C

@Parameter(label="regularization parameter (C)",
           required=false,
           direction=IN,
           supplemental=false,
           description="regularization parameter",
           mode=STANDARD,
           dataIOOrder=0)
private java.lang.Integer C

degree

@Parameter(label="degree (only for polynomial kernel)",
           required=false,
           direction=IN,
           supplemental=false,
           description="degree for polynomial svm kernel",
           mode=STANDARD,
           dataIOOrder=4)
private java.lang.Integer degree

entropyFilterSize

@Parameter(label="entropy filter size",
           required=true,
           direction=IN,
           supplemental=false,
           description="size of entropy filter mask",
           mode=STANDARD,
           dataIOOrder=4)
private java.lang.Integer entropyFilterSize

error_msg

private java.lang.String error_msg

falseFileNames

java.lang.StringBuffer falseFileNames

falseNegativeFileNames

java.lang.StringBuffer falseNegativeFileNames

falsePositiveFileNames

java.lang.StringBuffer falsePositiveFileNames

fn

private int fn

fp

private int fp

isHorizontal

private java.lang.Boolean isHorizontal

k

@Parameter(label="k (only for k-fold x-validation)",
           required=false,
           direction=IN,
           supplemental=false,
           description="k for k-fold cross validation",
           mode=STANDARD,
           dataIOOrder=5)
private java.lang.Integer k

maxIter

@Parameter(label="maximum iterations",
           required=false,
           direction=IN,
           supplemental=false,
           description="maximum number of iterations of level set segmentation",
           mode=ADVANCED,
           dataIOOrder=2)
private java.lang.Integer maxIter

method

@Parameter(label="validation method",
           required=false,
           direction=IN,
           supplemental=false,
           description="validation method for x-validation",
           mode=STANDARD,
           dataIOOrder=6)
private ScratchAssaySVMTrainer.ValidationMethod method

model

private libsvm.svm_model model

negDir

@Parameter(label="directory containing negative samples",
           required=true,
           direction=IN,
           supplemental=false,
           description="directory containing negative samples",
           mode=STANDARD,
           dataIOOrder=1)
private de.unihalle.informatik.Alida.datatypes.ALDDirectoryString negDir

orientation

@Parameter(label="scratch orientation",
           required=true,
           direction=IN,
           supplemental=false,
           description="horizontally or vertically oriented scratch",
           mode=STANDARD,
           dataIOOrder=2)
private ScratchAssaySVMTrainer.ScratchOrientation orientation

outFile

java.lang.String outFile

param

private libsvm.svm_parameter param

posDir

@Parameter(label="directory containing positive samples",
           required=true,
           direction=IN,
           supplemental=false,
           description="directory containing positive samples",
           mode=STANDARD,
           dataIOOrder=0)
private de.unihalle.informatik.Alida.datatypes.ALDDirectoryString posDir

prob

private libsvm.svm_problem prob

sigma

@Parameter(label="\u03c3",
           required=true,
           direction=IN,
           supplemental=false,
           description="standard deviation of gauss filter",
           mode=STANDARD,
           dataIOOrder=3)
private java.lang.Integer sigma

tn

private int tn

tp

private int tp

type

@Parameter(label="kernel type",
           required=false,
           direction=IN,
           supplemental=false,
           description="type of svm kernel",
           mode=STANDARD,
           dataIOOrder=1)
private ScratchAssaySVMTrainer.KERNEL_TYPE type

vx

private java.util.Vector<libsvm.svm_node[]> vx

vy

private java.util.Vector<java.lang.Double> vy
Constructor Detail

ScratchAssaySVMTrainer

public ScratchAssaySVMTrainer()
                       throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException
Throws:
de.unihalle.informatik.Alida.exceptions.ALDOperatorException

ScratchAssaySVMTrainer

public ScratchAssaySVMTrainer(java.lang.String posDir,
                              java.lang.String negDir,
                              int sigma,
                              int entropyFilterSize,
                              boolean isHorizontal,
                              int maxIter)
                       throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException
Parameters:
posDir - directory containing positive samples
negDir - directory containing negative samples
sigma - standard deviation of gauss filter
entropyFilterSize - size of entropy filter mask
isHorizontal - is scratch horizontally oriented (assumed to be vertically oriented else)
maxIter - maximum number of iterations for level set segmentation
Throws:
de.unihalle.informatik.Alida.exceptions.ALDOperatorException
Method Detail

addFeatures

private void addFeatures(double label,
                         double[] features)
add the given patterns (feature arrays) together with their corresponding label to the existing patterns used to train the SVM

Parameters:
label - label for the givven features
features - array of feature values

classify

private double classify(double[] features)
Parameters:
features -
Returns:
predicted class label

extract

private void extract(java.io.File[] samples,
                     double label)
segment the given images and extract their features for classification

Parameters:
samples - array of filenames containing images
label - label of the input images

extract

private void extract(java.util.Vector<java.io.File> samples,
                     double label)
segment the given images and extract their features for classification

Parameters:
samples - vector of filenames containing images
label - label of the input images

leaveOneOutCrossValidation

private void leaveOneOutCrossValidation()
leave-one-out cross validation, i.e. iteratively one sample is taken as test
sample whereas all others are used for training


makeTable

private MTBTableModel makeTable()
Returns:
table containing the cross validation results

operate

public void operate()
             throws de.unihalle.informatik.Alida.exceptions.ALDOperatorException,
                    de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException
Specified by:
operate in class de.unihalle.informatik.Alida.operator.ALDOperator
Throws:
de.unihalle.informatik.Alida.exceptions.ALDOperatorException
de.unihalle.informatik.Alida.exceptions.ALDProcessingDAGException

readImage

private MTBImage readImage(java.lang.String path)
Parameters:
path -
Returns:
image read from given path, if it is a valid image path

saveSVM

private void saveSVM()
save resulting svm model file


setSVMParameters

public void setSVMParameters(libsvm.svm_parameter param)
Parameters:
param -

stratifiedCrossValidation

private void stratifiedCrossValidation()
stratified k-fold cross validation, i.e. training and test tests contain approximately the same proportions of positive and negative samples in every iteration


test

private int[] test(java.util.Vector<java.io.File> samples,
                   int label)
Parameters:
samples - Vector of sample files
label - ground truth labels for the input images
Returns:
numbers of right and wrong classified images

train

private void train()
the actual svm training