Module for Individual with binary encoding.

class gaft.components.binary_individual.BinaryIndividual(ranges, eps=0.001)

Bases: gaft.components.individual.IndividualBase

Class for individual in population. Random solution will be initialized by default.

  • ranges (tuple list) – value ranges for all entries in solution.
  • eps (float or float list (with the same length with ranges)) – decrete precisions for binary encoding, default is 0.001.
static binarize(decimal, eps, length)

Helper function to convert a float to binary sequence.

  • decimal (float) – the decimal number to be converted
  • eps (float) – the decrete precision of binary sequence
  • length (int) – the length of binary sequence.

Clone a new individual from current one.

static decimalize(binary, eps, lower_bound)

Helper function to convert a binary sequence back to decimal number.

  • binary (list of int) – The binary list to be converted
  • eps (float) – the decrete precision of binary sequence
  • lower_bound (float) – the lower bound for decimal number

Decode gene sequence to solution of target function.


Encode solution to gene sequence in individual using different encoding.

init(chromsome=None, solution=None)

Initialize the individual by providing chromsome or solution.

  • chromsome (list of (float / int)) – chromesome sequence for the individual
  • solution (list of float) – the variable vector of the target function.


If both chromsome and solution are provided, only the chromsome would be used. If neither is provided, individual would be initialized randomly.