pg.evolution.Conditional

Accessible via pg.evolution.Conditional.

class Conditional(predicate, true_op=None, false_op=None)[source]

Bases: pg.evolution.Operation

Conditional operation.

A conditional operation allows sub-operations to be applied only when a condition is met.

Example:

pg.evolution.Conditional(
  lambda x: len(x) > 10,
  true_op=Top(10))

which is equivalent to:

Top(10).if_true(lambda x: len(x) > 10)

Methods:

call(inputs, global_state[, step])

Subclasses should override this method.

call(inputs, global_state, step=0)[source]

Subclasses should override this method.

The global_state and step are optional for the subclasses’ call signature.

Return type:

List[Any]

Parameters:
  • inputs – A list of values as inputs.

  • global_state – An AttributeDict object as the global state container, which is readable/writable during the operation.

  • step – Number of examples historically proposed, which can be used for determining a cross over schedule.

Returns:

A list of values as output of current operation.