This is the utility module, with some utility functions of general use, like list item swap, random utilities and etc.
An accumulator for the Root Mean Square Error (RMSE) and the Mean Square Error (MSE)
Add value to the accumulator
Parameters: |
|
---|
Return the mean square error
Return type: | float MSE |
---|
Return the root mean square error
Return type: | float RMSE |
---|
Get the edges of a G1DList individual
Parameter: | individual – the G1DList individual |
---|---|
Return type: | the edges dictionary |
Get the edges and the merge between the edges of two G1DList individuals
Parameters: |
|
---|---|
Return type: | a tuple (mom edges, dad edges, merge) |
Get the merge between the two individual edges
Parameters: |
|
---|---|
Return type: | the merged dictionary |
The Graph class
>>> g = Graph()
>>> g.addEdge("a", "b")
>>> g.addEdge("b", "c")
>>> for node in g:
... print node
a
b
c
New in version 0.6: The Graph class.
Add an edge between two nodes, if the nodes doesn’t exists, they will be created
Parameters: |
|
---|
Add the node
Parameter: | node – the node to add |
---|
Returns the neighbors of the node
Parameter: | node – the node |
---|
Returns all the current nodes on the graph
Return type: | the list of nodes |
---|
Compares two individual raw scores
>>> GPopulation.cmp_individual_raw(a, b)
Parameters: |
|
---|---|
Return type: | 0 if the two individuals raw score are the same, -1 if the B individual raw score is greater than A and 1 if the A individual raw score is greater than B. |
Note
this function is used to sorte the population individuals
Compares two individual fitness scores, used for sorting population
>>> GPopulation.cmp_individual_scaled(a, b)
Parameters: |
|
---|---|
Return type: | 0 if the two individuals fitness score are the same, -1 if the B individual fitness score is greater than A and 1 if the A individual fitness score is greater than B. |
Note
this function is used to sorte the population individuals
This function will import the name module, if fails, it will raise an ImportError exception and a message
Parameter: | name – the module name |
---|---|
Return type: | the module object |
New in version 0.6: The import_special function
Swaps elements A and B in a 2D list (matrix).
>>> l = [ [1,2,3], [4,5,6] ]
>>> Util.list2DSwapElement(l, (0,1), (1,1) )
>>> l
[[1, 5, 3], [4, 2, 6]]
Parameters: |
|
---|---|
Return type: | None |
Swaps elements A and B in a list.
>>> l = [1, 2, 3]
>>> Util.listSwapElement(l, 1, 2)
>>> l
[1, 3, 2]
Parameters: |
|
---|---|
Return type: | None |
Raise an exception and logs the message.
>>> Util.raiseException('The value is not an integer', ValueError)
Parameters: |
|
---|---|
Return type: | None |
Returns True with the p probability. If the p is 1.0, the function will always return True, or if is 0.0, the function will return always False.
>>> Util.randomFlipCoin(1.0)
True
Parameter: | p – probability, between 0.0 and 1.0 |
---|---|
Return type: | True or False |