in src/evaluator.py [0:0]
def check_hypothesis(eq):
"""
Check a hypothesis for a given equation and its solution.
"""
env = Evaluator.ENV
src = [env.id2word[wid] for wid in eq["src"]]
tgt = [env.id2word[wid] for wid in eq["tgt"]]
hyp = [env.id2word[wid] for wid in eq["hyp"]]
if eq["task"] == "ode_convergence_speed":
try:
tgt, _ = env.parse_float(tgt)
l1 = len(hyp)
hyp, l2 = env.parse_float(hyp)
if hyp == np.nan or l2 != l1:
is_valid = False
elif hyp == tgt:
is_valid = True
else:
den = hyp if tgt == 0 else tgt
is_valid = abs((tgt - hyp) / den) < TOLERANCE_THRESHOLD
except Exception:
is_valid = False
tgt = 0
hyp = 0
elif eq["task"] == "ode_control":
if env.predict_gramian:
try:
d, l1 = env.parse_int(hyp)
t, l2 = env.parse_int(tgt)
if d == 0 and t == 0 and not env.auxiliary_task:
if env.euclidian_metric:
is_valid = compare_gramians(
env,
tgt[l2 + 1 :],
hyp[l1 + 1 :],
env.gramian_tolerance,
env.gramian_norm1,
)
else:
is_valid = check_gramian(env, src, tgt, hyp[l1 + 1 :])
else:
is_valid = d == t
except Exception:
is_valid = False
else:
try:
tgt, _ = env.parse_int(tgt)
l1 = len(hyp)
hyp, l2 = env.parse_int(hyp)
if hyp == np.nan or l2 != l1:
is_valid = False
else:
is_valid = hyp == tgt
except Exception:
is_valid = False
elif eq["task"] == "fourier_cond_init":
try:
is_valid = check_fourier_cond_init(env, src, tgt, hyp)
except Exception:
is_valid = False
else:
is_valid = hyp == tgt
# update hypothesis
eq["src"] = env.input_to_infix(src)
eq["tgt"] = tgt
eq["hyp"] = hyp
eq["is_valid"] = is_valid
return eq