Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
green_belt_practice = build_lesson_plan(
"green_belt_practice",
[
LessonExercise(
lesson_name="eight_terms",
problem_count=1,
problem_fn=lambda: simplify_multiple_terms(8, powers_proability=0.85),
problem_type=MODE_SIMPLIFY_POLYNOMIAL,
mcts_sims=500,
num_observations=observations,
),
LessonExercise(
lesson_name="simplify_in_place_8_9",
problem_fn=lambda: combine_terms_in_place(8, 9),
problem_type=MODE_SIMPLIFY_POLYNOMIAL,
max_turns=5,
mcts_sims=500,
num_observations=observations,
),
LessonExercise(
lesson_name="move_then_simplify_8_9",
problem_fn=lambda: combine_terms_after_commuting(8, 9),
problem_type=MODE_SIMPLIFY_POLYNOMIAL,
max_turns=5,
mcts_sims=500,
num_observations=observations,
),
LessonExercise(
lesson_name="nine_terms",
problem_count=1,
problem_fn=lambda: simplify_multiple_terms(9, powers_proability=0.85),
problem_fn=lambda: simplify_multiple_terms(5, op=None),
problem_type=MODE_SIMPLIFY_POLYNOMIAL,
mcts_sims=purple_sims,
num_observations=64,
),
LessonExercise(
lesson_name="six_complex_terms_with_exponents",
problem_fn=lambda: simplify_multiple_terms(6, powers_proability=0.85, op=None),
problem_type=MODE_SIMPLIFY_POLYNOMIAL,
mcts_sims=purple_sims,
num_observations=64,
),
LessonExercise(
lesson_name="eight_complex_terms_with_exponents",
problem_fn=lambda: simplify_multiple_terms(8, powers_proability=0.85, op=None),
problem_type=MODE_SIMPLIFY_POLYNOMIAL,
mcts_sims=purple_sims,
num_observations=64,
),
LessonExercise(
lesson_name="ten_complex_terms_with_exponents",
problem_fn=lambda: simplify_multiple_terms(10, powers_proability=0.85, op=None),
problem_type=MODE_SIMPLIFY_POLYNOMIAL,
mcts_sims=purple_sims,
num_observations=64,
),
],
)
purple_practice_sims = 250
purple_belt_practice = build_lesson_plan(
"purple_belt_practice",
simplify_multiple_terms,
combine_terms_after_commuting,
combine_terms_in_place,
move_around_blockers_one,
move_around_blockers_two,
)
observations = 128
green_belt = build_lesson_plan(
"green_belt",
[
LessonExercise(
lesson_name="eight_terms",
problem_count=1,
problem_fn=lambda: simplify_multiple_terms(8, powers_proability=0.85),
problem_type=MODE_SIMPLIFY_POLYNOMIAL,
mcts_sims=200,
num_observations=observations,
),
LessonExercise(
lesson_name="simplify_in_place_8_9",
problem_fn=lambda: combine_terms_in_place(8, 9),
problem_type=MODE_SIMPLIFY_POLYNOMIAL,
max_turns=5,
mcts_sims=200,
num_observations=observations,
),
LessonExercise(
lesson_name="move_then_simplify_8_9",
problem_fn=lambda: combine_terms_after_commuting(8, 9),
problem_type=MODE_SIMPLIFY_POLYNOMIAL,
max_turns=5,
simple = config.get("simple", False)
self._counter += 1
if self._counter % 2 != 0:
# complex single-terms
text, complexity = simplify_multiple_terms(
num_terms,
op="*",
optional_var=simple,
optional_var_probability=0.66,
min_terms=2,
)
return MathyEnvProblem(text, complexity + 2, MODE_SIMPLIFY_COMPLEX_TERM)
# polynomial simplification
num_terms = int(config.get("poly_difficulty", poly))
text, complexity = simplify_multiple_terms(num_terms)
return MathyEnvProblem(text, complexity, MODE_SIMPLIFY_POLYNOMIAL)
"""Get the value of the current state
Input:
env_state: current env_state
searching: boolean that is True when called by MCTS simulation
Returns:
transition: the current state value transition
"""
agent = env_state.agent
expression = self.parser.parse(agent.problem)
features = env_state.to_input_features(self.get_valid_moves(env_state))
root = expression.get_root()
if (
env_state.agent.problem_type == MODE_SIMPLIFY_POLYNOMIAL
and not has_like_terms(root)
):
term_nodes = get_terms(root)
is_win = True
for term in term_nodes:
if not is_preferred_term_form(term):
is_win = False
if is_win:
return time_step.termination(features, self.get_win_signal(env_state))
# Check the turn count last because if the previous move that incremented
# the turn over the count resulted in a win-condition, we want it to be honored.
if env_state.agent.moves_remaining <= 0:
return time_step.termination(features, GameRewards.LOSE)
if len(agent.history) > 0:
def get_rewarding_actions(self, state: MathyEnvState) -> List[Type[BaseRule]]:
if state.agent.problem_type == MODE_SIMPLIFY_COMPLEX_TERM:
return [ConstantsSimplifyRule, VariableMultiplyRule]
# if not complex, must be poly simplification
assert state.agent.problem_type == MODE_SIMPLIFY_POLYNOMIAL
return [ConstantsSimplifyRule, DistributiveFactorOutRule]
combine_terms_in_place,
move_around_blockers_one,
move_around_blockers_two,
)
moves_per_complexity = 4
purple_sims = 50
purple_belt = build_lesson_plan(
"purple_belt_practice",
[
LessonExercise(
lesson_name="five_complex_terms",
problem_fn=lambda: simplify_multiple_terms(5, op=None),
problem_type=MODE_SIMPLIFY_POLYNOMIAL,
mcts_sims=purple_sims,
num_observations=64,
),
LessonExercise(
lesson_name="six_complex_terms_with_exponents",
problem_fn=lambda: simplify_multiple_terms(6, powers_proability=0.85, op=None),
problem_type=MODE_SIMPLIFY_POLYNOMIAL,
mcts_sims=purple_sims,
num_observations=64,
),
LessonExercise(
lesson_name="eight_complex_terms_with_exponents",
problem_fn=lambda: simplify_multiple_terms(8, powers_proability=0.85, op=None),
problem_type=MODE_SIMPLIFY_POLYNOMIAL,
mcts_sims=purple_sims,
num_observations=64,
def simple_polynomials(number_terms, sims=500, observations=32):
return build_lesson_plan(
"simple_polynomials",
[
LessonExercise(
lesson_name=f"polynomials_{number_terms}_terms",
problem_fn=lambda: simplify_multiple_terms(number_terms),
problem_type=MODE_SIMPLIFY_POLYNOMIAL,
mcts_sims=sims,
num_observations=observations,
)