geneticengine.grammar.metahandlers.ints

Attributes

min

max

T

Classes

IntRange

IntRange(a,b) restricts ints to be between a and b.

IntervalRange

This metahandler restricts the creation of ranges between two integers

Module Contents

geneticengine.grammar.metahandlers.ints.min
geneticengine.grammar.metahandlers.ints.max
geneticengine.grammar.metahandlers.ints.T
class geneticengine.grammar.metahandlers.ints.IntRange(min, max)

Bases: geneticengine.grammar.metahandlers.base.MetaHandlerGenerator

IntRange(a,b) restricts ints to be between a and b.

The range can be dynamically altered before the grammar extraction Int.__init__.__annotations__[“value”] = Annotated[int, IntRange(c,d)]

min
max
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

  • random (geneticengine.random.sources.RandomSource)

  • grammar (geneticengine.grammar.grammar.Grammar)

  • rec (Callable[[type[T]], T])

  • dependent_values (dict[str, Any])

  • parent_values (list[dict[str, Any]])

validate(v)
Return type:

bool

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])

classmethod __class_getitem__(args)
__repr__()
class geneticengine.grammar.metahandlers.ints.IntervalRange(minimum_length, maximum_length, maximum_top_limit)

Bases: geneticengine.grammar.metahandlers.base.MetaHandlerGenerator

This metahandler restricts the creation of ranges between two integers by forcing a minimum and maximum range size, as well as a top limit that the range can reach.

This is useful in genomics to generate random windows of variable size to scan an input sequence

Parameters:
  • minimum_length (int) – Minimum length possible when randomly generating the range

  • maximum_length (int) – Maximum length possible when randomly generating the range

  • maximum_top_limit (int) – Maximum value the range can reach

minimum_length
maximum_length
maximum_top_limit
classmethod __class_getitem__(args)
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

  • random (geneticengine.random.sources.RandomSource)

  • grammar (geneticengine.grammar.grammar.Grammar)

  • rec (Callable[[type[T]], T])

  • dependent_values (dict[str, Any])

  • parent_values (list[dict[str, Any]])

validate(v)
Return type:

bool

iterate(base_type, combine_lists)
Parameters:
  • base_type (type)

  • combine_lists (Callable[[list[type]], Generator[Any, Any, Any]])