def make_data(N=30): """ The data here consist of saffran-aslin-newport type strings. They have a geometric length distribution more like what you might find in natural data, with more frequent shorter strings. This is modeled in the hypothesis with a flip to whether or not you recurse to generate a longer string. """ data = [] cnt = Counter() for _ in xrange(N): cnt[''.join(sample_one(words) for _ in xrange(5))] += 1 return [FunctionData(input=[], output=cnt)]
def propose(self): new = copy(self) ## Now we just copy the whole thing while True: try: i = sample_one(range(self.N)) # random one # i = max(self.value.keys()) # only propose to last x, fb = self.get_word(i).propose() new.set_word(i, x) return new, fb except ProposalFailedException: pass
def propose(self): """ We only propose to the last in this kind of lexicon """ new = deepcopy(self) ## Now we just copy the whole thing while True: try: i = sample_one(range(self.N)) x, fb = self.get_word(i).propose() new.set_word(i, x) new.grammar = self.value[0].grammar # keep the grammar the same object return new, fb except ProposalFailedException: pass
def propose(self): """ We only propose to the last in this kind of lexicon """ new = deepcopy(self) ## Now we just copy the whole thing while True: try: i = sample_one(range(self.N)) # random one # i = max(self.value.keys()) # only propose to last x, fb = self.get_word(i).propose() new.set_word(i, x) new.grammar = self.value[0].grammar # keep the grammar the same object return new, fb except ProposalFailedException: pass
def make_data(N=20, f=TargetConcepts[0]): data = [] for _ in xrange(N): o = sample_one(all_objects) data.append(FunctionData(input=[o], output=f(o), alpha=0.90)) return data
def generate_data(N, f): data = [] for _ in xrange(N): o = sample_one(all_objects) data.append(FunctionData(input=[o], output=f(o))) return data
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Data # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ from LOTlib.DataAndObjects import FunctionData, make_all_objects from LOTlib.Miscellaneous import sample_one from random import random all_objects = make_all_objects( shape=SHAPES, color=COLORS ) # Generate all of the data, picking a different target hypothesis for each sequence # "people" are shown datas = [] for di in xrange(NDATASETS): # pick a hypothesis at random target = sample_one(hypotheses) print "# Target:", target data = [] for _ in xrange(DATASET_SIZE): obj = sample_one(all_objects) if random() < ALPHA: output = target(obj) else: output = random() < BETA data.append( FunctionData(input=[obj], output=output, alpha=ALPHA) ) datas.append(data)
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ # Data # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ from LOTlib.DataAndObjects import FunctionData, make_all_objects from LOTlib.Miscellaneous import sample_one from random import random all_objects = make_all_objects(shape=SHAPES, color=COLORS) # Generate all of the data, picking a different target hypothesis for each sequence # "people" are shown datas = [] for di in xrange(NDATASETS): # pick a hypothesis at random target = sample_one(hypotheses) print "# Target:", target data = [] for _ in xrange(DATASET_SIZE): obj = sample_one(all_objects) if random() < ALPHA: output = target(obj) else: output = random() < BETA data.append(FunctionData(input=[obj], output=output, alpha=ALPHA)) datas.append(data) # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~