geneticengine.grammar.metahandlers.vars
Attributes
Classes
VarRange([a, b, c]) represents the alternative between a, b, and c. |
|
VarRangeWithProbabilities([a, b, c], [pa, pb, pc]) represents the |
Module Contents
- geneticengine.grammar.metahandlers.vars.T
- class geneticengine.grammar.metahandlers.vars.VarRange(options)
Bases:
geneticengine.grammar.metahandlers.base.MetaHandlerGeneratorVarRange([a, b, c]) represents the alternative between a, b, and c.
The list of options can be dynamically altered before the grammar extraction with something like Var.__init__.__annotations__[“name”] = Annotated[str, VarRange([d, e, f])]. The option list must not be empty.
- Parameters:
options (list[T])
- options
- validate(v)
- Return type:
bool
- generate(random, grammar, base_type, rec, dependent_values, parent_values)
Generates an instance of type base_type, according to some criterion.
- Parameters:
r (Source) – Random source for generation
g (Grammar) – Grammar to follow in the generation :param Callable[[int, Type], Any] rec: The method to generate a new instance of type and maximum depth d
depth (int) – the current depth budget
base_type (Type) – The inner type being annotated
argname (str) – The name of the field of the parent object which is being generated :param Dict[str, Type] context: The names and types of all fields in the parent object :param Dict[str, Type] dependent_values: The names and values of all previous fields in the parent object
grammar (geneticengine.grammar.grammar.Grammar)
rec (Callable[[type[T]], T])
dependent_values (dict[str, Any])
parent_values (list[dict[str, Any]])
- __repr__()
- classmethod __class_getitem__(args)
- iterate(base_type, combine_lists, rec, dependent_values)
- Parameters:
base_type (type)
combine_lists (Callable[[list[type]], Generator[Any, Any, Any]])
rec (Any)
dependent_values (dict[str, Any])
- class geneticengine.grammar.metahandlers.vars.VarRangeWithProbabilities(options, probabilities)
Bases:
geneticengine.grammar.metahandlers.base.MetaHandlerGeneratorVarRangeWithProbabilities([a, b, c], [pa, pb, pc]) represents the alternative between a, b, and c with the given probabilities.
The options list must not be empty and the probabilities list must have the same length as options. Probabilities can be any non-negative numbers and are interpreted as weights.
- Parameters:
options (list[T])
probabilities (list[float])
- options
- probabilities
- validate(v)
- Return type:
bool
- generate(random, grammar, base_type, rec, dependent_values, parent_values)
Generates an instance of type base_type, according to some criterion.
- Parameters:
r (Source) – Random source for generation
g (Grammar) – Grammar to follow in the generation :param Callable[[int, Type], Any] rec: The method to generate a new instance of type and maximum depth d
depth (int) – the current depth budget
base_type (Type) – The inner type being annotated
argname (str) – The name of the field of the parent object which is being generated :param Dict[str, Type] context: The names and types of all fields in the parent object :param Dict[str, Type] dependent_values: The names and values of all previous fields in the parent object
grammar (geneticengine.grammar.grammar.Grammar)
rec (Callable[[type[T]], T])
dependent_values (dict[str, Any])
parent_values (list[dict[str, Any]])
- __repr__()
- classmethod __class_getitem__(args)
- iterate(base_type, combine_lists, rec, dependent_values)
- Parameters:
base_type (type)
combine_lists (Callable[[list[type]], Generator[Any, Any, Any]])
rec (Any)
dependent_values (dict[str, Any])