Example #1
0
def subgraph_pl_test(modelDict=dict(mix=mixture_model2,
                                    family=family_model2,
                                    unrelated=unrelated_model2,
                                    environmental=environmental_model2),
                     obsSet=None):
    'build multi-model hypergraph, apply to the obs, and print posterior liklihoods'
    p = 1./len(modelDict) # uninformative prior
    modelWh = stats.norm(0, 1)
    modelPu = stats.norm(10, 1)
    if obsSet is None:
        obsSet = get_family_obs(matingID=0)
    stop = model.StopState(useObsLabel=False)
    d = {}
    d2 = {}
    for model_name, model_f in modelDict.items(): # build distinct models
        state = model.SilentState(model_name)
        state.subgraph = model_f(modelWh, modelPu)
        d[state] = p
        d2[state] = {stop:1.}
    prior = model.StateGraph({'START':d})
    term = model.StateGraph(d2)
    dg = model.DependencyGraph({'START':{'model':prior},
                                'model':{'STOP':term}})
    m = model.Model(dg, obsSet)
    m.segmentGraph.p_forward(m.logPobsDict)
    f = m.segmentGraph.fprob[m.start].f
    fmerge = {}
    for node, logP in f.items(): # merge forward calcs from subgraphs
        try:
            subgraph = node.segmentGraph
        except AttributeError:
            pass
        else:
            merge_forward_dict(subgraph.fprob[subgraph.start].f, logP, fmerge)
    llDict = model.posterior_ll(fmerge)
    print_pl(llDict)
    return llDict
Example #2
0
def basic_pl(segmentGraph):
    f = segmentGraph.fprob[segmentGraph.start].f # forward prob dictionary
    return model.posterior_ll(f)