Class GeneticHelper

  • Direct Known Subclasses:
    WekaGeneticHelper

    public class GeneticHelper
    extends Object
    Helper class for bit-string related operations.
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    • Constructor Summary

      Constructors 
      Constructor Description
      GeneticHelper()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static double bitsToDouble​(String bits, double min, double max, int splits)
      Turns a bit string (0s and 1s) into a double.
      static float bitsToFloat​(String bits, double min, double max, int splits)
      Turns a bit string (0s and 1s) into a double.
      static int bitsToInt​(String bits, int min, int max)
      Turns the bit string back into an integer.
      static int[] bitsToIntArray​(String bits, int min, int max, int numBits, int size)
      Turns a bit string (0s and 1s) into an integer array.
      static String doubleToBits​(double in, double min, double max, int numBits, int splits)
      Turns a double into a bit string (0s and 1s).
      static String floatToBits​(float in, float min, float max, int numBits, int splits)
      Turns a double into a bit string (0s and 1s).
      static String intArrayToBits​(int[] ina, int min, int max, int numBits)
      Creates a bit string (0s and 1s) from an integer array.
      static String intToBits​(int in, int min, int max, int numBits)
      Turns an integer into a bitstring (0s and 1s).
    • Constructor Detail

      • GeneticHelper

        public GeneticHelper()
    • Method Detail

      • bitsToInt

        public static int bitsToInt​(String bits,
                                    int min,
                                    int max)
        Turns the bit string back into an integer.
        Parameters:
        bits - the bit string (0s and 1s)
        min - the minimum
        max - the maximum
        Returns:
        the integer
      • intToBits

        public static String intToBits​(int in,
                                       int min,
                                       int max,
                                       int numBits)
        Turns an integer into a bitstring (0s and 1s).
        Parameters:
        in - the integer to convert
        min - the minimum
        max - the maximum
        numBits - the number of bits
        Returns:
        the bit string
      • bitsToIntArray

        public static int[] bitsToIntArray​(String bits,
                                           int min,
                                           int max,
                                           int numBits,
                                           int size)
        Turns a bit string (0s and 1s) into an integer array.
        Parameters:
        bits - the string
        min - the minimum
        max - the maximum
        numBits - the number of bits
        size - the size of the array
        Returns:
        the reconstructed integer array
      • intArrayToBits

        public static String intArrayToBits​(int[] ina,
                                            int min,
                                            int max,
                                            int numBits)
        Creates a bit string (0s and 1s) from an integer array.
        Parameters:
        ina - the integer array
        min - the minimum
        max - the maximum
        numBits - the number of bits
        Returns:
        the bit string
      • bitsToDouble

        public static double bitsToDouble​(String bits,
                                          double min,
                                          double max,
                                          int splits)
        Turns a bit string (0s and 1s) into a double.
        Parameters:
        bits - the bit string
        min - the minimum
        max - the maximum
        splits - the number of splits
        Returns:
        the reconstructed double value
      • bitsToFloat

        public static float bitsToFloat​(String bits,
                                        double min,
                                        double max,
                                        int splits)
        Turns a bit string (0s and 1s) into a double.
        Parameters:
        bits - the bit string
        min - the minimum
        max - the maximum
        splits - the number of splits
        Returns:
        the reconstructed double value
      • doubleToBits

        public static String doubleToBits​(double in,
                                          double min,
                                          double max,
                                          int numBits,
                                          int splits)
        Turns a double into a bit string (0s and 1s).
        Parameters:
        in - the double value
        min - the minimum
        max - the maximum
        numBits - the number of bits
        splits - the number of splits
        Returns:
        the generated bit string
      • floatToBits

        public static String floatToBits​(float in,
                                         float min,
                                         float max,
                                         int numBits,
                                         int splits)
        Turns a double into a bit string (0s and 1s).
        Parameters:
        in - the double value
        min - the minimum
        max - the maximum
        numBits - the number of bits
        splits - the number of splits
        Returns:
        the generated bit string