FunctionSlot – function slots module

The function slot concept is large used by Pyevolve, the idea is simple, each genetic operator or any operator, can be assigned to a slot, by this way, we can add more than simple one operator, we can have for example, two or more mutator operators at same time, two or more evaluation functions, etc. In this FunctionSlot module, you’ll find the class FunctionSlot.FunctionSlot, which is the slot class.

class FunctionSlot.FunctionSlot(name='Anonymous Function', rand_apply=False)

FunctionSlot Class - The function slot

Example:
>>> genome.evaluator.set(eval_func)
>>> genome.evaluator[0]
<function eval_func at 0x018C8930>
>>> genome.evaluator
Slot [Evaluation Function] (Count: 1)
          Name: eval_func
>>> genome.evaluator.clear()
>>> genome.evaluator
Slot [Evaluation Function] (Count: 0)
          No function
Parameters:
  • name – the slot name
  • rand_apply – if True, just one of the functions in the slot will be applied, this function is randomly picked.
add(func)

Used to add a function to the slot

Parameter:func – the function to be added in the slot
apply(index, obj, **args)

Apply the index function

Parameters:
  • index – the index of the function
  • obj – this object is passes as parameter to the function
  • args – this args dictionary is passed to the function
applyFunctions(obj, **args)

Generator to apply all function slots in obj

Parameters:
  • obj – this object is passes as parameter to the function
  • args – this args dictionary is passed to the function
clear()
Used to clear the functions in the slot
getFunction(index=0)

Return the function handle at index

Parameter:index – the index of the function
isEmpty()
Return true if the function slot is empy
set(func)

Used to clear all functions in the slot and add one

Parameter:func – the function to be added in the slot

Note

the method set of the function slot remove all previous functions added to the slot.

setRandomApply(flag=True)

Sets the random function application, in this mode, the function will randomly choose one slot to apply

Parameter:flag – True or False

Recent Blog Posts

Previous topic

DBAdapters – database adapters for statistics

Next topic

Statistics – statistical structure module

This Page