MCPcopy Create free account
hub / github.com/Notgnoshi/generative / __init__

Method __init__

generative/lsystem/grammar.py:78–93  ·  view source on GitHub ↗

Initialize a Lindenmayer-System grammar parser with the given rules. :param rules: A set of production rules. A mapping of token -> replacements.

(
        self,
        rules: MultiDict[TokenName, RuleMapping],
        ignore: Set[TokenName] = None,
        seed: int = None,
    )

Source from the content-addressed store, hash-verified

76 """
77
78 def __init__(
79 self,
80 rules: MultiDict[TokenName, RuleMapping],
81 ignore: Set[TokenName] = None,
82 seed: int = None,
83 ):
84 """Initialize a Lindenmayer-System grammar parser with the given rules.
85
86 :param rules: A set of production rules. A mapping of token -> replacements.
87 """
88 self.ignore: Set[TokenName] = ignore if ignore is not None else set()
89 self.rules: MultiDict[TokenName, RuleMapping] = rules
90
91 self.seed = seed if seed is not None else random.randint(0, 2**32 - 1)
92 np.random.seed(self.seed)
93 logger.info(f"Using random seed: {self.seed}")
94
95 def pick_rule(self, rules: List[RuleMapping], token, left_ctx, right_ctx) -> RuleMapping:
96 """Pick the right rule based off the probability values or the parametric condition."""

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected