bodhidharma.classifiers.genetic_algorithms
Class FeatureWeightingEvaluator

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

public class FeatureWeightingEvaluator
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 feature. This Evaluator is used for finding a good feature weighting. 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
FeatureWeightingEvaluator(KNN knn_classifier, double[][] feature_values, int[][] classifications, int bits_per_value, 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

FeatureWeightingEvaluator

public FeatureWeightingEvaluator(KNN knn_classifier,
                                 double[][] feature_values,
                                 int[][] classifications,
                                 int bits_per_value,
                                 ClassificationResultsInterpereter results_interpereter)
                          throws java.lang.Exception
Basic constructor. The knn_classifier must be trained with training points, but its feature_weights parameter 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.
bits_per_value - 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.
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.

If previous feature selection set a feature 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. If previous feature selection set a feature 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.

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