bodhidharma.classifiers.genetic_algorithms
Class ClassifierWeightingEvaluator

java.lang.Object
  extended by bodhidharma.classifiers.genetic_algorithms.Evaluator
      extended by bodhidharma.classifiers.genetic_algorithms.ClassifierWeightingEvaluator

public class ClassifierWeightingEvaluator
extends Evaluator

Objects of this class evaluate and interpret the meaning of bit strings stored in genetic algorithm Chromosome objects. Each bit in the bit string represents part of the representation of a double. Each double represents the weighting for a classifier. The fitness value is calculated by performing a combined classification using the bit string's weighting for all of the classifiers.

See Also:
Chromosome, Breeder

Field Summary
 
Fields inherited from class bodhidharma.classifiers.genetic_algorithms.Evaluator
bit_string_length
 
Constructor Summary
ClassifierWeightingEvaluator(double[][][] test_classifier_results, int[][] correct_classifications, boolean[] ensemble_selection, int number_categories, int bits_per_weight, ClassificationResultsInterpereter results_interpereter)
          Basic constructor.
 
Method Summary
 double getFitness(short[] bit_string)
          Return the fitness of a chromosome given its DNA (bit string).
 java.lang.Object[] parseBitString(short[] bit_string)
          Returns an array of Doubles holding the meaning of the given bit string of a Chromosome.
 
Methods inherited from class bodhidharma.classifiers.genetic_algorithms.Evaluator
getBitStringLength
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassifierWeightingEvaluator

public ClassifierWeightingEvaluator(double[][][] test_classifier_results,
                                    int[][] correct_classifications,
                                    boolean[] ensemble_selection,
                                    int number_categories,
                                    int bits_per_weight,
                                    ClassificationResultsInterpereter results_interpereter)
Basic constructor.

Parameters:
test_classifier_results - Test classifier result values that will be classified to test performance. First indice indicates classifier, second indice indicates recording and third indice indicates category. Value of 1 for first indice corresponds to single-dimensional feature classifier. Is null if this classifier not used.
correct_classifications - Model classifications of test_classifier_results. First indice indicates recording. Entries indicate the indices of the categories that are correct classifications.
ensemble_selection - Whether or not each of the classifiers is a candidate for weighting. Weights for values of false are automatically set to 0.
number_categories - The possible number of categories into which recordings can be classified.
bits_per_weight - Number of bits used to represent each weighting. More bits means a greater variety of possible values.
results_interpereter - Used to perform actual classifications so that fitnesses can be performed. Default fitness will be used if null.
Method Detail

getFitness

public double getFitness(short[] bit_string)
                  throws java.lang.Exception
Return the fitness of a chromosome given its DNA (bit string). The fitness should vary between 0 (least fit possible) and 1 (most fit possible). Bit strings passed to this method must be of the same length as the length specified in the constructor of this object.

The fitness is calculated for each recording and category, and then averaged over all recordings.

There are two ways of calculating fitness. The first is used if the results_interpereter field is not null, and the second if it is null. The first way gives a fitness based on the fraction of correct classifications based on the given bit_string.

The alternative fitness for each recording is set equal to the sum of the normalized scores returned by the classifier for those categories to which the recording belongs.

If previous feature selection set a classifier to not be used, its weighting is interepereted as 0, irregardless of what it actually is, and its value is changed to 0 in the bit string. This is done by parseBitString method.

Throws an exception if there is a problem with the classification or if the length of the bit_string is not equal to the length of the bit_string_length field.

Specified by:
getFitness in class Evaluator
Throws:
java.lang.Exception

parseBitString

public java.lang.Object[] parseBitString(short[] bit_string)
                                  throws java.lang.Exception
Returns an array of Doubles holding the meaning of the given bit string of a Chromosome. These values represent feature weightings and fall between 0 and 1. These values are normalized accross the array.

If previous classifier selection set a classifier to not be used, its weighting is interepereted as 0, irregardless of what it actually is, and its value is changed to 0 in the bit string.

If all of the weightings are 0 for the given bit_string, one of the weightings selected by previous classifier selection is randomly chosen to be set to the maximum weighting.

Throws an exception if the length of the bit_string is not equal to the length of the bit_string_length field or if it is not evenly divisible by the word length.

Specified by:
parseBitString in class Evaluator
Throws:
java.lang.Exception