Changeset 191

Show
Ignore:
Timestamp:
08/21/08 12:36:09 (5 months ago)
Author:
apdavison
Message:

Reduced dependency of stgen.py on pygsl

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/stgen.py

    r106 r191  
    66try: 
    77    import pygsl 
     8    have_gsl = True 
    89except ImportError: 
    910    print "Warning: pygsl not available" 
    10 #from analysis import nstats 
    11 from numpy import array 
     11    have_gsl = False 
     12from numpy import array, log 
    1213import numpy 
    1314 
     
    1617 
    1718def calc_h_single(x,a,b,dt=1e-4): 
    18  
    19     import pygsl 
    2019    from pygsl.sf import gamma_inc_Q 
    21  
    22     from Numeric import array,log 
    23  
    24  
    25     Hpre = -log(gamma_inc_Q(a,(x-dt)/b)[0])[0] 
    26  
     20    Hpre = -log(pygsl.sf.gamma_inc_Q(a,(x-dt)/b)[0])[0] 
    2721    Hpost = -log(gamma_inc_Q(a,(x+dt)/b)[0])[0] 
    28  
    2922    return 0.5*(Hpost-Hpre)/dt 
    3023 
    3124def calc_h(x,a,b,dt=1e-4): 
    32  
    3325    Hpre = -log(array(map(gamma_inc_Q,a,(x-dt)/b))) 
    3426    Hpost = -log(array(map(gamma_inc_Q,a,(x-dt)/b))) 
    35  
    3627    return 0.5*(Hpost-Hpre)/dt 
    3728 
     
    3930class StGen: 
    4031 
    41     def __init__(self,gslrng=None,numpyrng=None): 
     32    def __init__(self, gslrng=None, numpyrng=None): 
    4233        """ Spike Train Generator 
    4334 
     
    4536        Similarly for numpyrng. 
    4637        If neither is specified, a gsl rng is created. 
    47         If both are specified, the gslrng is used.""" 
    48  
    49         if not gslrng: 
    50             if not numpyrng: 
     38        If both are specified, the gslrng is used. 
     39         
     40        Of course, if pygsl is not available, you can't 
     41        have a gsl rng and will get a numpy rng. 
     42        """ 
     43 
     44        if have_gsl: 
     45            if gslrng: 
     46                self.rng = gslrng 
     47            elif numpyrng: 
     48                self.rng = numpyrng 
     49            else:     
    5150                from pygsl.rng import rng 
    5251                self.rng = rng() 
    53             else: 
    54                 self.rng = numpyrng 
    5552        else: 
    56             self.rng = gslrng 
     53            self.rng = numpy.random.RandomState() 
    5754 
    5855    def seed(self,seed): 
     
    9491        if len(ps) > 0: 
    9592            # gen uniform rand on 0,1 for each spike 
    96             rn = array(self.rng.uniform(len(ps))) 
     93            rn = array(self.rng.uniform(0, 1, len(ps))) 
    9794 
    9895            # instantaneous rate for each spike