This module have the class which every representation extends, if you are planning to create a new representation, you must take a inside look into this module.
G1DBase Class - The base class for 1D chromosomes
| Parameter: | size – the 1D list size |
|---|
New in version 0.6: Added te G1DBase class
Appends an item to the end of the list
>>> genome.append(44)
| Parameter: | value – value to be added |
|---|
Copy genome to ‘g’
>>> genome_origin.copy(genome_destination)
| Parameter: | g – the destination instance |
|---|
Returns the internal list of the genome
... note:: this method was created to solve performance issues :rtype: the internal list
Returns the list supposed size
Warning
this is different from what the len(obj) returns
Removes an item from the list
>>> genome.remove(44)
| Parameter: | value – value to be added |
|---|
Assigns a list to the internal list of the chromosome
| Parameter: | lst – the list to assign the internal list of the chromosome |
|---|
GTreeBase Class - The base class for the tree genomes
| Parameter: | root_node – the root node of the tree |
|---|
New in version 0.6: Added te GTreeBase class
Clone this GenomeBase
| Return type: | the clone genome |
|---|
Note
If you are planning to create a new chromosome representation, you must implement this method on your class.
Copy the current contents GTreeBase to ‘g’
| Parameter: | g – the destination GTreeBase tree |
|---|
Note
If you are planning to create a new chromosome representation, you must implement this method on your class.
Return a new list with all nodes
| Return type: | the list with all nodes |
|---|
Return the tree height
| Return type: | the tree height |
|---|
Returns the depth of a node
| Return type: | the depth of the node, the depth of root node is 0 |
|---|
Returns the height of a node
Note
If the node has no childs, the height will be 0.
| Return type: | the height of the node |
|---|
Return the number of the nodes on the tree starting at the start_node, if start_node is None, then the method will count all the tree nodes.
| Return type: | the number of nodes |
|---|
Returns a random node from the Tree
| Parameter: | node_type – 0 = Any, 1 = Leaf, 2 = Branch |
|---|---|
| Return type: | random node |
Return the tree root node
| Return type: | the tree root node |
|---|
Returns a tree-formated string of the tree. This method is used by the __repr__ method of the tree
| Return type: | a string representing the tree |
|---|
Sets the root of the tree
| Parameter: | root – the tree root node |
|---|
Traversal the tree, this method will call the user-defined callback function for each node on the tree
| Parameters: |
|
|---|
GTreeNodeBase Class - The base class for the node tree genomes
| Parameters: |
|
|---|
New in version 0.6: Added te GTreeNodeBase class
Adds a child to the node
| Parameter: | child – the node to be added |
|---|
Clone this GenomeBase
| Return type: | the clone genome |
|---|
Note
If you are planning to create a new chromosome representation, you must implement this method on your class.
Copy the current contents GTreeNodeBase to ‘g’
| Parameter: | g – the destination node |
|---|
Note
If you are planning to create a new chromosome representation, you must implement this method on your class.
Returns the index-child of the node
| Return type: | child node |
|---|
Return the childs of the node
Warning
use .getChilds()[:] if you’ll change the list itself, like using childs.reverse(), otherwise the original genome child order will be changed.
| Return type: | a list of nodes |
|---|
Get the parent node of the node
| Return type: | the parent node |
|---|
Return True if the node is a leaf
| Return type: | True or False |
|---|
Replaces a child of the node
| Parameters: |
|
|---|
Sets the parent of the node
| Parameter: | parent – the parent node |
|---|
GenomeBase Class - The base of all chromosome representation
Clone this GenomeBase
| Return type: | the clone genome |
|---|
Note
If you are planning to create a new chromosome representation, you must implement this method on your class.
Copy the current GenomeBase to ‘g’
| Parameter: | g – the destination genome |
|---|
Note
If you are planning to create a new chromosome representation, you must implement this method on your class.
This is the reproduction function slot, the crossover. You can change the default crossover method using:
genome.crossover.set(Crossovers.G1DListCrossoverUniform)
Called to evaluate genome
| Parameter: | args – this parameters will be passes to the evaluator |
|---|
This is the evaluation function slot, you can add a function with the set method:
genome.evaluator.set(eval_func)
Get the Fitness Score of the genome
| Return type: | genome fitness score |
|---|
Gets an internal parameter
>>> genome.getParam("rangemax")
100
Note
All the individuals of the population shares this parameters and uses the same instance of this dict.
| Parameters: |
|
|---|
Get the Raw Score of the genome
| Return type: | genome raw score |
|---|
This is the initialization function of the genome, you can change the default initializator using the function slot:
genome.initializator.set(Initializators.G1DListInitializatorAllele)
In this example, the initializator Initializators.G1DListInitializatorAllele() will be used to create the initial population.
Called to initialize genome
| Parameter: | args – this parameters will be passed to the initializator |
|---|
Called to mutate the genome
| Parameter: | args – this parameters will be passed to the mutator |
|---|---|
| Return type: | the number of mutations returned by mutation operator |
This is the mutator function slot, you can change the default mutator using the slot set function:
genome.mutator.set(Mutators.G1DListMutatorSwap)
Set the internal params
>>> genome.setParams(rangemin=0, rangemax=100, gauss_mu=0, gauss_sigma=1)
Note
All the individuals of the population shares this parameters and uses the same instance of this dict.
| Parameter: | args – this params will saved in every chromosome for genetic op. use |
|---|