geneticengine.grammar.metahandlers.strings

Attributes

T

Classes

StringSizeBetween

StringSizeBetween(a,b) restricts strings to be of length between a and b

WeightedStringHandler

This metahandler restricts the creation of string nodes so that the

Module Contents

geneticengine.grammar.metahandlers.strings.T
class geneticengine.grammar.metahandlers.strings.StringSizeBetween(min, max, options=string.ascii_letters + string.digits)

Bases: geneticengine.grammar.metahandlers.base.MetaHandlerGenerator

StringSizeBetween(a,b) restricts strings to be of length between a and b and implements a special list mutation.

The range can be dynamically altered before the grammar extraction

X.__annotations__[“y”] = Annotated[List[Type], ListSizeBetween(c,d)].

The special string mutation entails three different alterations to the list in question: deletion of a random element;

addition of a random element; and replacement of a random element.

min
max
options = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',...
validate(v)
Return type:

bool

generate(random, grammar, base_type, rec, dependent_values, parent_values)
Parameters:
Return type:

Any

mutate(r, g, random_node, depth, base_type, current_node)
Parameters:
crossover(r, g, options, arg, list_type, current_node)
Parameters:
classmethod __class_getitem__(args)
__repr__()
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.strings.WeightedStringHandler(matrix, alphabet)

Bases: geneticengine.grammar.metahandlers.base.MetaHandlerGenerator

This metahandler restricts the creation of string nodes so that the output complies with a given alphabet and a matrix of probabilities for each position.

Each row on the matrix should reflect the probability of each character in that position. Thus, the number of cols in the input matrix should be the same as the number of characters in the alphabet.

This refinement will return a string with a size == nrows in the matrix

probability_matrix
alphabet
validate(v)
Return type:

bool

generate(random, grammar, base_type, rec, dependent_values, parent_values)
Parameters:
Return type:

str

__repr__()
classmethod __class_getitem__(args)
iterate(base_type, combine_lists)
Parameters:
  • base_type (type)

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