|
QDpy
|
Learn allowed token transitions and keep variation within their support. More...
Public Member Functions | |
| supports (self, sequence) | |
| Check the length and every contiguous n-gram of a candidate. | |
| sample (self, rng) | |
| Draw a complete sequence from the empirical transition model. | |
| mutate (self, sequence, rng) | |
| Replace one interior token and reconnect the remaining suffix. | |
| crossover (self, first, second, rng) | |
| Join an interior prefix and suffix from two supported parents. | |
Learn allowed token transitions and keep variation within their support.
Fixed-length token sequences supported by an observed n-gram graph. :param corpus: Iterable of token sequences. Tokens must be hashable. :param n: Number of tokens per n-gram, including its predicted token. :param length: Length of each candidate, at least n. Sampling uses corpus transition counts, restricted to edges that can complete the required length. Mutation and crossover use a shortest context bridge, then trim or extend the tail to length. A splice that cannot be completed returns the first parent.
Definition at line 22 of file gram_elites.py.
| qdpy.algorithms.gram_elites.NGramSequenceSpace.crossover | ( | self, | |
| first, | |||
| second, | |||
| rng ) |
Join an interior prefix and suffix from two supported parents.
Return a supported child using a shortest bridge between contexts.
Definition at line 159 of file gram_elites.py.
| qdpy.algorithms.gram_elites.NGramSequenceSpace.mutate | ( | self, | |
| sequence, | |||
| rng ) |
Replace one interior token and reconnect the remaining suffix.
Return a supported child and allow unchanged offspring at dead ends.
Definition at line 144 of file gram_elites.py.
| qdpy.algorithms.gram_elites.NGramSequenceSpace.sample | ( | self, | |
| rng ) |
Draw a complete sequence from the empirical transition model.
Draw a starting context uniformly, then use viable empirical edges.
Definition at line 90 of file gram_elites.py.
| qdpy.algorithms.gram_elites.NGramSequenceSpace.supports | ( | self, | |
| sequence ) |
Check the length and every contiguous n-gram of a candidate.
Return whether the fixed-length sequence stays in the corpus graph.
Definition at line 78 of file gram_elites.py.