def crossover_lot(x,y): t = copy(x.value) n1, _ = t.sample_subnode(resampleProbability=lambdaOne) n2, _ = y.value.sample_subnode(resampleProbability=lambda t: 1*(t.returntype==n1.returntype)) n1.setto(n2) # assign the value! return Hypothesis.__copy__(x, value=t)
def crossover_lot(x, y): t = copy(x.value) n1, _ = t.sample_subnode(resampleProbability=lambdaOne) n2, _ = y.value.sample_subnode( resampleProbability=lambda t: 1 * (t.returntype == n1.returntype)) n1.setto(n2) # assign the value! return Hypothesis.__copy__(x, value=t)
def propose(self): if random.random() < 0.5: ret = regeneration_proposal(self.grammar, self.value) else: ret = insert_delete_proposal(self.grammar, self.value) p = Hypothesis.__copy__(self, value=ret[0]) ret[0] = p return ret
def propose(self): if random.random() < 0.5: ret = regeneration_proposal(self.grammar, self.value) else: ret = insert_delete_proposal(self.grammar, self.value) p = Hypothesis.__copy__(self, value=ret[0]) ret[0] = p return ret
def propose(self, **kwargs): while True: # keep trying to propose try: ret = self.propose_tree(self.value, **kwargs) # don't unpack, since we may return [newt,fb] or [newt,f,b] break except ProposalFailedException: pass p = Hypothesis.__copy__(self, value=ret[0]) ret[0] = p # really make the first a hypothesis, not a tree return ret
def propose(self, **kwargs): while True: # keep trying to propose try: ret = self.propose_tree( self.value, **kwargs ) # don't unpack, since we may return [newt,fb] or [newt,f,b] break except ProposalFailedException: pass p = Hypothesis.__copy__(self, value=ret[0]) ret[0] = p # really make the first a hypothesis, not a tree return ret