Esempio n. 1
0
def response_densities(cond, mcent=8, nrep=3, stims=None,
                       sppt=163000, dsd=10000):
    """
    return a list l such that l[i] = is a gmm of the responses to stimulus i.

    Since these are 1D models, the underlying mixmod call always uses PkLkCk,
    but mcent specifies the max number of centers to try, nrep the number of
    repeats to use.

    stims may be a list, which restricts the set of stimuli that are modeled
    (by default, it is all presented stimuli).

    If the number of spikes evoked by a stimulus is very small, mixmod errors
    will result. This function will not try to calculate a model based on fewer
    than 2 spikes per center, reguardless of the value of mcent. For response
    groups with at least two spikes, mcent may be reduced. Responses with no
    spikes are modeled with a 0-component model (the dictionary
    {'components':(), 'support':sppt}. mixmod.evaluate on such a model will
    return a uniform probability if 1/sppt, so this behavior is equivalent to a
    uniform prior over a region of size sppt. Responses with exactly 1 spike are
    modeled as a single center, with mean at the time of that spike, and
    standard deviation specified by the free parameter dsd.

    This function adds the key "responses" to the resulting model dictionaries,
    containing the source spike trains

    """
    if stims is None:
        stims = set(cond['stims'])
    l = [None for _ in range(max(stims) + 1)]
    for s in stims:
        sts = spikes_from(cond, s, False)
        sf = flat(sts)
        if len(sf) > 1:
            mc = int(min(mcent, np.ceil(len(sf) / 2.0)))
            l[s] = mmcall(np.array(sf)[:, np.newaxis], range(1, mc + 1),
                          reps=nrep)
        elif sf:
            l[s] = {'proportions': (1.0,), 'c0': {'cov': ((dsd ** 2,),),
                                                  'mean': (sf[0],)},
                    'bic': 0, 'components': ('c0',), 'partition': (0,)}
        else:
            l[s] = {'components': (), 'support': sppt}
        l[s]['responses'] = sts

    return l
Esempio n. 2
0
def mixmodpartition(data, k, model="Gaussian_pk_Lk_Ck", reps=1):
    """Wraps mixmod.mmcal(data, [k], model, False, reps), and returns the
    resulting partition"""
    d = mmcall(data, [k], model, False, reps)
    return d['partition']