Пример #1
0
def forwardTest():
    spikeTimes = spt = [26, 50, 84, 128, 199, 247, 355] 
    P = setupSimData(spt = spikeTimes )
    S = smc.forward(P.V, P)
    
    pylab.figure()
    pylab.plot(P.V.F)
    pylab.title('Simulated Fluorescence')
    

    cbar = numpy.zeros(P.V.T)
    nbar = numpy.zeros(P.V.T)
    
    for t in xrange(P.V.T):
        for i in xrange(P.V.Nparticles):
            weight = S.w_f[i,t]
            cbar[t] += weight * S.C[i,t]
            nbar[t] += weight * S.n[i,t]
    
    #cbar /= P.V.Nparticles
    #nbar /= P.V.Nparticles
    
    pylab.figure()
    pylab.hold(True)
    pylab.title('expected Ca vs arbitrary particles')
    pylab.plot(S.C[3,:], label='particle 3')
    pylab.plot(S.C[10,:], label='particle 10')
    pylab.plot(S.C[20,:], label='particle 20')
    pylab.plot(cbar, label='E[C]')
    pylab.plot(spikeTimes, 6+numpy.ones(len(spikeTimes)), 'k.', label='simulated spike times')

    pylab.legend()
    
    #print(nbar.shape)
    pylab.figure()
    pylab.hold(True)
    pylab.plot(nbar, label='expected spikes')
    pylab.plot(spikeTimes, 0.5*numpy.ones(len(spikeTimes)), 'k.', label='simulated spike times')
    pylab.legend()
    pylab.title('spike detection')
    

    #pylab.figure()
    pylab.matshow(S.w_f)
    pylab.title('min s.w_f %f , max s.w_f: %f'%(numpy.min(S.w_f), numpy.max(S.w_f)))
    
    
    pylab.figure()
    pylab.hold(True)
    pylab.plot(S.w_f[3,:], label='particle 3')
    pylab.plot(S.w_f[10,:], label='particle 10')
    pylab.plot(S.w_f[20,:], label='particle 20')
    pylab.legend()
    pylab.title('individual particle weights')
    
    pylab.show()
Пример #2
0
def paramWalkHelper(spikeTimes, P):
    S = smc.forward(P.V, P)
    trueSpikes = numpy.zeros(P.V.T,dtype=bool)
    trueSpikes[spikeTimes] = True
    
    posterior = 0.0
    positivePosterior = 0.0
    spikeCount = 0
    for t in xrange(P.V.T):
        nbar = 0.0
        for i in xrange(P.V.Nparticles):
            nbar += S.w_f[i,t] * S.n[i,t]
        if(trueSpikes[t]):
            positivePosterior += nbar
            posterior += nbar
            spikeCount += 1
        else:
            posterior += (1-nbar)
            
    print('posterior: %f     post/V.T: %f'%(posterior, posterior/P.V.T))
    
    return positivePosterior/spikeCount#posterior/P.V.T