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

Function main

tools/random-production-rules.py:280–410  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

278
279
280def main(args):
281 logger.info("Using random seed %d", args.seed)
282 rng = np.random.default_rng(args.seed)
283
284 # F,G - Step forward while drawing
285 # f,g - Step forward without drawing
286 # -,+ - Yaw around the normal axis
287 # v,^ - Pitch around the transverse axis
288 # <,> - Roll around the longitudinal axis
289 # | - Flip orientation 180 degrees
290 # d,D - Turn drawing off, on
291 # [,] - Push, pop position and orientation onto a stack
292
293 # Pick the random distribution used for picking the LHS tokens.
294 lhs_distribution = generate_lhs_distribution(args.placeholders)
295 logger.debug("LHS Distribution: %s", lhs_distribution)
296
297 # Generate the LHS tokens
298 lhs_tokens = generate_lhs_tokens(lhs_distribution, rng)
299 logger.debug("LHS Tokens: %s", lhs_tokens)
300
301 # Pick a base random distribution used for picking the RHS tokens.
302 biases = {
303 "-": args.orientation_bias,
304 "+": args.orientation_bias,
305 "v": args.orientation_bias,
306 "^": args.orientation_bias,
307 "<": args.orientation_bias,
308 ">": args.orientation_bias,
309 "|": args.orientation_bias,
310 "[": args.branching_bias * 2,
311 "]": args.branching_bias,
312 "d": 1e-5,
313 "D": 1e-5,
314 "F": args.drawing_bias,
315 "G": args.drawing_bias,
316 "f": args.skipping_bias,
317 "g": args.skipping_bias,
318 }
319 biases.update({t: args.placeholder_bias for t in "abcehijklmnopqrstuwxyz"})
320 logger.debug("RHS biases: %s", biases)
321 rhs_distribution = generate_rhs_distribution(lhs_tokens, biases, args.temperature)
322 logger.debug("RHS Distribution: %s sum(%f)", rhs_distribution, sum(rhs_distribution.values()))
323
324 # Consider the two rules
325 # a -> aa
326 # b -> ab
327 # These rules guarantee that the resulting string expands exponentially when the rules are
328 # iteratively applied. But then consider the rules
329 # a -> a
330 # b -> a
331 # which could very conceivably be randomly generated. These particular rules will not result
332 # in a string expansion (which ultimately results in an expanding image when the rules are
333 # applied).
334 #
335 # I _think_ that as long as we guarantee each production rule contains at least two lhs_tokens
336 # in the production, we can guarantee that the resulting rule will not result in a steady state.
337 #

Callers 1

Calls 6

generate_lhs_tokensFunction · 0.85
generate_ruleFunction · 0.85
pairwiseFunction · 0.70
writeMethod · 0.45

Tested by

no test coverage detected