bodhidharma.classifiers.genetic_algorithms
Class FeatureSelectionEvaluator

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

public class FeatureSelectionEvaluator
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 the on (1) or off (0) setting of a feature. Features with an on setting are used for classification and feautres with an off are not used in classification. This Evaluator is used for feature selection. The fitness value is calculated by performing a classification using a KNN classifier.

See Also:
KNN, Chromosome, Breeder

Field Summary
 
Fields inherited from class bodhidharma.classifiers.genetic_algorithms.Evaluator
bit_string_length
 
Constructor Summary
FeatureSelectionEvaluator(KNN knn_classifier, double[][] feature_values, int[][] classifications, 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 Booleans 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

FeatureSelectionEvaluator

public FeatureSelectionEvaluator(KNN knn_classifier,
                                 double[][] feature_values,
                                 int[][] classifications,
                                 ClassificationResultsInterpereter results_interpereter)
                          throws java.lang.Exception
Basic constructor. The knn_classifier must be trained with training points, but its features_to_use and feature_weights parameters should be untrained (i.e. null). The order of the features and categories passed in the feature_values and classifications parameters must be consistent with those that were used to train the knn_classifier externally.

Throws an exception if the feature_values or classifications parameters are of improper sizes.

Parameters:
knn_classifier - Trained KNN classifier used to evaluate the fitness of DNA.
feature_values - Test feature values that will be classified to test performance. First indice indicates recording and second indicates feature.
classifications - Model classifications of feature_values. First indice indicates recording. Entries indicate the indices of the categories that are correct classifications.
results_interpereter - Used to perform actual classifications so that fitnesses can be performed. Default fitness will be used if null.
Throws:
java.lang.Exception
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). This need not be normalized. 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 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.

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 Booleans holding the meaning of the given bit string of a Chromosome. Values of 1 in the given bit_string are set to true and values of 0 are set to false. There is one element in the returned array for each bit in the bit_string. Bit strings passed to this method should be of the same length as the length specified in the constructor of this object.

Throws an exception if the length of the bit_string is not equal to the length of the bit_string_length> field.

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