Exemplo n.º 1
0
print "# Computed counts for each hypothesis & nonterminal"

# print counts

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Build up the info about the data
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

L = []  # each hypothesis's cumulative likelihood to each data point
NYes = []
NTrials = []
Output = []
GroupLength = []

for concept in concept2data.keys():

    data = concept2data[concept]

    # compute the likelihood for all the data here
    for h in hypotheses:
        h.stored_likelihood = [h.compute_single_likelihood(d) for d in data]

    for di in xrange(25):
        ll = [sum(h.stored_likelihood[:di])
              for h in hypotheses]  # each likelihood
        out = [
            map(lambda x: 1 * h(data[di].input, x), data[di].input)
            for h in hypotheses
        ]  # each response
Exemplo n.º 2
0
    Return standard sampling of hypotheses on this amount of data
    """
    if LOTlib.SIG_INTERRUPTED:
        return None, set()

    myset = standard_sample(make_hypothesis,
                           lambda: concept2data[concept_key][:ndata],
                           N=options.TOP_COUNT,
                           steps=options.STEPS,
                           show=False, save_top=None)

    return concept_key, set(myset.get_all())


if __name__ == "__main__":

    from LOTlib.MPI.MPI_map import MPI_unorderedmap, is_master_process
    from collections import defaultdict

    hypotheses = defaultdict(set)
    for key, s in  MPI_unorderedmap(run, itertools.product(concept2data.keys(), xrange(35), xrange(options.CHAINS)) ):
        hypotheses[key].update(s)
        print "# Done %s found %s hypotheses" % (key, len(s))

        # for h in s:
        #     print key, h

    import pickle
    with open(options.OUT_PATH, 'w') as f:
        pickle.dump(hypotheses, f)
Exemplo n.º 3
0
from Model.Grammar import grammar

trees = [h.value for h in hypotheses]

nt2counts, sig2idx, prior_offset = create_counts(grammar, trees, log=None)

print "# Computed counts for each hypothesis & nonterminal"

# print counts

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Build up the info about the data
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

concepts = concept2data.keys()

NYes     = []
NNo      = []

# Make NYes and Nno
for c in concepts:
    data = concept2data[c]

    for di, d in enumerate(data[:25]): # as far as we go into the trial
        for ri in xrange(len(d.input)): # each individual response
            k = tuple([c, di+1, ri+1])
            # assert k in human_yes and k in human_no, "*** Hmmm key %s is not in the data" % k
            if k in human_yes or k in human_no:
                NYes.append( human_yes[k])
                NNo.append( human_no[k])
Exemplo n.º 4
0
from Model.Grammar import grammar

trees = [h.value for h in hypotheses]

nt2counts, sig2idx, prior_offset = create_counts(grammar, trees, log=None)

print "# Computed counts for each hypothesis & nonterminal"

# print counts

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Build up the info about the data
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

concepts = concept2data.keys()

NYes = []
NNo = []

# Make NYes and Nno
for c in concepts:
    data = concept2data[c]

    for di, d in enumerate(data[:25]):  # as far as we go into the trial
        for ri in xrange(len(d.input)):  # each individual response
            k = tuple([c, di + 1, ri + 1])
            # assert k in human_yes and k in human_no, "*** Hmmm key %s is not in the data" % k
            if k in human_yes or k in human_no:
                NYes.append(human_yes[k])
                NNo.append(human_no[k])
Exemplo n.º 5
0
print "# Computed counts for each hypothesis & nonterminal"

# print counts

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Build up the info about the data
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

L        = [] # each hypothesis's cumulative likelihood to each data point
NYes     = []
NTrials  = []
Output  = []
GroupLength = []

for concept in concept2data.keys():

    data = concept2data[concept]

    # compute the likelihood for all the data here
    for h in hypotheses:
        h.stored_likelihood = [h.compute_single_likelihood(d) for d in data]

    for di in xrange(25):
        ll  = [ sum(h.stored_likelihood[:di]) for h in hypotheses ] # each likelihood
        out = [ map(lambda x: 1*h(data[di].input, x), data[di].input) for h in hypotheses] # each response

        # This group will be as long as this number of data points
        GroupLength.append( len(data[di].input) )
        L.append(ll)
Exemplo n.º 6
0
    myset = standard_sample(make_hypothesis,
                            lambda: concept2data[concept_key][:ndata],
                            N=options.TOP_COUNT,
                            steps=options.STEPS,
                            show=False,
                            save_top=None)

    return concept_key, set(myset.get_all())


if __name__ == "__main__":

    from LOTlib.MPI.MPI_map import MPI_unorderedmap, is_master_process
    from collections import defaultdict

    hypotheses = defaultdict(set)
    for key, s in MPI_unorderedmap(
            run,
            itertools.product(concept2data.keys(), xrange(35),
                              xrange(options.CHAINS))):
        hypotheses[key].update(s)
        print "# Done %s found %s hypotheses" % (key, len(s))

        # for h in s:
        #     print key, h

    import pickle
    with open(options.OUT_PATH, 'w') as f:
        pickle.dump(hypotheses, f)