Пример #1
0
def CustomEstimate(spike_trains):   
    D = DataPrinter('')
    for spike_train in spike_trains:
        regime_name = spike_train[0];
        sample_id = spike_train[1]
        N_spikes = spike_train[2];
        N_phi = spike_train[3];
    
        phi_norms =  linspace(1/(2.*N_phi), 1. - 1/ (2.*N_phi), N_phi)

        base_name = 'sinusoidal_spike_train_N=%d_'%N_spikes

        T_thresh = 128.0;
        regime_label = base_name + regime_name
            
        file_name = regime_label + '_' + str(sample_id)
        print file_name
        
        binnedTrain = BinnedSpikeTrain.initFromFile(file_name, phi_norms)
        ps = binnedTrain._Train._params
        abg_true = array((ps._alpha, ps._beta, ps._gamma))
        
        D.setRegime(regime_name,abg_true, Tsim=-1.0)
        
        binnedTrain.pruneBins(None, N_thresh = 5, T_thresh=T_thresh)
        D.addSample(sample_id, binnedTrain.getTf(), binnedTrain.getBinCount(), binnedTrain.getSpikeCount())
                    
        abg_init = initialize_right_2std(binnedTrain)
        abg_init[1] = amax([.1, abg_init[1]])
        abg_init[2] = amax([.0, abg_init[2]])
        D.addEstimate(sample_id, 'Initializer', abg_init,.0, warnflag = 0) 
                   
        #RELOAD ALL DATA:               
        binnedTrain = BinnedSpikeTrain.initFromFile(file_name, phi_norms)
        binnedTrain.pruneBins(None, N_thresh = 1, T_thresh=T_thresh)
        
        #Weighted Fortet:            
        start = time.clock()
        abg_est, warnflag = FortetEstimatorSup(binnedTrain, abg_init, verbose = True)
        finish = time.clock()
        D.addEstimate(sample_id, 'Fortet', abg_est, finish-start, warnflag)
        
        #Weighted F-P:
        dx = .025; dt = FPMultiPhiSolver.calculate_dt(dx, abg_true, -1.0) 
        phis = binnedTrain.bins.keys();
        S = FPMultiPhiSolver(binnedTrain.theta, phis,
                             dx, dt,
                             binnedTrain.getTf(), X_min = -1.0)            
        
        start = time.clock()
        abg_est, warnflag = FPSupEstimator(S, binnedTrain, abg_init, verbose = True)
        finish = time.clock()
        D.addEstimate(sample_id, 'FP', abg_est, finish-start, warnflag)
                    
    del D  
Пример #2
0
def TestEstimate(N_spikes = 100, N_trains=5, N_phi=8):
    print 'N_phi = ', N_phi
    
    phi_norms =  linspace(1/(2.*N_phi), 1. - 1/ (2.*N_phi), N_phi)

    batch_start = time.clock()    
    base_name = 'sinusoidal_spike_train_N=%d_'%N_spikes
    
    D = DataPrinter('')

    for regime_name, T_thresh in zip(['superT'],
                                     [64]):
        regime_label = base_name + regime_name
            
        for sample_id in xrange(1,N_trains +1):
            file_name = regime_label + '_' + str(sample_id)
            print file_name
            
            binnedTrain = BinnedSpikeTrain.initFromFile(file_name, phi_norms)
            ps = binnedTrain._Train._params
            abg_true = array((ps._alpha, ps._beta, ps._gamma))
            D.setRegime(regime_name,abg_true, Tsim=-1.0)
            
            binnedTrain.pruneBins(None, N_thresh = 5, T_thresh=T_thresh)
            D.addSample(sample_id, binnedTrain.getTf(), binnedTrain.getBinCount(), binnedTrain.getSpikeCount())
                        
            abg_init = initialize_right_2std(binnedTrain)
            abg_init[1] = amax([.1, abg_init[1]])
            abg_init[2] = amax([.0, abg_init[2]])
            D.addEstimate(sample_id, 'Initializer', abg_init,.0, warnflag = 0) 
                       
            #RELOAD ALL DATA:               
            binnedTrain = BinnedSpikeTrain.initFromFile(file_name, phi_norms)
            binnedTrain.pruneBins(None, N_thresh = 1, T_thresh=T_thresh)
            
            #Weighted Fortet:            
            start = time.clock()
            abg_est, warnflag = FortetEstimatorSup(binnedTrain, abg_init, verbose = True)
            finish = time.clock()
            D.addEstimate(sample_id, 'Fortet', abg_est, finish-start, warnflag)
            
            #Weighted F-P:
            dx = .025; dt = FPMultiPhiSolver.calculate_dt(dx, abg_true, -1.0) 
            phis = binnedTrain.bins.keys();
            S = FPMultiPhiSolver(binnedTrain.theta, phis,
                                 dx, dt,
                                 binnedTrain.getTf(), X_min = -1.0)            
            
            start = time.clock()
            abg_est, warnflag = FPSupEstimator(S, binnedTrain, abg_init, verbose = True)
            finish = time.clock()
            D.addEstimate(sample_id, 'FP', abg_est, finish-start, warnflag)
                    
    del D  
    print 'batch time = ', (time.clock() - batch_start) / 3600.0, ' hrs'
Пример #3
0
def ThetaBox(thetas, sample_id = 1):   
    D = DataPrinter('')
    for theta in thetas:
        N_phi = 20;
        phi_norms =  linspace(1/(2.*N_phi), 1. - 1/ (2.*N_phi), N_phi)

        file_name = 'sinusoidal_spike_train_N=1000_critical_theta=%d_%d'%(theta, sample_id)
        print file_name
                    
        T_thresh = 128.0;
        
        binnedTrain = BinnedSpikeTrain.initFromFile(file_name, phi_norms)
        ps = binnedTrain._Train._params
        abg_true = array((ps._alpha, ps._beta, ps._gamma))
        print 'ps = ', ps.getParams()
        
        regime_name = 'theta=%d'%int(ps._theta)
        print regime_name
        D.setRegime(regime_name,abg_true, Tsim=-1.0)
        
        binnedTrain.pruneBins(None, N_thresh = 5, T_thresh=T_thresh)
        D.addSample(sample_id, binnedTrain.getTf(), binnedTrain.getBinCount(), binnedTrain.getSpikeCount())
                    
        abg_init = initialize_right_2std(binnedTrain, cap_beta_gamma=True)
        D.addEstimate(sample_id, 'Initializer', abg_init,.0, warnflag = 0) 
                   
        #RELOAD ALL DATA:               
        binnedTrain = BinnedSpikeTrain.initFromFile(file_name, phi_norms)
        binnedTrain.pruneBins(None, N_thresh = 1, T_thresh=T_thresh)
        
        #Weighted Fortet:            
        start = time.clock()
        abg_est, warnflag = FortetEstimatorSup(binnedTrain, abg_init, verbose = False)
        finish = time.clock()
        D.addEstimate(sample_id, 'Fortet', abg_est, finish-start, warnflag)
        
        #Weighted F-P:
        dx = .025; dt = FPMultiPhiSolver.calculate_dt(dx, abg_true, -1.0) 
        phis = binnedTrain.bins.keys();
        S = FPMultiPhiSolver(binnedTrain.theta, phis,
                             dx, dt,
                             binnedTrain.getTf(), X_min = -1.0)            
        
        start = time.clock()
        abg_est, warnflag = FPSupEstimator(S, binnedTrain, abg_init, verbose = False)
        finish = time.clock()
        D.addEstimate(sample_id, 'FP', abg_est, finish-start, warnflag)
                    
    del D