Skip to content

pygx.algo.evolution.where

Interfaces and utilities for decision point selection.

where

Interfaces and utilities for decision point selection.

DecisionPointFilter

Bases: Object

Base class for decision point filter.

A decision point filter is used for deciding which decision points should be included during recombination and mutation. It takes a list of decision points as the candidates for filtering, and returns a list of decision points as the target that evolutionary operations should work on.

call abstractmethod

call(
    decision_points: list[DecisionPoint],
    global_state: AttributeDict | None = None,
    step: int = 0,
) -> list[DecisionPoint]

Implementation of filtering logic. Subclass to override.

Parameters:

Name Type Description Default
decision_points list[DecisionPoint]

A list of decision points as candidates for filtering.

required
global_state AttributeDict | None

An optional keyword argument as the global state.

None
step int

An optional keyword argument as current step of evolution.

0

Returns:

Type Description
list[DecisionPoint]

A list of decision points that should be kept.

Source code in pygx/algo/evolution/_where.py
@abc.abstractmethod
def call(
    self,
    decision_points: list[pg.geno.DecisionPoint],
    global_state: pg.geno.AttributeDict | None = None,
    step: int = 0,
) -> list[pg.geno.DecisionPoint]:
    """Implementation of filtering logic. Subclass to override.

    Args:
      decision_points: A list of decision points as candidates for filtering.
      global_state: An optional keyword argument as the global state.
      step: An optional keyword argument as current step of evolution.

    Returns:
      A list of decision points that should be kept.
    """

Lambda

Lambda(fn: Callable[[list[DecisionPoint]], list[DecisionPoint]], **kwargs)

Bases: DecisionPointFilter

Decision point filter that is converted from a callable object.

Source code in pygx/algo/evolution/_where.py
def __init__(
    self,
    fn: typing.Callable[
        [list[pg.geno.DecisionPoint]], list[pg.geno.DecisionPoint]
    ],
    **kwargs,
):
    super().__init__(**dict(fn=fn), **kwargs)

All

Bases: DecisionPointFilter

Include all decision points.

Any

Any(k: int | Callable[[int], int] = 1, **kwargs)

Bases: DecisionPointFilter

Include any K (1 by default) decision point(s).

Source code in pygx/algo/evolution/_where.py
def __init__(self, k: int | typing.Callable[[int], int] = 1, **kwargs):
    super().__init__(**dict(k=k), **kwargs)

where_spec

where_spec(default=ALL) -> ValueSpec

Returns the value spec for a decision point filter.

Source code in pygx/algo/evolution/_where.py
def where_spec(default=ALL) -> pg.typing.ValueSpec:
    """Returns the value spec for a decision point filter."""
    # `ALL` / `ANY` are module-level singletons handed to EVERY operation
    # that does not override `where`, so the second such hold would trip
    # rule 2. Reference them instead of copying: both are immutable in
    # practice (`All` is stateless; `ANY` keeps its defaults), so one shared
    # node is correct — and it saves a filter copy per operation. The ref
    # wraps the DEFAULT here rather than the exported name, which stays a
    # plain callable filter for direct use.
    return pg.typing.Object(DecisionPointFilter, default=pg.Ref(default))

options: show_root_heading: false show_root_toc_entry: false members_order: source heading_level: 2