示例#1
0
 def u_atom(self):
     if ModifiedDummyBuilder.activate_rejection_K:
         NodeCounter.L += 1
         L = NodeCounter.L
         if L > 1 and not bern(L / (L + 1)):
             self._grammar.restart_sampler()
     return DummyClass(u_size=1)
 def rej_to_K(u_derived_tree):
     return bern(2 / (u_derived_tree.u_size + 1))
 def rej_to_G_1(g):
     return bern(1 / (g.l_size + 1))
示例#4
0
 def rej_G_3_arrow_dx_to_dy(dummy):
     return bern(1 / 3 * dummy._u_size /
                 (dummy._l_size + 1))  # todo check this
示例#5
0
 def rej_K_dy_to_K_dx(dummy):
     return bern(1.5 * dummy._l_size / (dummy._u_size + 1))
### binary trees ###

K_dy = AliasSampler('K_dy')
K_dx = AliasSampler('K_dx')
R_b_as = AliasSampler('R_b_as')
R_w_as = AliasSampler('R_w_as')
R_b_head = AliasSampler('R_b_head')
R_w_head = AliasSampler('R_w_head')
R_b = AliasSampler('R_b')
R_w = AliasSampler('R_w')
K = AliasSampler('K')

binary_tree_rules = {
    'K':
    Bij(
        Rej(K_dy, lambda gamma: bern(2 / (gamma.u_size() + 1))),
        lambda gamma: DummyClass(gamma.l_size(),
                                 gamma.u_size() + 1
                                 )  # u size increases by 1 due to underive
    ),
    'K_dx':
    DxFromDy(K_dy, alpha_l_u=2 / 3),
    'K_dy':
    R_b_as + R_w_as,
    'R_b_as': (R_w * L * U) + (U * L * R_w) + (R_w * L * R_w),
    'R_w_as': (R_b_head * U) + (U * R_b_head) + R_b**2,
    'R_b_head': (R_w_head * L * U * U) + (U * U * L * R_w_head) +
    (R_w_head * L * R_w_head),
    'R_w_head':
    U + (R_b * U) + (U * R_b) + R_b**2,
    'R_b': (U + R_w) * L * (U + R_w),