geneticWedge.gp
Class Utils

java.lang.Object
  extended by geneticWedge.gp.Utils

public final class Utils
extends java.lang.Object

Utils contains a number of static methods of use to various members of the gp package.


Constructor Summary
Utils()
           
 
Method Summary
static java.awt.geom.Point2D.Double[] getAllROCCoordinates(double[] outputs, double[] targetOutputs)
          This method is used in calculating AUROC values.
static double getAUROC(double[] outputs, double[] targetOutputs)
          Calculates and returns the Area under the ROC curve (AUROC) during a classification task, using all of the provided data.
static int getDepth(java.util.Vector<Component> nodes, int index)
          This method returns the depth of the node represented by index
static double getDistance(Individual ind1, Individual ind2)
          This method returns the genotypic distance between 2 Individuals.
static double getDistance(java.util.Vector<Component> nodes1, java.util.Vector<Component> nodes2)
          This method returns the genotypic distance between 2 component lists.
static int getEndOfFragment(java.util.Vector<Component> nodes, int startIndex)
          This method calculates the index of the last node within a subtree.
static int[] getFragmentDepths(java.util.Vector<Component> nodes, int startIndex, int finishIndex)
          This method calulates the minimum and maximum depths occurring between 2 nodes (those represented by startIndex and endIndex).
static int[] getIndicesProbabilistically(int[] initialIndices, boolean favourFirst)
          This method takes a vector of indices that are assumed to be ordered.
static int[] getIndicesProbabilistically(java.util.Vector<java.lang.Integer> initialIndices, boolean favourFirst)
          This method takes a vector of indices that are assumed to be ordered.
static java.util.Hashtable<java.lang.Integer,java.lang.Double>[] getNumberedInputs(java.util.Hashtable<java.lang.String,java.lang.Double>[] inputs, java.lang.String[] names)
           
static java.lang.String[] getOutputClasses(java.lang.String[] targetOutputs)
          Returns the unique classes avaialable from a list of class memberships, sorted into ascending (alphabetical) order.
static int[] getRandomIndices(int length)
          Returns the integers between 1 and length (inclusive) in random order.
static int[] getRandomIndices(int length, int numberOfIndices)
          Returns an array containing numberOfIndices.
static int[] ShellSortStrings(java.lang.String[] values)
          Sorts values using the Shell sort algorithm, in alphabetical order.
static int[] ShellSortValues(double[] values)
          Sorts values using the Shell sort algorithm, returning them in ascending order.
static int[] ShellSortValues(double[] values, boolean sortAscending)
          Sorts values using the Shell sort algorithm.
static double[][] stringToNumericTargets(java.lang.String[] stringTargets, java.lang.String[] targetClasses)
          Converts String representations of class membership into numeric values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utils

public Utils()
Method Detail

stringToNumericTargets

public static double[][] stringToNumericTargets(java.lang.String[] stringTargets,
                                                java.lang.String[] targetClasses)
Converts String representations of class membership into numeric values. This is needed because input values are numeric. When using a GP for classification class membership tags must therefore be converted into double values. +1 is used to indictae membership, -1 to indicate non-membership.


getEndOfFragment

public static int getEndOfFragment(java.util.Vector<Component> nodes,
                                   int startIndex)
This method calculates the index of the last node within a subtree. It is essential when performing mutation and crossover operations beacuse it allows the removal/transfer of a subtree intact, using its start and end indices.


getFragmentDepths

public static int[] getFragmentDepths(java.util.Vector<Component> nodes,
                                      int startIndex,
                                      int finishIndex)
This method calulates the minimum and maximum depths occurring between 2 nodes (those represented by startIndex and endIndex). If startIndex and endIndex are the first and last nodes within a subtree, the difference between the 2 depths is the depth of the subtree.


getDepth

public static int getDepth(java.util.Vector<Component> nodes,
                           int index)
This method returns the depth of the node represented by index


getRandomIndices

public static int[] getRandomIndices(int length,
                                     int numberOfIndices)
Returns an array containing numberOfIndices. These are selected from the numbers 1 to length without repetition. Therefore, if length < numberOfIndices null will be returned.


getRandomIndices

public static int[] getRandomIndices(int length)
Returns the integers between 1 and length (inclusive) in random order. This is useful for randomly permuting data.


ShellSortValues

public static int[] ShellSortValues(double[] values,
                                    boolean sortAscending)
Sorts values using the Shell sort algorithm. If sortAscending is true, the values will be in order from smallest to largest. The returned array contains the indices of values in the requested order.


ShellSortStrings

public static int[] ShellSortStrings(java.lang.String[] values)
Sorts values using the Shell sort algorithm, in alphabetical order. The returned array contains the indices of values in the requested order.


ShellSortValues

public static int[] ShellSortValues(double[] values)
Sorts values using the Shell sort algorithm, returning them in ascending order. The returned array contains the indices of values in order.


getIndicesProbabilistically

public static int[] getIndicesProbabilistically(java.util.Vector<java.lang.Integer> initialIndices,
                                                boolean favourFirst)
This method takes a vector of indices that are assumed to be ordered. It performs roulette wheel rank selection, with the early indices favoured if favourFirst is true. It is designed to be used for selecting several indices, for example when performing multiple-tree crossover.


getIndicesProbabilistically

public static int[] getIndicesProbabilistically(int[] initialIndices,
                                                boolean favourFirst)
This method takes a vector of indices that are assumed to be ordered. It performs roulette wheel rank selection, with the early indices favoured if favourFirst is true. It is designed to be used for selecting several indices, for example when performing multiple-tree crossover.


getOutputClasses

public static java.lang.String[] getOutputClasses(java.lang.String[] targetOutputs)
Returns the unique classes avaialable from a list of class memberships, sorted into ascending (alphabetical) order.


getDistance

public static double getDistance(Individual ind1,
                                 Individual ind2)
This method returns the genotypic distance between 2 Individuals. The trees of the 2 Individuals are overlain and identical nodes are identified starting from the root. However, once a dissimilar node has been identified, the remaining subtree is considered to be different. The distance between the Individuals is then calculated as (max-noMatches)/max, where max is the number of nodes in the larger Individual and noMatches is the number of matching nodes.


getDistance

public static double getDistance(java.util.Vector<Component> nodes1,
                                 java.util.Vector<Component> nodes2)
This method returns the genotypic distance between 2 component lists. The trees of the 2 Individuals are overlain and identical nodes are identified starting from the root. However, once a dissimilar node has been identified, the remaining subtree is considered to be different. The distance between the Individuals is then calculated as (max-noMatches)/max, where max is the number of nodes in the larger Individual and noMatches is the number of matching nodes.


getNumberedInputs

public static java.util.Hashtable<java.lang.Integer,java.lang.Double>[] getNumberedInputs(java.util.Hashtable<java.lang.String,java.lang.Double>[] inputs,
                                                                                          java.lang.String[] names)

getAUROC

public static double getAUROC(double[] outputs,
                              double[] targetOutputs)
                       throws InvalidInputSizeException
Calculates and returns the Area under the ROC curve (AUROC) during a classification task, using all of the provided data. The AUROC is a measure of the discriminatory power of a classifier.

Throws:
InvalidInputSizeException

getAllROCCoordinates

public static java.awt.geom.Point2D.Double[] getAllROCCoordinates(double[] outputs,
                                                                  double[] targetOutputs)
                                                           throws InvalidInputSizeException
This method is used in calculating AUROC values. It is a public method to enable other classes to obtain ROC coordinates to be used, for example, in visualisation.

Throws:
InvalidInputSizeException