Skip to content

pygx.algo.evolution.selectors

Common selectors for evolutionary algorithms.

selectors

Common selectors for evolutionary algorithms.

Random

Random(n: int | float | None = None, **kwargs)

Bases: Selector

Random N selector.

Source code in pygx/algo/evolution/_selectors.py
def __init__(self, n: int | float | None = None, **kwargs):
    super().__init__(**dict(n=n), **kwargs)

Sample

Sample(
    n: int | float | None = None,
    weights: Operation | Callable[..., list[float]] | None = None,
    **kwargs
)

Bases: Selector

Sample N items from a weighting function.

Source code in pygx/algo/evolution/_selectors.py
def __init__(
    self,
    n: int | float | None = None,
    weights: 'base.Operation | Callable[..., list[float]] | None' = None,
    **kwargs,
):
    super().__init__(**dict(n=n, weights=weights), **kwargs)

Proportional

Proportional(
    n: int | float | None = None,
    weights: Operation | Callable[..., list[float]] | None = None,
    **kwargs
)

Bases: Selector

Select N items proportional to the input weights.

Source code in pygx/algo/evolution/_selectors.py
def __init__(
    self,
    n: int | float | None = None,
    weights: 'base.Operation | Callable[..., list[float]] | None' = None,
    **kwargs,
):
    super().__init__(**dict(n=n, weights=weights), **kwargs)

Top

Top(n: int | float | None = None, **kwargs)

Bases: Selector

Top N selector.

Source code in pygx/algo/evolution/_selectors.py
def __init__(self, n: int | float | None = None, **kwargs):
    super().__init__(**dict(n=n), **kwargs)

Bottom

Bottom(n: int | float | None = None, **kwargs)

Bases: Selector

Bottom N selector.

Source code in pygx/algo/evolution/_selectors.py
def __init__(self, n: int | float | None = None, **kwargs):
    super().__init__(**dict(n=n), **kwargs)

First

First(n: int | float | None = None, **kwargs)

Bases: Selector

First N selector.

Source code in pygx/algo/evolution/_selectors.py
def __init__(self, n: int | float | None = None, **kwargs):
    super().__init__(**dict(n=n), **kwargs)

Last

Last(n: int | float | None = None, **kwargs)

Bases: Selector

Last N selector.

Source code in pygx/algo/evolution/_selectors.py
def __init__(self, n: int | float | None = None, **kwargs):
    super().__init__(**dict(n=n), **kwargs)

num_output_spec

num_output_spec()

Returns the value spec for the number of elements in the output.

Source code in pygx/algo/evolution/_selectors.py
def num_output_spec():
    """Returns the value spec for the number of elements in the output."""
    return scalars.scalar_spec(
        pg.typing.Union(
            [
                pg.typing.Int(min_value=0),  # Output count.
                pg.typing.Float(
                    min_value=0.0, max_value=1.0
                ),  # Output proportion.
            ]
        )
    ).noneable()

compute_num_output

compute_num_output(n: int | float | None, num_inputs: int, step: int) -> int

Returns the number of output.

Source code in pygx/algo/evolution/_selectors.py
def compute_num_output(
    n: int | float | None, num_inputs: int, step: int
) -> int:
    """Returns the number of output."""
    n = scalars.scalar_value(n, step)
    if isinstance(n, float):
        n = math.ceil(n * num_inputs)
    elif n is None:
        n = num_inputs
    return n

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