Changeset 347

Show
Ignore:
Timestamp:
11/16/08 00:29:16 (2 months ago)
Author:
mschmucker
Message:

split up svn_example1.py in two, adding some comments and setting Id keyword

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/examples/sfn2008/sfn_example_stgen.py

    • Property svn:mergeinfo set
    • Property svn:keywords set to Id
    r345 r347  
     1""" 
     2$Id$ 
     3 
     4Example to show off some capabilities of the stgen module  
     5and the SpikeTrain class. 
     6 
     7Performed at the NeuroTools demo session, INCF booth,  
     8SfN annual meeting 2008, Washington. DC. 
     9""" 
    110import NeuroTools.stgen as stgen 
    211sg = stgen.StGen() 
    312duration = 10000. 
    4 nu = 20. 
    5 c = 0.0 # correlation 
    6 rate_independent = (1-c)*nu 
    7 rate_shared = c*nu 
     13rate_independent = 100. #Hz 
     14rate_shared = 10. #Hz, 10 % correlation 
    815 
    916st1 = sg.poisson_generator(rate=rate_independent, t_stop = duration)  
     
    2229import numpy 
    2330cc = numpy.correlate(st1.time_histogram(time_bin = 1.),  
    24                     st2.time_histogram(time_bin = 1.),  
    25                     mode = 'same') 
     31                     st2.time_histogram(time_bin = 1.),  
     32                     mode = 'same') 
    2633 
    2734import pylab 
    2835pylab.plot(cc) 
    2936 
    30 # inject correlation into st1 and st2 
     37# inject correlation into st1 and st2 (only if correlation is > 0) 
    3138st3 = sg.poisson_generator(rate=rate_shared, t_stop = duration)  
    3239st1.merge(st3) 
     
    3441 
    3542cc2 = numpy.correlate(st1.time_histogram(time_bin = 1.),  
    36                     st2.time_histogram(time_bin = 1.),  
    37                     mode = 'same') 
     43                      st2.time_histogram(time_bin = 1.),  
     44                      mode = 'same') 
    3845 
    3946import pylab 
    4047pylab.plot(cc2) 
    4148 
    42 #shot noise 
     49#generate shot noise from st1 
    4350st1_shot = stgen.shotnoise_fromspikes(st1,  
    44                                      q = 1.0,  
    45                                      tau = 10.,  
    46                                      t_start = st1.t_start,  
    47                                      t_stop = st1.t_stop) 
     51                                      q = 1.0,  
     52                                      tau = 10.,  
     53                                      t_start = st1.t_start,  
     54                                      t_stop = st1.t_stop) 
    4855pylab.figure() 
    4956pylab.plot(st1_shot.signal) 
     
    5360 
    5461 
    55 # example parameter space range etc. 
    56 # parameter scan, c vs. jitter 
    57  
    58  
    59 def calc_cc(p): 
    60     rate_independent = (1-p.c)*p.nu 
    61     rate_shared = p.c*p.nu 
    62      
    63     st1 = sg.poisson_generator(rate=rate_independent, t_stop = p.duration)  
    64     st2 = sg.poisson_generator(rate=rate_independent, t_stop = p.duration) 
    65     if p.c >0: 
    66         st3 = sg.poisson_generator(rate=rate_shared, t_stop = duration)  
    67         st1.merge(st3.jitter(p.jitter)) 
    68         st2.merge(st3.jitter(p.jitter)) 
    69      
    70     cc = numpy.correlate(st1.time_histogram(time_bin = 1.0),st2.time_histogram(time_bin = 1.),mode = 'same') 
    71     corrcoef = numpy.corrcoef(st1.time_histogram(time_bin = 1.0),st2.time_histogram(time_bin = 1.)) 
    72     return cc, corrcoef[0][1] 
    73  
    74  
    75  
    76 from NeuroTools.parameters import ParameterSpace 
    77 from NeuroTools.parameters import ParameterRange 
    78 from NeuroTools.sandbox import make_name 
    79  
    80 p = ParameterSpace({}) 
    81 p.nu = 20. # Hz 
    82 p.c = ParameterRange([0.0,0.01,0.1,0.5]) 
    83 p.jitter = ParameterRange([0.0,1.0,5.0,]) 
    84 p.duration = 1000. 
    85  
    86 dims, labels = p.parameter_space_dimension_labels() 
    87  
    88 corrcoef_results = numpy.empty(dims) 
    89  
    90 for experiment in p.iter_inner(): 
    91     index = p.parameter_space_index(experiment) 
    92     cc, corrcoef = calc_cc(experiment) 
    93     time_axis = numpy.linspace(-cc.shape[0]/2.,cc.shape[0]/2.,cc.shape[0]) 
    94     corrcoef_results[index] = corrcoef 
    95     subplot_index = (dims[1]*index[0])+index[1] 
    96     pylab.subplot(dims[0],dims[1],subplot_index+1) 
    97     pylab.plot(time_axis,cc) 
    98     pylab.title(make_name(experiment,p.range_keys())) 
    99     pylab.xlim(-30,30.) 
    100     pylab.ylim(0,130.) 
    101      
    102  
    103