pg.geno.Choices

Accessible via pg.geno.Choices.

class Choices(num_choices=1, candidates=MISSING_VALUE, literal_values=None, distinct=True, sorted=False, subchoice_index=None, hints=None, location=, name=None)[source]

Bases: pg.geno.DecisionPoint

Represents a single or multiple choices from a list of candidates.

Example:

# Create a single choice with a nested subspace for candidate 2 (0-based).
pg.geno.oneof([
    pg.geno.constant(),
    pg.geno.constant(),
    pg.geno.space([
        pg.geno.floatv(0.1, 1.0)
        pg.geno.manyof(2, [
            pg.geno.constant(),
            pg.geno.constant(),
            pg.geno.constant()
        ])
    ])
])

See also: pg.geno.oneof, pg.geno.manyof.

Methods:

candidate_index(choice_value)

Returns the candidate index of a choice value.

format([compact, verbose, root_indent, show_id])

Format this object.

format_candidate(index[, display_format])

Get a formatted candidate value by index.

subchoice(index)

Returns spec for choice i.

validate(dna)

Validate whether a DNA value conforms to this spec.

Attributes:

choice_specs

Returns all choice specs.

decision_points

Returns all decision points in their declaration order.

is_categorical

Returns True if current node is a categorical choice.

is_custom_decision_point

Returns True if current node is a custom decision point.

is_numerical

Returns True if current node is numerical decision.

is_subchoice

Returns if current choice is a subchoice of a multi-choice.

space_size

Returns the search space size.

candidate_index(choice_value)[source]

Returns the candidate index of a choice value.

Return type:

int

Parameters:

choice_value – Choice value can be: a (integer, float or string) as a candidate’s literal value, or a text in the format “<index>/<num_candidates>” or a text in the format “<index>/<num_candidates> (<literal>)”.

Returns:

The index of chosen candidate.

Raises:
  • ValueErrorchoice_value is not a valid index or it does not matches

  • any candidate's literal value.

property choice_specs: List[Choices][source]

Returns all choice specs.

property decision_points: List[DecisionPoint][source]

Returns all decision points in their declaration order.

Returns:

All decision points in current space. For multi-choices, the sub-choice objects will be returned. Users can call spec.parent_choice to access the parent multi-choice node.

format(compact=True, verbose=True, root_indent=0, show_id=True, **kwargs)[source]

Format this object.

format_candidate(index, display_format='choice_and_literal')[source]

Get a formatted candidate value by index.

Return type:

Union[str, int, float]

Parameters:
  • index – The index of the candidate to format.

  • display_format – One of ‘choice’, ‘literal’ and ‘choice_and_literal’ as the output format for human consumption.

Returns:

A int, float or string that represent the candidate based on the

display format.

property is_categorical: bool[source]

Returns True if current node is a categorical choice.

property is_custom_decision_point: bool[source]

Returns True if current node is a custom decision point.

property is_numerical: bool[source]

Returns True if current node is numerical decision.

property is_subchoice: bool[source]

Returns if current choice is a subchoice of a multi-choice.

property space_size: int[source]

Returns the search space size.

subchoice(index)[source]

Returns spec for choice i.

Return type:

pg.geno.Choices

validate(dna)[source]

Validate whether a DNA value conforms to this spec.

Return type:

None