rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
class test_trapz(unittest.TestCase): def check_basic(self): x = [1,4,6,7,12] y = [11,15,6,3,9] val = (11+15)/2.0*3 + (15+6)/2.0*2 + (6+3)/2.0 + (3+9)/2.0*5.0 assert_equal(trapz(y,x),val) def check_nd(self): x = sort(20*rand(10,20,30)) y = x**2 + 2*x + 1 dx = x[:,1:,:] - x[:,:-1,:] val = add.reduce(dx*(y[:,1:,:] + y[:,:-1,:])/2.0,1) assert_array_equal(trapz(y,x,axis=1),val)
def check_basic(self): ba = [1,2,10,11,6,5,4] ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]] for ctype in ['1','b','s','i','l','f','d','F','D']: a = array(ba,ctype) a2 = array(ba2,ctype) if ctype in ['1', 'b']: self.failUnlessRaises(ArithmeticError, cumprod, a) self.failUnlessRaises(ArithmeticError, cumprod, a2, 1) self.failUnlessRaises(ArithmeticError, cumprod, a) else: assert_array_equal(cumprod(a), array([1, 2, 20, 220, 1320, 6600, 26400],ctype)) assert_array_equal(cumprod(a2), array([[ 1, 2, 3, 4], [ 5, 12, 21, 36], [50, 36, 84, 180]],ctype)) assert_array_equal(cumprod(a2,axis=1), array([[ 1, 2, 6, 24], [ 5, 30, 210, 1890], [10, 30, 120, 600]],ctype))
return threeAddrProgram, signature, tempsig, constants
return threeAddrProgram, signature, tempsig, constants, input_names
def registerMaker(node, temporary=False): reg = Register(node, temporary=temporary) reg.n = reg_num[0] reg_num[0] -= 1 return reg
threeAddrProgram, inputsig, tempsig, constants = \
threeAddrProgram, inputsig, tempsig, constants, input_names = \
def numexpr(ex, signature=(), copy_args=(), **kwargs): """Compile an expression built using E.<variable> variables to a function. ex can also be specified as a string "2*a+3*b". The order of the input variables and their types can be specified using the signature parameter, which is a list of (name, type) pairs. """ threeAddrProgram, inputsig, tempsig, constants = \ precompile(ex, signature, copy_args, **kwargs) program = compileThreeAddrForm(threeAddrProgram) return interpreter.NumExpr(inputsig, tempsig, program, constants)
return interpreter.NumExpr(inputsig, tempsig, program, constants)
return interpreter.NumExpr(inputsig, tempsig, program, constants, input_names)
def numexpr(ex, signature=(), copy_args=(), **kwargs): """Compile an expression built using E.<variable> variables to a function. ex can also be specified as a string "2*a+3*b". The order of the input variables and their types can be specified using the signature parameter, which is a list of (name, type) pairs. """ threeAddrProgram, inputsig, tempsig, constants = \ precompile(ex, signature, copy_args, **kwargs) program = compileThreeAddrForm(threeAddrProgram) return interpreter.NumExpr(inputsig, tempsig, program, constants)
r_constants = 1 + nex.n_inputs
r_constants = 1 + len(nex.signature)
def disassemble(nex): rev_opcodes = {} for op in interpreter.opcodes: rev_opcodes[interpreter.opcodes[op]] = op r_constants = 1 + nex.n_inputs r_temps = r_constants + len(nex.constants) def getArg(pc): arg = ord(nex.program[pc]) if arg == 0: return 'r0' elif arg == 255: return None elif arg < r_constants: return 'r%d[%s]' % (arg, nex.input_names[arg-1]) elif arg < r_temps: return 'c%d[%s]' % (arg, nex.constants[arg - r_constants]) else: return 't%d' % (arg,) source = [] for pc in range(0, len(nex.program), 4): op = rev_opcodes.get(ord(nex.program[pc])) dest = getArg(pc+1) arg1 = getArg(pc+2) arg2 = getArg(pc+3) source.append( (op, dest, arg1, arg2) ) return source
b = time.clock()
b = timer()
def initialize(self,reseed = 1): b = time.clock() self.test_settings(self.settings) self.gen = 0 sd = self.settings['rand_seed']; alg = self.settings['rand_alg'] if reseed: rv.initialize(seed = sd, algorithm = alg) self.settings['seed_used'] = rv.initial_seed() self._print('initializing... seed = %d' % self.settings['seed_used']) self.crossover = self.pop.model_genome.crossover # get the crossover op from the first genome self.pop.settings = self.settings #should these be shared? self.size_pop(self.settings['pop_size']) self.settings['crossover'] = string.split(str(self.crossover))[0][1:] self.settings['selector'] = string.split(str(self.pop.selector))[0][1:] self.settings['scaler'] = string.split(str(self.pop.scaler))[0][1:] self.settings['genome_type'] = string.split(str(self.pop.model_genome))[0][1:]
self.step_time = time.clock() - b
self.step_time = timer() - b
def initialize(self,reseed = 1): b = time.clock() self.test_settings(self.settings) self.gen = 0 sd = self.settings['rand_seed']; alg = self.settings['rand_alg'] if reseed: rv.initialize(seed = sd, algorithm = alg) self.settings['seed_used'] = rv.initial_seed() self._print('initializing... seed = %d' % self.settings['seed_used']) self.crossover = self.pop.model_genome.crossover # get the crossover op from the first genome self.pop.settings = self.settings #should these be shared? self.size_pop(self.settings['pop_size']) self.settings['crossover'] = string.split(str(self.crossover))[0][1:] self.settings['selector'] = string.split(str(self.pop.selector))[0][1:] self.settings['scaler'] = string.split(str(self.pop.scaler))[0][1:] self.settings['genome_type'] = string.split(str(self.pop.model_genome))[0][1:]
b = time.clock()
b = timer()
def step(self,steps=1): sz = len(self.pop) replace = int(self.settings['p_replace'] * len(self.pop)) p_crossover = self.settings['p_cross'] for st in range(steps): b = time.clock() for i in range(0,replace,2): mom,dad= self.pop.select(2) self.stats['selections'] = self.stats['selections'] + 2 if flip_coin(p_crossover): try: bro,sis = self.crossover((mom,dad)) self.stats['crossovers'] = self.stats['crossovers'] + 2 self.pop.append(bro); self.pop.append(sis) except ValueError: #crossover failed - just act as if this iteration never happened i = i - 2 #print 'crossover failure - ignoring and continuing' else: self.pop.append(mom.clone());self.pop.append(dad.clone()); if replace % 2: #we did one to many - remove the last individual del self.pop[-1] self.stats['crossovers'] = self.stats['crossovers'] - 1 e1 = time.clock(); self.stats['mutations'] = self.stats['mutations'] + self.pop[sz:].mutate()
e1 = time.clock();
e1 = timer();
def step(self,steps=1): sz = len(self.pop) replace = int(self.settings['p_replace'] * len(self.pop)) p_crossover = self.settings['p_cross'] for st in range(steps): b = time.clock() for i in range(0,replace,2): mom,dad= self.pop.select(2) self.stats['selections'] = self.stats['selections'] + 2 if flip_coin(p_crossover): try: bro,sis = self.crossover((mom,dad)) self.stats['crossovers'] = self.stats['crossovers'] + 2 self.pop.append(bro); self.pop.append(sis) except ValueError: #crossover failed - just act as if this iteration never happened i = i - 2 #print 'crossover failure - ignoring and continuing' else: self.pop.append(mom.clone());self.pop.append(dad.clone()); if replace % 2: #we did one to many - remove the last individual del self.pop[-1] self.stats['crossovers'] = self.stats['crossovers'] - 1 e1 = time.clock(); self.stats['mutations'] = self.stats['mutations'] + self.pop[sz:].mutate()
e2 = time.clock();
e2 = timer();
def step(self,steps=1): sz = len(self.pop) replace = int(self.settings['p_replace'] * len(self.pop)) p_crossover = self.settings['p_cross'] for st in range(steps): b = time.clock() for i in range(0,replace,2): mom,dad= self.pop.select(2) self.stats['selections'] = self.stats['selections'] + 2 if flip_coin(p_crossover): try: bro,sis = self.crossover((mom,dad)) self.stats['crossovers'] = self.stats['crossovers'] + 2 self.pop.append(bro); self.pop.append(sis) except ValueError: #crossover failed - just act as if this iteration never happened i = i - 2 #print 'crossover failure - ignoring and continuing' else: self.pop.append(mom.clone());self.pop.append(dad.clone()); if replace % 2: #we did one to many - remove the last individual del self.pop[-1] self.stats['crossovers'] = self.stats['crossovers'] - 1 e1 = time.clock(); self.stats['mutations'] = self.stats['mutations'] + self.pop[sz:].mutate()
e3 = time.clock();
e3 = timer();
def step(self,steps=1): sz = len(self.pop) replace = int(self.settings['p_replace'] * len(self.pop)) p_crossover = self.settings['p_cross'] for st in range(steps): b = time.clock() for i in range(0,replace,2): mom,dad= self.pop.select(2) self.stats['selections'] = self.stats['selections'] + 2 if flip_coin(p_crossover): try: bro,sis = self.crossover((mom,dad)) self.stats['crossovers'] = self.stats['crossovers'] + 2 self.pop.append(bro); self.pop.append(sis) except ValueError: #crossover failed - just act as if this iteration never happened i = i - 2 #print 'crossover failure - ignoring and continuing' else: self.pop.append(mom.clone());self.pop.append(dad.clone()); if replace % 2: #we did one to many - remove the last individual del self.pop[-1] self.stats['crossovers'] = self.stats['crossovers'] - 1 e1 = time.clock(); self.stats['mutations'] = self.stats['mutations'] + self.pop[sz:].mutate()
e = time.clock(); self.step_time = e - b
e = timer(); self.step_time = e - b
def step(self,steps=1): sz = len(self.pop) replace = int(self.settings['p_replace'] * len(self.pop)) p_crossover = self.settings['p_cross'] for st in range(steps): b = time.clock() for i in range(0,replace,2): mom,dad= self.pop.select(2) self.stats['selections'] = self.stats['selections'] + 2 if flip_coin(p_crossover): try: bro,sis = self.crossover((mom,dad)) self.stats['crossovers'] = self.stats['crossovers'] + 2 self.pop.append(bro); self.pop.append(sis) except ValueError: #crossover failed - just act as if this iteration never happened i = i - 2 #print 'crossover failure - ignoring and continuing' else: self.pop.append(mom.clone());self.pop.append(dad.clone()); if replace % 2: #we did one to many - remove the last individual del self.pop[-1] self.stats['crossovers'] = self.stats['crossovers'] - 1 e1 = time.clock(); self.stats['mutations'] = self.stats['mutations'] + self.pop[sz:].mutate()
b = time.clock()
b = timer()
def evolve(self): b = time.clock() self.initialize() self.pre_evolve() self.p_dev = self.pop_deviation() self.iteration_output() while ( self.gen < self.settings['gens'] and self.settings['p_deviation'] < self.p_dev ): self.step() self.p_dev = self.pop_deviation() self.iteration_output() if(self.gen % self.settings['update_rate'] == 0): self.update_dbase() self.update_dbase() #enter status prior to post_evolve in dbase self.post_evolve() self.db_entry['run_time'] = time.clock() - b self.write_dbase()
self.db_entry['run_time'] = time.clock() - b
self.db_entry['run_time'] = timer() - b
def evolve(self): b = time.clock() self.initialize() self.pre_evolve() self.p_dev = self.pop_deviation() self.iteration_output() while ( self.gen < self.settings['gens'] and self.settings['p_deviation'] < self.p_dev ): self.step() self.p_dev = self.pop_deviation() self.iteration_output() if(self.gen % self.settings['update_rate'] == 0): self.update_dbase() self.update_dbase() #enter status prior to post_evolve in dbase self.post_evolve() self.db_entry['run_time'] = time.clock() - b self.write_dbase()
b = time.clock()
b = timer()
def initialize(self, mode = 'serial'): b = time.clock() #same as galg self.test_settings(self.settings) self.gen = 0 sd = self.settings['rand_seed']; alg = self.settings['rand_alg'] rv.initialize(seed = sd, algorithm = alg) self.settings['seed_used'] = rv.initial_seed() self._print('initializing... seed = %d' % self.settings['seed_used']) self.crossover = self.pop[0].crossover # get the crossover op from the first genome self.pop.settings = self.settings #end same as galg #set up my population to hold the best from each sub-pop self.pop._size(0) #erase any current member of the pop self.pop._size(self.settings['num_pops']) self.crossover = self.pop[0].crossover #extract the galg settings so we don't get a ton of warnings #and create the sub ga_s sub_ga_settings = {} self.GAs = [] for key in galg.valid_settings: sub_ga_settings[key] = self.settings[key] for i in range(self.settings['num_pops']): self.GAs.append(galg(self.pop.clone())) self.GAs[i].settings = sub_ga_settings.copy()
self.step_time = time.clock() - b
self.step_time = timer() - b
def initialize(self, mode = 'serial'): b = time.clock() #same as galg self.test_settings(self.settings) self.gen = 0 sd = self.settings['rand_seed']; alg = self.settings['rand_alg'] rv.initialize(seed = sd, algorithm = alg) self.settings['seed_used'] = rv.initial_seed() self._print('initializing... seed = %d' % self.settings['seed_used']) self.crossover = self.pop[0].crossover # get the crossover op from the first genome self.pop.settings = self.settings #end same as galg #set up my population to hold the best from each sub-pop self.pop._size(0) #erase any current member of the pop self.pop._size(self.settings['num_pops']) self.crossover = self.pop[0].crossover #extract the galg settings so we don't get a ton of warnings #and create the sub ga_s sub_ga_settings = {} self.GAs = [] for key in galg.valid_settings: sub_ga_settings[key] = self.settings[key] for i in range(self.settings['num_pops']): self.GAs.append(galg(self.pop.clone())) self.GAs[i].settings = sub_ga_settings.copy()
b = time.clock()
b = timer()
def step(self,steps=1,mode = 'serial'): for st in range(steps): b = time.clock() cnt = 0 #self.pop._size(0) # used if we keep a single pop if mode[0] == 'p' or mode[0] == 'P': """ sys.setcheckinterval(100) finished = sync.event() bar = sync.barrier(len(self.GAs)) for ga in self.GAs: thread.start_new_thread(GA_stepper,(bar,finished,ga)) finished.wait() sys.setcheckinterval(10) """ else: for ga in self.GAs: ga.step() for ga in self.GAs: #replace the worst member of the local pop self.pop[-1] = ga.pop.best() self.pop.sort() #probabaly not the fast approach to things, but... keeps an itelligent pop #for ind in ga.pop: self.pop.append(ind) self.migrate() self.gen = self.gen + 1 e = time.clock(); self.step_time = e - b self.update_stats() self.db_entry['best_scores'].append(self.stats['current']['max'])
e = time.clock(); self.step_time = e - b
e = timer(); self.step_time = e - b
def step(self,steps=1,mode = 'serial'): for st in range(steps): b = time.clock() cnt = 0 #self.pop._size(0) # used if we keep a single pop if mode[0] == 'p' or mode[0] == 'P': """ sys.setcheckinterval(100) finished = sync.event() bar = sync.barrier(len(self.GAs)) for ga in self.GAs: thread.start_new_thread(GA_stepper,(bar,finished,ga)) finished.wait() sys.setcheckinterval(10) """ else: for ga in self.GAs: ga.step() for ga in self.GAs: #replace the worst member of the local pop self.pop[-1] = ga.pop.best() self.pop.sort() #probabaly not the fast approach to things, but... keeps an itelligent pop #for ind in ga.pop: self.pop.append(ind) self.migrate() self.gen = self.gen + 1 e = time.clock(); self.step_time = e - b self.update_stats() self.db_entry['best_scores'].append(self.stats['current']['max'])
b = time.clock()
b = timer()
def evolve(self, mode = 'serial'): b = time.clock() self.initialize(mode) self.pre_evolve() self.p_dev = self.pop_deviation() self.iteration_output() while ( self.gen < self.settings['gens'] and self.settings['p_deviation'] < self.p_dev ): self.step(1,mode) self.p_dev = self.pop_deviation() self.iteration_output() self.update_dbase() #enter status prior to post_evolve in dbase self.post_evolve() self.db_entry['run_time'] = time.clock() - b self.write_dbase()
self.db_entry['run_time'] = time.clock() - b
self.db_entry['run_time'] = timer() - b
def evolve(self, mode = 'serial'): b = time.clock() self.initialize(mode) self.pre_evolve() self.p_dev = self.pop_deviation() self.iteration_output() while ( self.gen < self.settings['gens'] and self.settings['p_deviation'] < self.p_dev ): self.step(1,mode) self.p_dev = self.pop_deviation() self.iteration_output() self.update_dbase() #enter status prior to post_evolve in dbase self.post_evolve() self.db_entry['run_time'] = time.clock() - b self.write_dbase()
t1 = time.time()
t1 = timer()
def GA_stepper(bar,finished,GA): t1 = time.time() GA.step() t2 = time.time() print 'thread ' + `thread.get_ident()` + 'time ' + `t2-t1` + ' sec.' bar.enter() finished.post()
t2 = time.time()
t2 = timer()
def GA_stepper(bar,finished,GA): t1 = time.time() GA.step() t2 = time.time() print 'thread ' + `thread.get_ident()` + 'time ' + `t2-t1` + ' sec.' bar.enter() finished.post()
def __init__(self, format, maxprint=MAXPRINT, allocsize=ALLOCSIZE): self.format = format
def __init__(self, maxprint=MAXPRINT, allocsize=ALLOCSIZE): self.format = self.__class__.__name__[:3] if self.format == 'spm': raise ValueError, "This class is not intended" \ " to be instantiated directly."
def __init__(self, format, maxprint=MAXPRINT, allocsize=ALLOCSIZE): self.format = format self.maxprint = maxprint self.allocsize = allocsize
spmatrix.__init__(self, 'csc')
spmatrix.__init__(self)
def __init__(self,s,ij=None,M=None,N=None,nzmax=100,typecode=Float,copy=0): spmatrix.__init__(self, 'csc') if isinstance(s,spmatrix): if isinstance(s, csc_matrix): # do nothing but copy information self.shape = s.shape if copy: self.data = s.data.copy() self.rowind = s.rowind.copy() self.indptr = s.indptr.copy() else: self.data = s.data self.rowind = s.rowind self.indptr = s.indptr elif isinstance(s, csr_matrix): self.shape = s.shape func = getattr(sparsetools,s.ftype+'transp') self.data, self.rowind, self.indptr = \ func(s.shape[1], s.data, s.colind, s.indptr) else: temp = s.tocsc() self.data = temp.data self.rowind = temp.rowind self.indptr = temp.indptr self.shape = temp.shape elif isinstance(s,type(3)): M=s N=ij self.data = zeros((nzmax,),typecode) self.rowind = zeros((nzmax,),'i') self.indptr = zeros((N+1,),'i') self.shape = (M,N) elif (isinstance(s,ArrayType) or \ isinstance(s,type([]))): s = asarray(s) if s.typecode() not in 'fdFD': s = s*1.0 if (rank(s) == 2): # converting from a full array M, N = s.shape typecode = s.typecode() func = getattr(sparsetools,_transtabl[typecode]+'fulltocsc') ierr = irow = jcol = 0 nnz = sum(ravel(s != 0.0)) a = zeros((nnz,),typecode) rowa = zeros((nnz,),'i') ptra = zeros((N+1,),'i') while 1: a, rowa, ptra, irow, jcol, ierr = \ func(s, a, rowa, ptra, irow, jcol, ierr) if (ierr == 0): break nnz = nnz + ALLOCSIZE a = resize1d(a, nnz) rowa = resize1d(rowa, nnz)
spmatrix.__init__(self, 'csr')
spmatrix.__init__(self)
def __init__(self,s,ij=None,M=None,N=None,nzmax=100,typecode=Float,copy=0): spmatrix.__init__(self, 'csr') if isinstance(s,spmatrix): if isinstance(s, csr_matrix): # do nothing but copy information self.shape = s.shape if copy: self.data = s.data.copy() self.colind = s.colind.copy() self.indptr = s.indptr.copy() else: self.data = s.data self.colind = s.colind self.indptr = s.indptr elif isinstance(s, csc_matrix): self.shape = s.shape func = getattr(sparsetools,s.ftype+'transp') self.data, self.colind, self.indptr = \ func(s.shape[1], s.data, s.rowind, s.indptr) else: try: temp = s.tocsr() except AttributeError: temp = csr_matrix(s.tocsc()) self.data = temp.data self.rowind = temp.rowind self.indptr = temp.indptr self.shape = temp.shape elif isinstance(s,type(3)): M=s N=ij self.data = zeros((nzmax,),typecode) self.colind = zeros((nzmax,),'i') self.indptr = zeros((M+1,),'i') self.shape = (M,N) elif (isinstance(s,ArrayType) or \ isinstance(s,type([]))): s = asarray(s) if (rank(s) == 2): # converting from a full array ocsc = csc_matrix(transpose(s)) self.shape = ocsc.shape[1], ocsc.shape[0] self.colind = ocsc.rowind self.indptr = ocsc.indptr self.data = ocsc.data elif isinstance(ij, ArrayType) and (rank(ij) == 2) and (shape(ij) == (len(s),2)): ijnew = ij.copy() ijnew[:,0] = ij[:,1] ijnew[:,1] = ij[:,0] temp = coo_matrix(s,ijnew,M=M,N=N,nzmax=nzmax, typecode=typecode) temp = temp.tocsc() self.data = temp.data self.colind = temp.colind self.indptr = temp.indptr self.shape = temp.shape elif isinstance(ij, types.TupleType) and (len(ij)==2): self.data = asarray(s) self.colind = ij[0] self.indptr = ij[1] if N is None: try: N = amax(self.colind) + 1 except ValueError: N = 0 if M is None: M = len(self.indptr) - 1 if M == -1: M = 0 self.shape = (M,N) else: raise ValueError, "Unrecognized form for csr_matrix constructor." else: raise ValueError, "Unrecognized form for csr_matrix constructor."
spmatrix.__init__(self,'dok')
spmatrix.__init__(self)
def __init__(self,A=None): dict.__init__(self) spmatrix.__init__(self,'dok') self.shape = (0,0) self.nnz = 0 if A is not None: A = asarray(A) N,M = A.shape for n in range(N): for m in range(M): if A[n,m] != 0: self[n,m] = A[n,m]
spmatrix.__init__(self, 'coo')
spmatrix.__init__(self)
def __init__(self, obj, ij, M=None, N=None, nzmax=None, typecode=None): spmatrix.__init__(self, 'coo') if type(ij) is type(()) and len(ij)==2: if M is None: M = amax(ij[0]) if N is None: N = amax(ij[1]) self.row = asarray(ij[0],'i') self.col = asarray(ij[1],'i') else: aij = asarray(ij,'i') if M is None: M = amax(aij[:,0]) if N is None: N = amax(aij[:,1]) self.row = aij[:,0] self.col = aij[:,1] aobj = asarray(obj,typecode=typecode) self.shape = (M,N) if nzmax is None: nzmax = len(aobj) self.nzmax = nzmax self.data = aobj self.typecode = aobj.typecode() self._check()
Pk = mu**k * exp(-mu) / arr(special.gamma(k+1)) return Pk
Pk = k*log(mu)-special.gammaln(k+1) - mu return exp(Pk)
def _pmf(self, k, mu): Pk = mu**k * exp(-mu) / arr(special.gamma(k+1)) return Pk
ret_val = apply(obj, args, kw)
ret_val = apply(obj, d_args, d_kw)
def __call__(self, *args, **kw): """Performs the call to the proxied callable object by dispatching the method to the secondary thread.""" obj = self.__dont_mess_with_me_unless_you_know_what_youre_doing ret_val = None if main.in_proxy_call: ret_val = apply(obj, args, kw) else: finished = threading.Event() evt = proxy_event(obj, args, kw, finished) wxPostEvent(self.catcher, evt) finished.wait() if finished.exception_info: raise finished.exception_info[0], \ finished.exception_info[1] ret_val = finished._result return smart_return(ret_val)
evt = proxy_event(obj, args, kw, finished)
evt = proxy_event(obj, d_args, d_kw, finished)
def __call__(self, *args, **kw): """Performs the call to the proxied callable object by dispatching the method to the secondary thread.""" obj = self.__dont_mess_with_me_unless_you_know_what_youre_doing ret_val = None if main.in_proxy_call: ret_val = apply(obj, args, kw) else: finished = threading.Event() evt = proxy_event(obj, args, kw, finished) wxPostEvent(self.catcher, evt) finished.wait() if finished.exception_info: raise finished.exception_info[0], \ finished.exception_info[1] ret_val = finished._result return smart_return(ret_val)
exec(function)
exec function in globals(), locals()
def remap (listoflists,criterion): function = 'lines = map(lambda x: '+criterion+',listoflists)' exec(function) return lines
p = [-.9077932138396487614720659-82196399419401501888968130.0E-27*1j, -.9077932138396487614720659+82196399419401501888968130.0E-27*1j,
p = [-.9077932138396487614720659-82196399419401501888968130.0e-27*1j, -.9077932138396487614720659+82196399419401501888968130.0e-27*1j,
def besselap(N): """Return (z,p,k) zero, pole, gain for analog prototype of an Nth order Bessel filter.""" z = [] k = 1 if N == 0: p = []; elif N == 1: p = [-1] elif N == 2: p = [-.8660254037844386467637229+.4999999999999999999999996*1j, -.8660254037844386467637229-.4999999999999999999999996*1j] elif N == 3: p = [-.9416000265332067855971980, -.7456403858480766441810907-.7113666249728352680992154*1j, -.7456403858480766441810907+.7113666249728352680992154*1j] elif N == 4: p = [-.6572111716718829545787781-.8301614350048733772399715*1j, -.6572111716718829545787788+.8301614350048733772399715*1j, -.9047587967882449459642637-.2709187330038746636700923*1j, -.9047587967882449459642624+.2709187330038746636700926*1j] elif N == 5: p = [-.9264420773877602247196260, -.8515536193688395541722677-.4427174639443327209850002*1j, -.8515536193688395541722677+.4427174639443327209850002*1j, -.5905759446119191779319432-.9072067564574549539291747*1j, -.5905759446119191779319432+.9072067564574549539291747*1j] elif N == 6: p = [-.9093906830472271808050953-.1856964396793046769246397*1j, -.9093906830472271808050953+.1856964396793046769246397*1j, -.7996541858328288520243325-.5621717346937317988594118*1j, -.7996541858328288520243325+.5621717346937317988594118*1j, -.5385526816693109683073792-.9616876881954277199245657*1j, -.5385526816693109683073792+.9616876881954277199245657*1j] elif N == 7: p = [-.9194871556490290014311619, -.8800029341523374639772340-.3216652762307739398381830*1j, -.8800029341523374639772340+.3216652762307739398381830*1j, -.7527355434093214462291616-.6504696305522550699212995*1j, -.7527355434093214462291616+.6504696305522550699212995*1j, -.4966917256672316755024763-1.002508508454420401230220*1j, -.4966917256672316755024763+1.002508508454420401230220*1j] elif N == 8: p = [-.9096831546652910216327629-.1412437976671422927888150*1j, -.9096831546652910216327629+.1412437976671422927888150*1j, -.8473250802359334320103023-.4259017538272934994996429*1j, -.8473250802359334320103023+.4259017538272934994996429*1j, -.7111381808485399250796172-.7186517314108401705762571*1j, -.7111381808485399250796172+.7186517314108401705762571*1j, -.4621740412532122027072175-1.034388681126901058116589*1j, -.4621740412532122027072175+1.034388681126901058116589*1j] elif N == 9: p = [-.9154957797499037686769223, -.8911217017079759323183848-.2526580934582164192308115*1j, -.8911217017079759323183848+.2526580934582164192308115*1j, -.8148021112269012975514135-.5085815689631499483745341*1j, -.8148021112269012975514135+.5085815689631499483745341*1j, -.6743622686854761980403401-.7730546212691183706919682*1j, -.6743622686854761980403401+.7730546212691183706919682*1j, -.4331415561553618854685942-1.060073670135929666774323*1j, -.4331415561553618854685942+1.060073670135929666774323*1j] elif N == 10: p = [-.9091347320900502436826431-.1139583137335511169927714*1j, -.9091347320900502436826431+.1139583137335511169927714*1j, -.8688459641284764527921864-.3430008233766309973110589*1j, -.8688459641284764527921864+.3430008233766309973110589*1j, -.7837694413101441082655890-.5759147538499947070009852*1j, -.7837694413101441082655890+.5759147538499947070009852*1j, -.6417513866988316136190854-.8175836167191017226233947*1j, -.6417513866988316136190854+.8175836167191017226233947*1j, -.4083220732868861566219785-1.081274842819124562037210*1j, -.4083220732868861566219785+1.081274842819124562037210*1j] elif N == 11: p = [-.9129067244518981934637318, -.8963656705721166099815744-.2080480375071031919692341*1j -.8963656705721166099815744+.2080480375071031919692341*1j, -.8453044014712962954184557-.4178696917801248292797448*1j, -.8453044014712962954184557+.4178696917801248292797448*1j, -.7546938934722303128102142-.6319150050721846494520941*1j, -.7546938934722303128102142+.6319150050721846494520941*1j, -.6126871554915194054182909-.8547813893314764631518509*1j, -.6126871554915194054182909+.8547813893314764631518509*1j, -.3868149510055090879155425-1.099117466763120928733632*1j, -.3868149510055090879155425+1.099117466763120928733632*1j] elif N == 12: p = [-.9084478234140682638817772-95506365213450398415258360.0e-27*1j, -.9084478234140682638817772+95506365213450398415258360.0e-27*1j, -.8802534342016826507901575-.2871779503524226723615457*1j, -.8802534342016826507901575+.2871779503524226723615457*1j, -.8217296939939077285792834-.4810212115100676440620548*1j, -.8217296939939077285792834+.4810212115100676440620548*1j, -.7276681615395159454547013-.6792961178764694160048987*1j, -.7276681615395159454547013+.6792961178764694160048987*1j, -.5866369321861477207528215-.8863772751320727026622149*1j, -.5866369321861477207528215+.8863772751320727026622149*1j, -.3679640085526312839425808-1.114373575641546257595657*1j, -.3679640085526312839425808+1.114373575641546257595657*1j] elif N == 13: p = [-.9110914665984182781070663, -.8991314665475196220910718-.1768342956161043620980863*1j, -.8991314665475196220910718+.1768342956161043620980863*1j, -.8625094198260548711573628-.3547413731172988997754038*1j, -.8625094198260548711573628+.3547413731172988997754038*1j, -.7987460692470972510394686-.5350752120696801938272504*1j, -.7987460692470972510394686+.5350752120696801938272504*1j, -.7026234675721275653944062-.7199611890171304131266374*1j, -.7026234675721275653944062+.7199611890171304131266374*1j, -.5631559842430199266325818-.9135900338325109684927731*1j, -.5631559842430199266325818+.9135900338325109684927731*1j, -.3512792323389821669401925-1.127591548317705678613239*1j, -.3512792323389821669401925+1.127591548317705678613239*1j] elif N == 14: p = [-.9077932138396487614720659-82196399419401501888968130.0E-27*1j, -.9077932138396487614720659+82196399419401501888968130.0E-27*1j, -.8869506674916445312089167-.2470079178765333183201435*1j, -.8869506674916445312089167+.2470079178765333183201435*1j, -.8441199160909851197897667-.4131653825102692595237260*1j, -.8441199160909851197897667+.4131653825102692595237260*1j, -.7766591387063623897344648-.5819170677377608590492434*1j, -.7766591387063623897344648+.5819170677377608590492434*1j, -.6794256425119233117869491-.7552857305042033418417492*1j, -.6794256425119233117869491+.7552857305042033418417492*1j, -.5418766775112297376541293-.9373043683516919569183099*1j, -.5418766775112297376541293+.9373043683516919569183099*1j, -.3363868224902037330610040-1.139172297839859991370924*1j, -.3363868224902037330610040+1.139172297839859991370924*1j] elif N == 15: p = [-.9097482363849064167228581, -.9006981694176978324932918-.1537681197278439351298882*1j, -.9006981694176978324932918+.1537681197278439351298882*1j, -.8731264620834984978337843-.3082352470564267657715883*1j, -.8731264620834984978337843+.3082352470564267657715883*1j, -.8256631452587146506294553-.4642348752734325631275134*1j, -.8256631452587146506294553+.4642348752734325631275134*1j, -.7556027168970728127850416-.6229396358758267198938604*1j, -.7556027168970728127850416+.6229396358758267198938604*1j, -.6579196593110998676999362-.7862895503722515897065645*1j, -.6579196593110998676999362+.7862895503722515897065645*1j, -.5224954069658330616875186-.9581787261092526478889345*1j, -.5224954069658330616875186+.9581787261092526478889345*1j, -.3229963059766444287113517-1.149416154583629539665297*1j, -.3229963059766444287113517+1.149416154583629539665297*1j] elif N == 16: p = [-.9072099595087001356491337-72142113041117326028823950.0E-27*1j, -.9072099595087001356491337+72142113041117326028823950.0E-27*1j, -.8911723070323647674780132-.2167089659900576449410059*1j, -.8911723070323647674780132+.2167089659900576449410059*1j, -.8584264231521330481755780-.3621697271802065647661080*1j, -.8584264231521330481755780+.3621697271802065647661080*1j, -.8074790293236003885306146-.5092933751171800179676218*1j, -.8074790293236003885306146+.5092933751171800179676218*1j, -.7356166304713115980927279-.6591950877860393745845254*1j, -.7356166304713115980927279+.6591950877860393745845254*1j, -.6379502514039066715773828-.8137453537108761895522580*1j, -.6379502514039066715773828+.8137453537108761895522580*1j, -.5047606444424766743309967-.9767137477799090692947061*1j, -.5047606444424766743309967+.9767137477799090692947061*1j, -.3108782755645387813283867-1.158552841199330479412225*1j, -.3108782755645387813283867+1.158552841199330479412225*1j] elif N == 17: p = [-.9087141161336397432860029, -.9016273850787285964692844-.1360267995173024591237303*1j, -.9016273850787285964692844+.1360267995173024591237303*1j, -.8801100704438627158492165-.2725347156478803885651973*1j, -.8801100704438627158492165+.2725347156478803885651973*1j, -.8433414495836129204455491-.4100759282910021624185986*1j, -.8433414495836129204455491+.4100759282910021624185986*1j, -.7897644147799708220288138-.5493724405281088674296232*1j, -.7897644147799708220288138+.5493724405281088674296232*1j, -.7166893842372349049842743-.6914936286393609433305754*1j, -.7166893842372349049842743+.6914936286393609433305754*1j, -.6193710717342144521602448-.8382497252826992979368621*1j, -.6193710717342144521602448+.8382497252826992979368621*1j, -.4884629337672704194973683-.9932971956316781632345466*1j, -.4884629337672704194973683+.9932971956316781632345466*1j, -.2998489459990082015466971-1.166761272925668786676672*1j, -.2998489459990082015466971+1.166761272925668786676672*1j] elif N == 18: p = [-.9067004324162775554189031-64279241063930693839360680.0E-27*1j, -.9067004324162775554189031+64279241063930693839360680.0E-27*1j, -.8939764278132455733032155-.1930374640894758606940586*1j, -.8939764278132455733032155+.1930374640894758606940586*1j, -.8681095503628830078317207-.3224204925163257604931634*1j, -.8681095503628830078317207+.3224204925163257604931634*1j, -.8281885016242836608829018-.4529385697815916950149364*1j, -.8281885016242836608829018+.4529385697815916950149364*1j, -.7726285030739558780127746-.5852778162086640620016316*1j, -.7726285030739558780127746+.5852778162086640620016316*1j, -.6987821445005273020051878-.7204696509726630531663123*1j, -.6987821445005273020051878+.7204696509726630531663123*1j, -.6020482668090644386627299-.8602708961893664447167418*1j, -.6020482668090644386627299+.8602708961893664447167418*1j, -.4734268069916151511140032-1.008234300314801077034158*1j, -.4734268069916151511140032+1.008234300314801077034158*1j, -.2897592029880489845789953-1.174183010600059128532230*1j, -.2897592029880489845789953+1.174183010600059128532230*1j] elif N == 19: p = [-.9078934217899404528985092, -.9021937639390660668922536-.1219568381872026517578164*1j, -.9021937639390660668922536+.1219568381872026517578164*1j, -.8849290585034385274001112-.2442590757549818229026280*1j, -.8849290585034385274001112+.2442590757549818229026280*1j, -.8555768765618421591093993-.3672925896399872304734923*1j, -.8555768765618421591093993+.3672925896399872304734923*1j, -.8131725551578197705476160-.4915365035562459055630005*1j, -.8131725551578197705476160+.4915365035562459055630005*1j, -.7561260971541629355231897-.6176483917970178919174173*1j, -.7561260971541629355231897+.6176483917970178919174173*1j, -.6818424412912442033411634-.7466272357947761283262338*1j, -.6818424412912442033411634+.7466272357947761283262338*1j, -.5858613321217832644813602-.8801817131014566284786759*1j, -.5858613321217832644813602+.8801817131014566284786759*1j, -.4595043449730988600785456-1.021768776912671221830298*1j, -.4595043449730988600785456+1.021768776912671221830298*1j, -.2804866851439370027628724-1.180931628453291873626003*1j, -.2804866851439370027628724+1.180931628453291873626003*1j] elif N == 20: p = [-.9062570115576771146523497-57961780277849516990208850.0E-27*1j, -.9062570115576771146523497+57961780277849516990208850.0E-27*1j, -.8959150941925768608568248-.1740317175918705058595844*1j, -.8959150941925768608568248+.1740317175918705058595844*1j, -.8749560316673332850673214-.2905559296567908031706902*1j, -.8749560316673332850673214+.2905559296567908031706902*1j, -.8427907479956670633544106-.4078917326291934082132821*1j, -.8427907479956670633544106+.4078917326291934082132821*1j, -.7984251191290606875799876-.5264942388817132427317659*1j, -.7984251191290606875799876+.5264942388817132427317659*1j, -.7402780309646768991232610-.6469975237605228320268752*1j, -.7402780309646768991232610+.6469975237605228320268752*1j, -.6658120544829934193890626-.7703721701100763015154510*1j, -.6658120544829934193890626+.7703721701100763015154510*1j, -.5707026806915714094398061-.8982829066468255593407161*1j, -.5707026806915714094398061+.8982829066468255593407161*1j, -.4465700698205149555701841-1.034097702560842962315411*1j, -.4465700698205149555701841+1.034097702560842962315411*1j, -.2719299580251652601727704-1.187099379810885886139638*1j, -.2719299580251652601727704+1.187099379810885886139638*1j] elif N == 21: p = [-.9072262653142957028884077, -.9025428073192696303995083-.1105252572789856480992275*1j, -.9025428073192696303995083+.1105252572789856480992275*1j, -.8883808106664449854431605-.2213069215084350419975358*1j, -.8883808106664449854431605+.2213069215084350419975358*1j, -.8643915813643204553970169-.3326258512522187083009453*1j, -.8643915813643204553970169+.3326258512522187083009453*1j, -.8299435470674444100273463-.4448177739407956609694059*1j, -.8299435470674444100273463+.4448177739407956609694059*1j, -.7840287980408341576100581-.5583186348022854707564856*1j, -.7840287980408341576100581+.5583186348022854707564856*1j, -.7250839687106612822281339-.6737426063024382240549898*1j, -.7250839687106612822281339+.6737426063024382240549898*1j, -.6506315378609463397807996-.7920349342629491368548074*1j, -.6506315378609463397807996+.7920349342629491368548074*1j, -.5564766488918562465935297-.9148198405846724121600860*1j, -.5564766488918562465935297+.9148198405846724121600860*1j, -.4345168906815271799687308-1.045382255856986531461592*1j, -.4345168906815271799687308+1.045382255856986531461592*1j, -.2640041595834031147954813-1.192762031948052470183960*1j, -.2640041595834031147954813+1.192762031948052470183960*1j] elif N == 22: p = [-.9058702269930872551848625-52774908289999045189007100.0E-27*1j, -.9058702269930872551848625+52774908289999045189007100.0E-27*1j, -.8972983138153530955952835-.1584351912289865608659759*1j, -.8972983138153530955952835+.1584351912289865608659759*1j, -.8799661455640176154025352-.2644363039201535049656450*1j, -.8799661455640176154025352+.2644363039201535049656450*1j, -.8534754036851687233084587-.3710389319482319823405321*1j, -.8534754036851687233084587+.3710389319482319823405321*1j, -.8171682088462720394344996-.4785619492202780899653575*1j, -.8171682088462720394344996+.4785619492202780899653575*1j, -.7700332930556816872932937-.5874255426351153211965601*1j, -.7700332930556816872932937+.5874255426351153211965601*1j, -.7105305456418785989070935-.6982266265924524000098548*1j, -.7105305456418785989070935+.6982266265924524000098548*1j, -.6362427683267827226840153-.8118875040246347267248508*1j, -.6362427683267827226840153+.8118875040246347267248508*1j, -.5430983056306302779658129-.9299947824439872998916657*1j, -.5430983056306302779658129+.9299947824439872998916657*1j, -.4232528745642628461715044-1.055755605227545931204656*1j, -.4232528745642628461715044+1.055755605227545931204656*1j, -.2566376987939318038016012-1.197982433555213008346532*1j, -.2566376987939318038016012+1.197982433555213008346532*1j] elif N == 23: p = [-.9066732476324988168207439, -.9027564979912504609412993-.1010534335314045013252480*1j, -.9027564979912504609412993+.1010534335314045013252480*1j, -.8909283242471251458653994-.2023024699381223418195228*1j, -.8909283242471251458653994+.2023024699381223418195228*1j, -.8709469395587416239596874-.3039581993950041588888925*1j, -.8709469395587416239596874+.3039581993950041588888925*1j, -.8423805948021127057054288-.4062657948237602726779246*1j, -.8423805948021127057054288+.4062657948237602726779246*1j, -.8045561642053176205623187-.5095305912227258268309528*1j, -.8045561642053176205623187+.5095305912227258268309528*1j, -.7564660146829880581478138-.6141594859476032127216463*1j, -.7564660146829880581478138+.6141594859476032127216463*1j, -.6965966033912705387505040-.7207341374753046970247055*1j, -.6965966033912705387505040+.7207341374753046970247055*1j, -.6225903228771341778273152-.8301558302812980678845563*1j, -.6225903228771341778273152+.8301558302812980678845563*1j, -.5304922463810191698502226-.9439760364018300083750242*1j, -.5304922463810191698502226+.9439760364018300083750242*1j, -.4126986617510148836149955-1.065328794475513585531053*1j, -.4126986617510148836149955+1.065328794475513585531053*1j, -.2497697202208956030229911-1.202813187870697831365338*1j, -.2497697202208956030229911+1.202813187870697831365338*1j] elif N == 24: p = [-.9055312363372773709269407-48440066540478700874836350.0E-27*1j, -.9055312363372773709269407+48440066540478700874836350.0E-27*1j, -.8983105104397872954053307-.1454056133873610120105857*1j, -.8983105104397872954053307+.1454056133873610120105857*1j, -.8837358034555706623131950-.2426335234401383076544239*1j, -.8837358034555706623131950+.2426335234401383076544239*1j, -.8615278304016353651120610-.3403202112618624773397257*1j, -.8615278304016353651120610+.3403202112618624773397257*1j, -.8312326466813240652679563-.4386985933597305434577492*1j, -.8312326466813240652679563+.4386985933597305434577492*1j, -.7921695462343492518845446-.5380628490968016700338001*1j, -.7921695462343492518845446+.5380628490968016700338001*1j, -.7433392285088529449175873-.6388084216222567930378296*1j, -.7433392285088529449175873+.6388084216222567930378296*1j, -.6832565803536521302816011-.7415032695091650806797753*1j, -.6832565803536521302816011+.7415032695091650806797753*1j, -.6096221567378335562589532-.8470292433077202380020454*1j, -.6096221567378335562589532+.8470292433077202380020454*1j, -.5185914574820317343536707-.9569048385259054576937721*1j, -.5185914574820317343536707+.9569048385259054576937721*1j, -.4027853855197518014786978-1.074195196518674765143729*1j, -.4027853855197518014786978+1.074195196518674765143729*1j, -.2433481337524869675825448-1.207298683731972524975429*1j, -.2433481337524869675825448+1.207298683731972524975429*1j] elif N == 25: p = [-.9062073871811708652496104, -.9028833390228020537142561-93077131185102967450643820.0E-27*1j, -.9028833390228020537142561+93077131185102967450643820.0E-27*1j, -.8928551459883548836774529-.1863068969804300712287138*1j, -.8928551459883548836774529+.1863068969804300712287138*1j, -.8759497989677857803656239-.2798521321771408719327250*1j, -.8759497989677857803656239+.2798521321771408719327250*1j, -.8518616886554019782346493-.3738977875907595009446142*1j, -.8518616886554019782346493+.3738977875907595009446142*1j, -.8201226043936880253962552-.4686668574656966589020580*1j, -.8201226043936880253962552+.4686668574656966589020580*1j, -.7800496278186497225905443-.5644441210349710332887354*1j, -.7800496278186497225905443+.5644441210349710332887354*1j, -.7306549271849967721596735-.6616149647357748681460822*1j, -.7306549271849967721596735+.6616149647357748681460822*1j, -.6704827128029559528610523-.7607348858167839877987008*1j, -.6704827128029559528610523+.7607348858167839877987008*1j, -.5972898661335557242320528-.8626676330388028512598538*1j, -.5972898661335557242320528+.8626676330388028512598538*1j, -.5073362861078468845461362-.9689006305344868494672405*1j, -.5073362861078468845461362+.9689006305344868494672405*1j, -.3934529878191079606023847-1.082433927173831581956863*1j, -.3934529878191079606023847+1.082433927173831581956863*1j, -.2373280669322028974199184-1.211476658382565356579418*1j, -.2373280669322028974199184+1.211476658382565356579418*1j] else: raise ValueError, "Bessel Filter not supported for order %d" % N return z, p, k
p = [-.9072099595087001356491337-72142113041117326028823950.0E-27*1j, -.9072099595087001356491337+72142113041117326028823950.0E-27*1j,
p = [-.9072099595087001356491337-72142113041117326028823950.0e-27*1j, -.9072099595087001356491337+72142113041117326028823950.0e-27*1j,
def besselap(N): """Return (z,p,k) zero, pole, gain for analog prototype of an Nth order Bessel filter.""" z = [] k = 1 if N == 0: p = []; elif N == 1: p = [-1] elif N == 2: p = [-.8660254037844386467637229+.4999999999999999999999996*1j, -.8660254037844386467637229-.4999999999999999999999996*1j] elif N == 3: p = [-.9416000265332067855971980, -.7456403858480766441810907-.7113666249728352680992154*1j, -.7456403858480766441810907+.7113666249728352680992154*1j] elif N == 4: p = [-.6572111716718829545787781-.8301614350048733772399715*1j, -.6572111716718829545787788+.8301614350048733772399715*1j, -.9047587967882449459642637-.2709187330038746636700923*1j, -.9047587967882449459642624+.2709187330038746636700926*1j] elif N == 5: p = [-.9264420773877602247196260, -.8515536193688395541722677-.4427174639443327209850002*1j, -.8515536193688395541722677+.4427174639443327209850002*1j, -.5905759446119191779319432-.9072067564574549539291747*1j, -.5905759446119191779319432+.9072067564574549539291747*1j] elif N == 6: p = [-.9093906830472271808050953-.1856964396793046769246397*1j, -.9093906830472271808050953+.1856964396793046769246397*1j, -.7996541858328288520243325-.5621717346937317988594118*1j, -.7996541858328288520243325+.5621717346937317988594118*1j, -.5385526816693109683073792-.9616876881954277199245657*1j, -.5385526816693109683073792+.9616876881954277199245657*1j] elif N == 7: p = [-.9194871556490290014311619, -.8800029341523374639772340-.3216652762307739398381830*1j, -.8800029341523374639772340+.3216652762307739398381830*1j, -.7527355434093214462291616-.6504696305522550699212995*1j, -.7527355434093214462291616+.6504696305522550699212995*1j, -.4966917256672316755024763-1.002508508454420401230220*1j, -.4966917256672316755024763+1.002508508454420401230220*1j] elif N == 8: p = [-.9096831546652910216327629-.1412437976671422927888150*1j, -.9096831546652910216327629+.1412437976671422927888150*1j, -.8473250802359334320103023-.4259017538272934994996429*1j, -.8473250802359334320103023+.4259017538272934994996429*1j, -.7111381808485399250796172-.7186517314108401705762571*1j, -.7111381808485399250796172+.7186517314108401705762571*1j, -.4621740412532122027072175-1.034388681126901058116589*1j, -.4621740412532122027072175+1.034388681126901058116589*1j] elif N == 9: p = [-.9154957797499037686769223, -.8911217017079759323183848-.2526580934582164192308115*1j, -.8911217017079759323183848+.2526580934582164192308115*1j, -.8148021112269012975514135-.5085815689631499483745341*1j, -.8148021112269012975514135+.5085815689631499483745341*1j, -.6743622686854761980403401-.7730546212691183706919682*1j, -.6743622686854761980403401+.7730546212691183706919682*1j, -.4331415561553618854685942-1.060073670135929666774323*1j, -.4331415561553618854685942+1.060073670135929666774323*1j] elif N == 10: p = [-.9091347320900502436826431-.1139583137335511169927714*1j, -.9091347320900502436826431+.1139583137335511169927714*1j, -.8688459641284764527921864-.3430008233766309973110589*1j, -.8688459641284764527921864+.3430008233766309973110589*1j, -.7837694413101441082655890-.5759147538499947070009852*1j, -.7837694413101441082655890+.5759147538499947070009852*1j, -.6417513866988316136190854-.8175836167191017226233947*1j, -.6417513866988316136190854+.8175836167191017226233947*1j, -.4083220732868861566219785-1.081274842819124562037210*1j, -.4083220732868861566219785+1.081274842819124562037210*1j] elif N == 11: p = [-.9129067244518981934637318, -.8963656705721166099815744-.2080480375071031919692341*1j -.8963656705721166099815744+.2080480375071031919692341*1j, -.8453044014712962954184557-.4178696917801248292797448*1j, -.8453044014712962954184557+.4178696917801248292797448*1j, -.7546938934722303128102142-.6319150050721846494520941*1j, -.7546938934722303128102142+.6319150050721846494520941*1j, -.6126871554915194054182909-.8547813893314764631518509*1j, -.6126871554915194054182909+.8547813893314764631518509*1j, -.3868149510055090879155425-1.099117466763120928733632*1j, -.3868149510055090879155425+1.099117466763120928733632*1j] elif N == 12: p = [-.9084478234140682638817772-95506365213450398415258360.0e-27*1j, -.9084478234140682638817772+95506365213450398415258360.0e-27*1j, -.8802534342016826507901575-.2871779503524226723615457*1j, -.8802534342016826507901575+.2871779503524226723615457*1j, -.8217296939939077285792834-.4810212115100676440620548*1j, -.8217296939939077285792834+.4810212115100676440620548*1j, -.7276681615395159454547013-.6792961178764694160048987*1j, -.7276681615395159454547013+.6792961178764694160048987*1j, -.5866369321861477207528215-.8863772751320727026622149*1j, -.5866369321861477207528215+.8863772751320727026622149*1j, -.3679640085526312839425808-1.114373575641546257595657*1j, -.3679640085526312839425808+1.114373575641546257595657*1j] elif N == 13: p = [-.9110914665984182781070663, -.8991314665475196220910718-.1768342956161043620980863*1j, -.8991314665475196220910718+.1768342956161043620980863*1j, -.8625094198260548711573628-.3547413731172988997754038*1j, -.8625094198260548711573628+.3547413731172988997754038*1j, -.7987460692470972510394686-.5350752120696801938272504*1j, -.7987460692470972510394686+.5350752120696801938272504*1j, -.7026234675721275653944062-.7199611890171304131266374*1j, -.7026234675721275653944062+.7199611890171304131266374*1j, -.5631559842430199266325818-.9135900338325109684927731*1j, -.5631559842430199266325818+.9135900338325109684927731*1j, -.3512792323389821669401925-1.127591548317705678613239*1j, -.3512792323389821669401925+1.127591548317705678613239*1j] elif N == 14: p = [-.9077932138396487614720659-82196399419401501888968130.0E-27*1j, -.9077932138396487614720659+82196399419401501888968130.0E-27*1j, -.8869506674916445312089167-.2470079178765333183201435*1j, -.8869506674916445312089167+.2470079178765333183201435*1j, -.8441199160909851197897667-.4131653825102692595237260*1j, -.8441199160909851197897667+.4131653825102692595237260*1j, -.7766591387063623897344648-.5819170677377608590492434*1j, -.7766591387063623897344648+.5819170677377608590492434*1j, -.6794256425119233117869491-.7552857305042033418417492*1j, -.6794256425119233117869491+.7552857305042033418417492*1j, -.5418766775112297376541293-.9373043683516919569183099*1j, -.5418766775112297376541293+.9373043683516919569183099*1j, -.3363868224902037330610040-1.139172297839859991370924*1j, -.3363868224902037330610040+1.139172297839859991370924*1j] elif N == 15: p = [-.9097482363849064167228581, -.9006981694176978324932918-.1537681197278439351298882*1j, -.9006981694176978324932918+.1537681197278439351298882*1j, -.8731264620834984978337843-.3082352470564267657715883*1j, -.8731264620834984978337843+.3082352470564267657715883*1j, -.8256631452587146506294553-.4642348752734325631275134*1j, -.8256631452587146506294553+.4642348752734325631275134*1j, -.7556027168970728127850416-.6229396358758267198938604*1j, -.7556027168970728127850416+.6229396358758267198938604*1j, -.6579196593110998676999362-.7862895503722515897065645*1j, -.6579196593110998676999362+.7862895503722515897065645*1j, -.5224954069658330616875186-.9581787261092526478889345*1j, -.5224954069658330616875186+.9581787261092526478889345*1j, -.3229963059766444287113517-1.149416154583629539665297*1j, -.3229963059766444287113517+1.149416154583629539665297*1j] elif N == 16: p = [-.9072099595087001356491337-72142113041117326028823950.0E-27*1j, -.9072099595087001356491337+72142113041117326028823950.0E-27*1j, -.8911723070323647674780132-.2167089659900576449410059*1j, -.8911723070323647674780132+.2167089659900576449410059*1j, -.8584264231521330481755780-.3621697271802065647661080*1j, -.8584264231521330481755780+.3621697271802065647661080*1j, -.8074790293236003885306146-.5092933751171800179676218*1j, -.8074790293236003885306146+.5092933751171800179676218*1j, -.7356166304713115980927279-.6591950877860393745845254*1j, -.7356166304713115980927279+.6591950877860393745845254*1j, -.6379502514039066715773828-.8137453537108761895522580*1j, -.6379502514039066715773828+.8137453537108761895522580*1j, -.5047606444424766743309967-.9767137477799090692947061*1j, -.5047606444424766743309967+.9767137477799090692947061*1j, -.3108782755645387813283867-1.158552841199330479412225*1j, -.3108782755645387813283867+1.158552841199330479412225*1j] elif N == 17: p = [-.9087141161336397432860029, -.9016273850787285964692844-.1360267995173024591237303*1j, -.9016273850787285964692844+.1360267995173024591237303*1j, -.8801100704438627158492165-.2725347156478803885651973*1j, -.8801100704438627158492165+.2725347156478803885651973*1j, -.8433414495836129204455491-.4100759282910021624185986*1j, -.8433414495836129204455491+.4100759282910021624185986*1j, -.7897644147799708220288138-.5493724405281088674296232*1j, -.7897644147799708220288138+.5493724405281088674296232*1j, -.7166893842372349049842743-.6914936286393609433305754*1j, -.7166893842372349049842743+.6914936286393609433305754*1j, -.6193710717342144521602448-.8382497252826992979368621*1j, -.6193710717342144521602448+.8382497252826992979368621*1j, -.4884629337672704194973683-.9932971956316781632345466*1j, -.4884629337672704194973683+.9932971956316781632345466*1j, -.2998489459990082015466971-1.166761272925668786676672*1j, -.2998489459990082015466971+1.166761272925668786676672*1j] elif N == 18: p = [-.9067004324162775554189031-64279241063930693839360680.0E-27*1j, -.9067004324162775554189031+64279241063930693839360680.0E-27*1j, -.8939764278132455733032155-.1930374640894758606940586*1j, -.8939764278132455733032155+.1930374640894758606940586*1j, -.8681095503628830078317207-.3224204925163257604931634*1j, -.8681095503628830078317207+.3224204925163257604931634*1j, -.8281885016242836608829018-.4529385697815916950149364*1j, -.8281885016242836608829018+.4529385697815916950149364*1j, -.7726285030739558780127746-.5852778162086640620016316*1j, -.7726285030739558780127746+.5852778162086640620016316*1j, -.6987821445005273020051878-.7204696509726630531663123*1j, -.6987821445005273020051878+.7204696509726630531663123*1j, -.6020482668090644386627299-.8602708961893664447167418*1j, -.6020482668090644386627299+.8602708961893664447167418*1j, -.4734268069916151511140032-1.008234300314801077034158*1j, -.4734268069916151511140032+1.008234300314801077034158*1j, -.2897592029880489845789953-1.174183010600059128532230*1j, -.2897592029880489845789953+1.174183010600059128532230*1j] elif N == 19: p = [-.9078934217899404528985092, -.9021937639390660668922536-.1219568381872026517578164*1j, -.9021937639390660668922536+.1219568381872026517578164*1j, -.8849290585034385274001112-.2442590757549818229026280*1j, -.8849290585034385274001112+.2442590757549818229026280*1j, -.8555768765618421591093993-.3672925896399872304734923*1j, -.8555768765618421591093993+.3672925896399872304734923*1j, -.8131725551578197705476160-.4915365035562459055630005*1j, -.8131725551578197705476160+.4915365035562459055630005*1j, -.7561260971541629355231897-.6176483917970178919174173*1j, -.7561260971541629355231897+.6176483917970178919174173*1j, -.6818424412912442033411634-.7466272357947761283262338*1j, -.6818424412912442033411634+.7466272357947761283262338*1j, -.5858613321217832644813602-.8801817131014566284786759*1j, -.5858613321217832644813602+.8801817131014566284786759*1j, -.4595043449730988600785456-1.021768776912671221830298*1j, -.4595043449730988600785456+1.021768776912671221830298*1j, -.2804866851439370027628724-1.180931628453291873626003*1j, -.2804866851439370027628724+1.180931628453291873626003*1j] elif N == 20: p = [-.9062570115576771146523497-57961780277849516990208850.0E-27*1j, -.9062570115576771146523497+57961780277849516990208850.0E-27*1j, -.8959150941925768608568248-.1740317175918705058595844*1j, -.8959150941925768608568248+.1740317175918705058595844*1j, -.8749560316673332850673214-.2905559296567908031706902*1j, -.8749560316673332850673214+.2905559296567908031706902*1j, -.8427907479956670633544106-.4078917326291934082132821*1j, -.8427907479956670633544106+.4078917326291934082132821*1j, -.7984251191290606875799876-.5264942388817132427317659*1j, -.7984251191290606875799876+.5264942388817132427317659*1j, -.7402780309646768991232610-.6469975237605228320268752*1j, -.7402780309646768991232610+.6469975237605228320268752*1j, -.6658120544829934193890626-.7703721701100763015154510*1j, -.6658120544829934193890626+.7703721701100763015154510*1j, -.5707026806915714094398061-.8982829066468255593407161*1j, -.5707026806915714094398061+.8982829066468255593407161*1j, -.4465700698205149555701841-1.034097702560842962315411*1j, -.4465700698205149555701841+1.034097702560842962315411*1j, -.2719299580251652601727704-1.187099379810885886139638*1j, -.2719299580251652601727704+1.187099379810885886139638*1j] elif N == 21: p = [-.9072262653142957028884077, -.9025428073192696303995083-.1105252572789856480992275*1j, -.9025428073192696303995083+.1105252572789856480992275*1j, -.8883808106664449854431605-.2213069215084350419975358*1j, -.8883808106664449854431605+.2213069215084350419975358*1j, -.8643915813643204553970169-.3326258512522187083009453*1j, -.8643915813643204553970169+.3326258512522187083009453*1j, -.8299435470674444100273463-.4448177739407956609694059*1j, -.8299435470674444100273463+.4448177739407956609694059*1j, -.7840287980408341576100581-.5583186348022854707564856*1j, -.7840287980408341576100581+.5583186348022854707564856*1j, -.7250839687106612822281339-.6737426063024382240549898*1j, -.7250839687106612822281339+.6737426063024382240549898*1j, -.6506315378609463397807996-.7920349342629491368548074*1j, -.6506315378609463397807996+.7920349342629491368548074*1j, -.5564766488918562465935297-.9148198405846724121600860*1j, -.5564766488918562465935297+.9148198405846724121600860*1j, -.4345168906815271799687308-1.045382255856986531461592*1j, -.4345168906815271799687308+1.045382255856986531461592*1j, -.2640041595834031147954813-1.192762031948052470183960*1j, -.2640041595834031147954813+1.192762031948052470183960*1j] elif N == 22: p = [-.9058702269930872551848625-52774908289999045189007100.0E-27*1j, -.9058702269930872551848625+52774908289999045189007100.0E-27*1j, -.8972983138153530955952835-.1584351912289865608659759*1j, -.8972983138153530955952835+.1584351912289865608659759*1j, -.8799661455640176154025352-.2644363039201535049656450*1j, -.8799661455640176154025352+.2644363039201535049656450*1j, -.8534754036851687233084587-.3710389319482319823405321*1j, -.8534754036851687233084587+.3710389319482319823405321*1j, -.8171682088462720394344996-.4785619492202780899653575*1j, -.8171682088462720394344996+.4785619492202780899653575*1j, -.7700332930556816872932937-.5874255426351153211965601*1j, -.7700332930556816872932937+.5874255426351153211965601*1j, -.7105305456418785989070935-.6982266265924524000098548*1j, -.7105305456418785989070935+.6982266265924524000098548*1j, -.6362427683267827226840153-.8118875040246347267248508*1j, -.6362427683267827226840153+.8118875040246347267248508*1j, -.5430983056306302779658129-.9299947824439872998916657*1j, -.5430983056306302779658129+.9299947824439872998916657*1j, -.4232528745642628461715044-1.055755605227545931204656*1j, -.4232528745642628461715044+1.055755605227545931204656*1j, -.2566376987939318038016012-1.197982433555213008346532*1j, -.2566376987939318038016012+1.197982433555213008346532*1j] elif N == 23: p = [-.9066732476324988168207439, -.9027564979912504609412993-.1010534335314045013252480*1j, -.9027564979912504609412993+.1010534335314045013252480*1j, -.8909283242471251458653994-.2023024699381223418195228*1j, -.8909283242471251458653994+.2023024699381223418195228*1j, -.8709469395587416239596874-.3039581993950041588888925*1j, -.8709469395587416239596874+.3039581993950041588888925*1j, -.8423805948021127057054288-.4062657948237602726779246*1j, -.8423805948021127057054288+.4062657948237602726779246*1j, -.8045561642053176205623187-.5095305912227258268309528*1j, -.8045561642053176205623187+.5095305912227258268309528*1j, -.7564660146829880581478138-.6141594859476032127216463*1j, -.7564660146829880581478138+.6141594859476032127216463*1j, -.6965966033912705387505040-.7207341374753046970247055*1j, -.6965966033912705387505040+.7207341374753046970247055*1j, -.6225903228771341778273152-.8301558302812980678845563*1j, -.6225903228771341778273152+.8301558302812980678845563*1j, -.5304922463810191698502226-.9439760364018300083750242*1j, -.5304922463810191698502226+.9439760364018300083750242*1j, -.4126986617510148836149955-1.065328794475513585531053*1j, -.4126986617510148836149955+1.065328794475513585531053*1j, -.2497697202208956030229911-1.202813187870697831365338*1j, -.2497697202208956030229911+1.202813187870697831365338*1j] elif N == 24: p = [-.9055312363372773709269407-48440066540478700874836350.0E-27*1j, -.9055312363372773709269407+48440066540478700874836350.0E-27*1j, -.8983105104397872954053307-.1454056133873610120105857*1j, -.8983105104397872954053307+.1454056133873610120105857*1j, -.8837358034555706623131950-.2426335234401383076544239*1j, -.8837358034555706623131950+.2426335234401383076544239*1j, -.8615278304016353651120610-.3403202112618624773397257*1j, -.8615278304016353651120610+.3403202112618624773397257*1j, -.8312326466813240652679563-.4386985933597305434577492*1j, -.8312326466813240652679563+.4386985933597305434577492*1j, -.7921695462343492518845446-.5380628490968016700338001*1j, -.7921695462343492518845446+.5380628490968016700338001*1j, -.7433392285088529449175873-.6388084216222567930378296*1j, -.7433392285088529449175873+.6388084216222567930378296*1j, -.6832565803536521302816011-.7415032695091650806797753*1j, -.6832565803536521302816011+.7415032695091650806797753*1j, -.6096221567378335562589532-.8470292433077202380020454*1j, -.6096221567378335562589532+.8470292433077202380020454*1j, -.5185914574820317343536707-.9569048385259054576937721*1j, -.5185914574820317343536707+.9569048385259054576937721*1j, -.4027853855197518014786978-1.074195196518674765143729*1j, -.4027853855197518014786978+1.074195196518674765143729*1j, -.2433481337524869675825448-1.207298683731972524975429*1j, -.2433481337524869675825448+1.207298683731972524975429*1j] elif N == 25: p = [-.9062073871811708652496104, -.9028833390228020537142561-93077131185102967450643820.0E-27*1j, -.9028833390228020537142561+93077131185102967450643820.0E-27*1j, -.8928551459883548836774529-.1863068969804300712287138*1j, -.8928551459883548836774529+.1863068969804300712287138*1j, -.8759497989677857803656239-.2798521321771408719327250*1j, -.8759497989677857803656239+.2798521321771408719327250*1j, -.8518616886554019782346493-.3738977875907595009446142*1j, -.8518616886554019782346493+.3738977875907595009446142*1j, -.8201226043936880253962552-.4686668574656966589020580*1j, -.8201226043936880253962552+.4686668574656966589020580*1j, -.7800496278186497225905443-.5644441210349710332887354*1j, -.7800496278186497225905443+.5644441210349710332887354*1j, -.7306549271849967721596735-.6616149647357748681460822*1j, -.7306549271849967721596735+.6616149647357748681460822*1j, -.6704827128029559528610523-.7607348858167839877987008*1j, -.6704827128029559528610523+.7607348858167839877987008*1j, -.5972898661335557242320528-.8626676330388028512598538*1j, -.5972898661335557242320528+.8626676330388028512598538*1j, -.5073362861078468845461362-.9689006305344868494672405*1j, -.5073362861078468845461362+.9689006305344868494672405*1j, -.3934529878191079606023847-1.082433927173831581956863*1j, -.3934529878191079606023847+1.082433927173831581956863*1j, -.2373280669322028974199184-1.211476658382565356579418*1j, -.2373280669322028974199184+1.211476658382565356579418*1j] else: raise ValueError, "Bessel Filter not supported for order %d" % N return z, p, k
p = [-.9067004324162775554189031-64279241063930693839360680.0E-27*1j, -.9067004324162775554189031+64279241063930693839360680.0E-27*1j,
p = [-.9067004324162775554189031-64279241063930693839360680.0e-27*1j, -.9067004324162775554189031+64279241063930693839360680.0e-27*1j,
def besselap(N): """Return (z,p,k) zero, pole, gain for analog prototype of an Nth order Bessel filter.""" z = [] k = 1 if N == 0: p = []; elif N == 1: p = [-1] elif N == 2: p = [-.8660254037844386467637229+.4999999999999999999999996*1j, -.8660254037844386467637229-.4999999999999999999999996*1j] elif N == 3: p = [-.9416000265332067855971980, -.7456403858480766441810907-.7113666249728352680992154*1j, -.7456403858480766441810907+.7113666249728352680992154*1j] elif N == 4: p = [-.6572111716718829545787781-.8301614350048733772399715*1j, -.6572111716718829545787788+.8301614350048733772399715*1j, -.9047587967882449459642637-.2709187330038746636700923*1j, -.9047587967882449459642624+.2709187330038746636700926*1j] elif N == 5: p = [-.9264420773877602247196260, -.8515536193688395541722677-.4427174639443327209850002*1j, -.8515536193688395541722677+.4427174639443327209850002*1j, -.5905759446119191779319432-.9072067564574549539291747*1j, -.5905759446119191779319432+.9072067564574549539291747*1j] elif N == 6: p = [-.9093906830472271808050953-.1856964396793046769246397*1j, -.9093906830472271808050953+.1856964396793046769246397*1j, -.7996541858328288520243325-.5621717346937317988594118*1j, -.7996541858328288520243325+.5621717346937317988594118*1j, -.5385526816693109683073792-.9616876881954277199245657*1j, -.5385526816693109683073792+.9616876881954277199245657*1j] elif N == 7: p = [-.9194871556490290014311619, -.8800029341523374639772340-.3216652762307739398381830*1j, -.8800029341523374639772340+.3216652762307739398381830*1j, -.7527355434093214462291616-.6504696305522550699212995*1j, -.7527355434093214462291616+.6504696305522550699212995*1j, -.4966917256672316755024763-1.002508508454420401230220*1j, -.4966917256672316755024763+1.002508508454420401230220*1j] elif N == 8: p = [-.9096831546652910216327629-.1412437976671422927888150*1j, -.9096831546652910216327629+.1412437976671422927888150*1j, -.8473250802359334320103023-.4259017538272934994996429*1j, -.8473250802359334320103023+.4259017538272934994996429*1j, -.7111381808485399250796172-.7186517314108401705762571*1j, -.7111381808485399250796172+.7186517314108401705762571*1j, -.4621740412532122027072175-1.034388681126901058116589*1j, -.4621740412532122027072175+1.034388681126901058116589*1j] elif N == 9: p = [-.9154957797499037686769223, -.8911217017079759323183848-.2526580934582164192308115*1j, -.8911217017079759323183848+.2526580934582164192308115*1j, -.8148021112269012975514135-.5085815689631499483745341*1j, -.8148021112269012975514135+.5085815689631499483745341*1j, -.6743622686854761980403401-.7730546212691183706919682*1j, -.6743622686854761980403401+.7730546212691183706919682*1j, -.4331415561553618854685942-1.060073670135929666774323*1j, -.4331415561553618854685942+1.060073670135929666774323*1j] elif N == 10: p = [-.9091347320900502436826431-.1139583137335511169927714*1j, -.9091347320900502436826431+.1139583137335511169927714*1j, -.8688459641284764527921864-.3430008233766309973110589*1j, -.8688459641284764527921864+.3430008233766309973110589*1j, -.7837694413101441082655890-.5759147538499947070009852*1j, -.7837694413101441082655890+.5759147538499947070009852*1j, -.6417513866988316136190854-.8175836167191017226233947*1j, -.6417513866988316136190854+.8175836167191017226233947*1j, -.4083220732868861566219785-1.081274842819124562037210*1j, -.4083220732868861566219785+1.081274842819124562037210*1j] elif N == 11: p = [-.9129067244518981934637318, -.8963656705721166099815744-.2080480375071031919692341*1j -.8963656705721166099815744+.2080480375071031919692341*1j, -.8453044014712962954184557-.4178696917801248292797448*1j, -.8453044014712962954184557+.4178696917801248292797448*1j, -.7546938934722303128102142-.6319150050721846494520941*1j, -.7546938934722303128102142+.6319150050721846494520941*1j, -.6126871554915194054182909-.8547813893314764631518509*1j, -.6126871554915194054182909+.8547813893314764631518509*1j, -.3868149510055090879155425-1.099117466763120928733632*1j, -.3868149510055090879155425+1.099117466763120928733632*1j] elif N == 12: p = [-.9084478234140682638817772-95506365213450398415258360.0e-27*1j, -.9084478234140682638817772+95506365213450398415258360.0e-27*1j, -.8802534342016826507901575-.2871779503524226723615457*1j, -.8802534342016826507901575+.2871779503524226723615457*1j, -.8217296939939077285792834-.4810212115100676440620548*1j, -.8217296939939077285792834+.4810212115100676440620548*1j, -.7276681615395159454547013-.6792961178764694160048987*1j, -.7276681615395159454547013+.6792961178764694160048987*1j, -.5866369321861477207528215-.8863772751320727026622149*1j, -.5866369321861477207528215+.8863772751320727026622149*1j, -.3679640085526312839425808-1.114373575641546257595657*1j, -.3679640085526312839425808+1.114373575641546257595657*1j] elif N == 13: p = [-.9110914665984182781070663, -.8991314665475196220910718-.1768342956161043620980863*1j, -.8991314665475196220910718+.1768342956161043620980863*1j, -.8625094198260548711573628-.3547413731172988997754038*1j, -.8625094198260548711573628+.3547413731172988997754038*1j, -.7987460692470972510394686-.5350752120696801938272504*1j, -.7987460692470972510394686+.5350752120696801938272504*1j, -.7026234675721275653944062-.7199611890171304131266374*1j, -.7026234675721275653944062+.7199611890171304131266374*1j, -.5631559842430199266325818-.9135900338325109684927731*1j, -.5631559842430199266325818+.9135900338325109684927731*1j, -.3512792323389821669401925-1.127591548317705678613239*1j, -.3512792323389821669401925+1.127591548317705678613239*1j] elif N == 14: p = [-.9077932138396487614720659-82196399419401501888968130.0E-27*1j, -.9077932138396487614720659+82196399419401501888968130.0E-27*1j, -.8869506674916445312089167-.2470079178765333183201435*1j, -.8869506674916445312089167+.2470079178765333183201435*1j, -.8441199160909851197897667-.4131653825102692595237260*1j, -.8441199160909851197897667+.4131653825102692595237260*1j, -.7766591387063623897344648-.5819170677377608590492434*1j, -.7766591387063623897344648+.5819170677377608590492434*1j, -.6794256425119233117869491-.7552857305042033418417492*1j, -.6794256425119233117869491+.7552857305042033418417492*1j, -.5418766775112297376541293-.9373043683516919569183099*1j, -.5418766775112297376541293+.9373043683516919569183099*1j, -.3363868224902037330610040-1.139172297839859991370924*1j, -.3363868224902037330610040+1.139172297839859991370924*1j] elif N == 15: p = [-.9097482363849064167228581, -.9006981694176978324932918-.1537681197278439351298882*1j, -.9006981694176978324932918+.1537681197278439351298882*1j, -.8731264620834984978337843-.3082352470564267657715883*1j, -.8731264620834984978337843+.3082352470564267657715883*1j, -.8256631452587146506294553-.4642348752734325631275134*1j, -.8256631452587146506294553+.4642348752734325631275134*1j, -.7556027168970728127850416-.6229396358758267198938604*1j, -.7556027168970728127850416+.6229396358758267198938604*1j, -.6579196593110998676999362-.7862895503722515897065645*1j, -.6579196593110998676999362+.7862895503722515897065645*1j, -.5224954069658330616875186-.9581787261092526478889345*1j, -.5224954069658330616875186+.9581787261092526478889345*1j, -.3229963059766444287113517-1.149416154583629539665297*1j, -.3229963059766444287113517+1.149416154583629539665297*1j] elif N == 16: p = [-.9072099595087001356491337-72142113041117326028823950.0E-27*1j, -.9072099595087001356491337+72142113041117326028823950.0E-27*1j, -.8911723070323647674780132-.2167089659900576449410059*1j, -.8911723070323647674780132+.2167089659900576449410059*1j, -.8584264231521330481755780-.3621697271802065647661080*1j, -.8584264231521330481755780+.3621697271802065647661080*1j, -.8074790293236003885306146-.5092933751171800179676218*1j, -.8074790293236003885306146+.5092933751171800179676218*1j, -.7356166304713115980927279-.6591950877860393745845254*1j, -.7356166304713115980927279+.6591950877860393745845254*1j, -.6379502514039066715773828-.8137453537108761895522580*1j, -.6379502514039066715773828+.8137453537108761895522580*1j, -.5047606444424766743309967-.9767137477799090692947061*1j, -.5047606444424766743309967+.9767137477799090692947061*1j, -.3108782755645387813283867-1.158552841199330479412225*1j, -.3108782755645387813283867+1.158552841199330479412225*1j] elif N == 17: p = [-.9087141161336397432860029, -.9016273850787285964692844-.1360267995173024591237303*1j, -.9016273850787285964692844+.1360267995173024591237303*1j, -.8801100704438627158492165-.2725347156478803885651973*1j, -.8801100704438627158492165+.2725347156478803885651973*1j, -.8433414495836129204455491-.4100759282910021624185986*1j, -.8433414495836129204455491+.4100759282910021624185986*1j, -.7897644147799708220288138-.5493724405281088674296232*1j, -.7897644147799708220288138+.5493724405281088674296232*1j, -.7166893842372349049842743-.6914936286393609433305754*1j, -.7166893842372349049842743+.6914936286393609433305754*1j, -.6193710717342144521602448-.8382497252826992979368621*1j, -.6193710717342144521602448+.8382497252826992979368621*1j, -.4884629337672704194973683-.9932971956316781632345466*1j, -.4884629337672704194973683+.9932971956316781632345466*1j, -.2998489459990082015466971-1.166761272925668786676672*1j, -.2998489459990082015466971+1.166761272925668786676672*1j] elif N == 18: p = [-.9067004324162775554189031-64279241063930693839360680.0E-27*1j, -.9067004324162775554189031+64279241063930693839360680.0E-27*1j, -.8939764278132455733032155-.1930374640894758606940586*1j, -.8939764278132455733032155+.1930374640894758606940586*1j, -.8681095503628830078317207-.3224204925163257604931634*1j, -.8681095503628830078317207+.3224204925163257604931634*1j, -.8281885016242836608829018-.4529385697815916950149364*1j, -.8281885016242836608829018+.4529385697815916950149364*1j, -.7726285030739558780127746-.5852778162086640620016316*1j, -.7726285030739558780127746+.5852778162086640620016316*1j, -.6987821445005273020051878-.7204696509726630531663123*1j, -.6987821445005273020051878+.7204696509726630531663123*1j, -.6020482668090644386627299-.8602708961893664447167418*1j, -.6020482668090644386627299+.8602708961893664447167418*1j, -.4734268069916151511140032-1.008234300314801077034158*1j, -.4734268069916151511140032+1.008234300314801077034158*1j, -.2897592029880489845789953-1.174183010600059128532230*1j, -.2897592029880489845789953+1.174183010600059128532230*1j] elif N == 19: p = [-.9078934217899404528985092, -.9021937639390660668922536-.1219568381872026517578164*1j, -.9021937639390660668922536+.1219568381872026517578164*1j, -.8849290585034385274001112-.2442590757549818229026280*1j, -.8849290585034385274001112+.2442590757549818229026280*1j, -.8555768765618421591093993-.3672925896399872304734923*1j, -.8555768765618421591093993+.3672925896399872304734923*1j, -.8131725551578197705476160-.4915365035562459055630005*1j, -.8131725551578197705476160+.4915365035562459055630005*1j, -.7561260971541629355231897-.6176483917970178919174173*1j, -.7561260971541629355231897+.6176483917970178919174173*1j, -.6818424412912442033411634-.7466272357947761283262338*1j, -.6818424412912442033411634+.7466272357947761283262338*1j, -.5858613321217832644813602-.8801817131014566284786759*1j, -.5858613321217832644813602+.8801817131014566284786759*1j, -.4595043449730988600785456-1.021768776912671221830298*1j, -.4595043449730988600785456+1.021768776912671221830298*1j, -.2804866851439370027628724-1.180931628453291873626003*1j, -.2804866851439370027628724+1.180931628453291873626003*1j] elif N == 20: p = [-.9062570115576771146523497-57961780277849516990208850.0E-27*1j, -.9062570115576771146523497+57961780277849516990208850.0E-27*1j, -.8959150941925768608568248-.1740317175918705058595844*1j, -.8959150941925768608568248+.1740317175918705058595844*1j, -.8749560316673332850673214-.2905559296567908031706902*1j, -.8749560316673332850673214+.2905559296567908031706902*1j, -.8427907479956670633544106-.4078917326291934082132821*1j, -.8427907479956670633544106+.4078917326291934082132821*1j, -.7984251191290606875799876-.5264942388817132427317659*1j, -.7984251191290606875799876+.5264942388817132427317659*1j, -.7402780309646768991232610-.6469975237605228320268752*1j, -.7402780309646768991232610+.6469975237605228320268752*1j, -.6658120544829934193890626-.7703721701100763015154510*1j, -.6658120544829934193890626+.7703721701100763015154510*1j, -.5707026806915714094398061-.8982829066468255593407161*1j, -.5707026806915714094398061+.8982829066468255593407161*1j, -.4465700698205149555701841-1.034097702560842962315411*1j, -.4465700698205149555701841+1.034097702560842962315411*1j, -.2719299580251652601727704-1.187099379810885886139638*1j, -.2719299580251652601727704+1.187099379810885886139638*1j] elif N == 21: p = [-.9072262653142957028884077, -.9025428073192696303995083-.1105252572789856480992275*1j, -.9025428073192696303995083+.1105252572789856480992275*1j, -.8883808106664449854431605-.2213069215084350419975358*1j, -.8883808106664449854431605+.2213069215084350419975358*1j, -.8643915813643204553970169-.3326258512522187083009453*1j, -.8643915813643204553970169+.3326258512522187083009453*1j, -.8299435470674444100273463-.4448177739407956609694059*1j, -.8299435470674444100273463+.4448177739407956609694059*1j, -.7840287980408341576100581-.5583186348022854707564856*1j, -.7840287980408341576100581+.5583186348022854707564856*1j, -.7250839687106612822281339-.6737426063024382240549898*1j, -.7250839687106612822281339+.6737426063024382240549898*1j, -.6506315378609463397807996-.7920349342629491368548074*1j, -.6506315378609463397807996+.7920349342629491368548074*1j, -.5564766488918562465935297-.9148198405846724121600860*1j, -.5564766488918562465935297+.9148198405846724121600860*1j, -.4345168906815271799687308-1.045382255856986531461592*1j, -.4345168906815271799687308+1.045382255856986531461592*1j, -.2640041595834031147954813-1.192762031948052470183960*1j, -.2640041595834031147954813+1.192762031948052470183960*1j] elif N == 22: p = [-.9058702269930872551848625-52774908289999045189007100.0E-27*1j, -.9058702269930872551848625+52774908289999045189007100.0E-27*1j, -.8972983138153530955952835-.1584351912289865608659759*1j, -.8972983138153530955952835+.1584351912289865608659759*1j, -.8799661455640176154025352-.2644363039201535049656450*1j, -.8799661455640176154025352+.2644363039201535049656450*1j, -.8534754036851687233084587-.3710389319482319823405321*1j, -.8534754036851687233084587+.3710389319482319823405321*1j, -.8171682088462720394344996-.4785619492202780899653575*1j, -.8171682088462720394344996+.4785619492202780899653575*1j, -.7700332930556816872932937-.5874255426351153211965601*1j, -.7700332930556816872932937+.5874255426351153211965601*1j, -.7105305456418785989070935-.6982266265924524000098548*1j, -.7105305456418785989070935+.6982266265924524000098548*1j, -.6362427683267827226840153-.8118875040246347267248508*1j, -.6362427683267827226840153+.8118875040246347267248508*1j, -.5430983056306302779658129-.9299947824439872998916657*1j, -.5430983056306302779658129+.9299947824439872998916657*1j, -.4232528745642628461715044-1.055755605227545931204656*1j, -.4232528745642628461715044+1.055755605227545931204656*1j, -.2566376987939318038016012-1.197982433555213008346532*1j, -.2566376987939318038016012+1.197982433555213008346532*1j] elif N == 23: p = [-.9066732476324988168207439, -.9027564979912504609412993-.1010534335314045013252480*1j, -.9027564979912504609412993+.1010534335314045013252480*1j, -.8909283242471251458653994-.2023024699381223418195228*1j, -.8909283242471251458653994+.2023024699381223418195228*1j, -.8709469395587416239596874-.3039581993950041588888925*1j, -.8709469395587416239596874+.3039581993950041588888925*1j, -.8423805948021127057054288-.4062657948237602726779246*1j, -.8423805948021127057054288+.4062657948237602726779246*1j, -.8045561642053176205623187-.5095305912227258268309528*1j, -.8045561642053176205623187+.5095305912227258268309528*1j, -.7564660146829880581478138-.6141594859476032127216463*1j, -.7564660146829880581478138+.6141594859476032127216463*1j, -.6965966033912705387505040-.7207341374753046970247055*1j, -.6965966033912705387505040+.7207341374753046970247055*1j, -.6225903228771341778273152-.8301558302812980678845563*1j, -.6225903228771341778273152+.8301558302812980678845563*1j, -.5304922463810191698502226-.9439760364018300083750242*1j, -.5304922463810191698502226+.9439760364018300083750242*1j, -.4126986617510148836149955-1.065328794475513585531053*1j, -.4126986617510148836149955+1.065328794475513585531053*1j, -.2497697202208956030229911-1.202813187870697831365338*1j, -.2497697202208956030229911+1.202813187870697831365338*1j] elif N == 24: p = [-.9055312363372773709269407-48440066540478700874836350.0E-27*1j, -.9055312363372773709269407+48440066540478700874836350.0E-27*1j, -.8983105104397872954053307-.1454056133873610120105857*1j, -.8983105104397872954053307+.1454056133873610120105857*1j, -.8837358034555706623131950-.2426335234401383076544239*1j, -.8837358034555706623131950+.2426335234401383076544239*1j, -.8615278304016353651120610-.3403202112618624773397257*1j, -.8615278304016353651120610+.3403202112618624773397257*1j, -.8312326466813240652679563-.4386985933597305434577492*1j, -.8312326466813240652679563+.4386985933597305434577492*1j, -.7921695462343492518845446-.5380628490968016700338001*1j, -.7921695462343492518845446+.5380628490968016700338001*1j, -.7433392285088529449175873-.6388084216222567930378296*1j, -.7433392285088529449175873+.6388084216222567930378296*1j, -.6832565803536521302816011-.7415032695091650806797753*1j, -.6832565803536521302816011+.7415032695091650806797753*1j, -.6096221567378335562589532-.8470292433077202380020454*1j, -.6096221567378335562589532+.8470292433077202380020454*1j, -.5185914574820317343536707-.9569048385259054576937721*1j, -.5185914574820317343536707+.9569048385259054576937721*1j, -.4027853855197518014786978-1.074195196518674765143729*1j, -.4027853855197518014786978+1.074195196518674765143729*1j, -.2433481337524869675825448-1.207298683731972524975429*1j, -.2433481337524869675825448+1.207298683731972524975429*1j] elif N == 25: p = [-.9062073871811708652496104, -.9028833390228020537142561-93077131185102967450643820.0E-27*1j, -.9028833390228020537142561+93077131185102967450643820.0E-27*1j, -.8928551459883548836774529-.1863068969804300712287138*1j, -.8928551459883548836774529+.1863068969804300712287138*1j, -.8759497989677857803656239-.2798521321771408719327250*1j, -.8759497989677857803656239+.2798521321771408719327250*1j, -.8518616886554019782346493-.3738977875907595009446142*1j, -.8518616886554019782346493+.3738977875907595009446142*1j, -.8201226043936880253962552-.4686668574656966589020580*1j, -.8201226043936880253962552+.4686668574656966589020580*1j, -.7800496278186497225905443-.5644441210349710332887354*1j, -.7800496278186497225905443+.5644441210349710332887354*1j, -.7306549271849967721596735-.6616149647357748681460822*1j, -.7306549271849967721596735+.6616149647357748681460822*1j, -.6704827128029559528610523-.7607348858167839877987008*1j, -.6704827128029559528610523+.7607348858167839877987008*1j, -.5972898661335557242320528-.8626676330388028512598538*1j, -.5972898661335557242320528+.8626676330388028512598538*1j, -.5073362861078468845461362-.9689006305344868494672405*1j, -.5073362861078468845461362+.9689006305344868494672405*1j, -.3934529878191079606023847-1.082433927173831581956863*1j, -.3934529878191079606023847+1.082433927173831581956863*1j, -.2373280669322028974199184-1.211476658382565356579418*1j, -.2373280669322028974199184+1.211476658382565356579418*1j] else: raise ValueError, "Bessel Filter not supported for order %d" % N return z, p, k
p = [-.9062570115576771146523497-57961780277849516990208850.0E-27*1j, -.9062570115576771146523497+57961780277849516990208850.0E-27*1j,
p = [-.9062570115576771146523497-57961780277849516990208850.0e-27*1j, -.9062570115576771146523497+57961780277849516990208850.0e-27*1j,
def besselap(N): """Return (z,p,k) zero, pole, gain for analog prototype of an Nth order Bessel filter.""" z = [] k = 1 if N == 0: p = []; elif N == 1: p = [-1] elif N == 2: p = [-.8660254037844386467637229+.4999999999999999999999996*1j, -.8660254037844386467637229-.4999999999999999999999996*1j] elif N == 3: p = [-.9416000265332067855971980, -.7456403858480766441810907-.7113666249728352680992154*1j, -.7456403858480766441810907+.7113666249728352680992154*1j] elif N == 4: p = [-.6572111716718829545787781-.8301614350048733772399715*1j, -.6572111716718829545787788+.8301614350048733772399715*1j, -.9047587967882449459642637-.2709187330038746636700923*1j, -.9047587967882449459642624+.2709187330038746636700926*1j] elif N == 5: p = [-.9264420773877602247196260, -.8515536193688395541722677-.4427174639443327209850002*1j, -.8515536193688395541722677+.4427174639443327209850002*1j, -.5905759446119191779319432-.9072067564574549539291747*1j, -.5905759446119191779319432+.9072067564574549539291747*1j] elif N == 6: p = [-.9093906830472271808050953-.1856964396793046769246397*1j, -.9093906830472271808050953+.1856964396793046769246397*1j, -.7996541858328288520243325-.5621717346937317988594118*1j, -.7996541858328288520243325+.5621717346937317988594118*1j, -.5385526816693109683073792-.9616876881954277199245657*1j, -.5385526816693109683073792+.9616876881954277199245657*1j] elif N == 7: p = [-.9194871556490290014311619, -.8800029341523374639772340-.3216652762307739398381830*1j, -.8800029341523374639772340+.3216652762307739398381830*1j, -.7527355434093214462291616-.6504696305522550699212995*1j, -.7527355434093214462291616+.6504696305522550699212995*1j, -.4966917256672316755024763-1.002508508454420401230220*1j, -.4966917256672316755024763+1.002508508454420401230220*1j] elif N == 8: p = [-.9096831546652910216327629-.1412437976671422927888150*1j, -.9096831546652910216327629+.1412437976671422927888150*1j, -.8473250802359334320103023-.4259017538272934994996429*1j, -.8473250802359334320103023+.4259017538272934994996429*1j, -.7111381808485399250796172-.7186517314108401705762571*1j, -.7111381808485399250796172+.7186517314108401705762571*1j, -.4621740412532122027072175-1.034388681126901058116589*1j, -.4621740412532122027072175+1.034388681126901058116589*1j] elif N == 9: p = [-.9154957797499037686769223, -.8911217017079759323183848-.2526580934582164192308115*1j, -.8911217017079759323183848+.2526580934582164192308115*1j, -.8148021112269012975514135-.5085815689631499483745341*1j, -.8148021112269012975514135+.5085815689631499483745341*1j, -.6743622686854761980403401-.7730546212691183706919682*1j, -.6743622686854761980403401+.7730546212691183706919682*1j, -.4331415561553618854685942-1.060073670135929666774323*1j, -.4331415561553618854685942+1.060073670135929666774323*1j] elif N == 10: p = [-.9091347320900502436826431-.1139583137335511169927714*1j, -.9091347320900502436826431+.1139583137335511169927714*1j, -.8688459641284764527921864-.3430008233766309973110589*1j, -.8688459641284764527921864+.3430008233766309973110589*1j, -.7837694413101441082655890-.5759147538499947070009852*1j, -.7837694413101441082655890+.5759147538499947070009852*1j, -.6417513866988316136190854-.8175836167191017226233947*1j, -.6417513866988316136190854+.8175836167191017226233947*1j, -.4083220732868861566219785-1.081274842819124562037210*1j, -.4083220732868861566219785+1.081274842819124562037210*1j] elif N == 11: p = [-.9129067244518981934637318, -.8963656705721166099815744-.2080480375071031919692341*1j -.8963656705721166099815744+.2080480375071031919692341*1j, -.8453044014712962954184557-.4178696917801248292797448*1j, -.8453044014712962954184557+.4178696917801248292797448*1j, -.7546938934722303128102142-.6319150050721846494520941*1j, -.7546938934722303128102142+.6319150050721846494520941*1j, -.6126871554915194054182909-.8547813893314764631518509*1j, -.6126871554915194054182909+.8547813893314764631518509*1j, -.3868149510055090879155425-1.099117466763120928733632*1j, -.3868149510055090879155425+1.099117466763120928733632*1j] elif N == 12: p = [-.9084478234140682638817772-95506365213450398415258360.0e-27*1j, -.9084478234140682638817772+95506365213450398415258360.0e-27*1j, -.8802534342016826507901575-.2871779503524226723615457*1j, -.8802534342016826507901575+.2871779503524226723615457*1j, -.8217296939939077285792834-.4810212115100676440620548*1j, -.8217296939939077285792834+.4810212115100676440620548*1j, -.7276681615395159454547013-.6792961178764694160048987*1j, -.7276681615395159454547013+.6792961178764694160048987*1j, -.5866369321861477207528215-.8863772751320727026622149*1j, -.5866369321861477207528215+.8863772751320727026622149*1j, -.3679640085526312839425808-1.114373575641546257595657*1j, -.3679640085526312839425808+1.114373575641546257595657*1j] elif N == 13: p = [-.9110914665984182781070663, -.8991314665475196220910718-.1768342956161043620980863*1j, -.8991314665475196220910718+.1768342956161043620980863*1j, -.8625094198260548711573628-.3547413731172988997754038*1j, -.8625094198260548711573628+.3547413731172988997754038*1j, -.7987460692470972510394686-.5350752120696801938272504*1j, -.7987460692470972510394686+.5350752120696801938272504*1j, -.7026234675721275653944062-.7199611890171304131266374*1j, -.7026234675721275653944062+.7199611890171304131266374*1j, -.5631559842430199266325818-.9135900338325109684927731*1j, -.5631559842430199266325818+.9135900338325109684927731*1j, -.3512792323389821669401925-1.127591548317705678613239*1j, -.3512792323389821669401925+1.127591548317705678613239*1j] elif N == 14: p = [-.9077932138396487614720659-82196399419401501888968130.0E-27*1j, -.9077932138396487614720659+82196399419401501888968130.0E-27*1j, -.8869506674916445312089167-.2470079178765333183201435*1j, -.8869506674916445312089167+.2470079178765333183201435*1j, -.8441199160909851197897667-.4131653825102692595237260*1j, -.8441199160909851197897667+.4131653825102692595237260*1j, -.7766591387063623897344648-.5819170677377608590492434*1j, -.7766591387063623897344648+.5819170677377608590492434*1j, -.6794256425119233117869491-.7552857305042033418417492*1j, -.6794256425119233117869491+.7552857305042033418417492*1j, -.5418766775112297376541293-.9373043683516919569183099*1j, -.5418766775112297376541293+.9373043683516919569183099*1j, -.3363868224902037330610040-1.139172297839859991370924*1j, -.3363868224902037330610040+1.139172297839859991370924*1j] elif N == 15: p = [-.9097482363849064167228581, -.9006981694176978324932918-.1537681197278439351298882*1j, -.9006981694176978324932918+.1537681197278439351298882*1j, -.8731264620834984978337843-.3082352470564267657715883*1j, -.8731264620834984978337843+.3082352470564267657715883*1j, -.8256631452587146506294553-.4642348752734325631275134*1j, -.8256631452587146506294553+.4642348752734325631275134*1j, -.7556027168970728127850416-.6229396358758267198938604*1j, -.7556027168970728127850416+.6229396358758267198938604*1j, -.6579196593110998676999362-.7862895503722515897065645*1j, -.6579196593110998676999362+.7862895503722515897065645*1j, -.5224954069658330616875186-.9581787261092526478889345*1j, -.5224954069658330616875186+.9581787261092526478889345*1j, -.3229963059766444287113517-1.149416154583629539665297*1j, -.3229963059766444287113517+1.149416154583629539665297*1j] elif N == 16: p = [-.9072099595087001356491337-72142113041117326028823950.0E-27*1j, -.9072099595087001356491337+72142113041117326028823950.0E-27*1j, -.8911723070323647674780132-.2167089659900576449410059*1j, -.8911723070323647674780132+.2167089659900576449410059*1j, -.8584264231521330481755780-.3621697271802065647661080*1j, -.8584264231521330481755780+.3621697271802065647661080*1j, -.8074790293236003885306146-.5092933751171800179676218*1j, -.8074790293236003885306146+.5092933751171800179676218*1j, -.7356166304713115980927279-.6591950877860393745845254*1j, -.7356166304713115980927279+.6591950877860393745845254*1j, -.6379502514039066715773828-.8137453537108761895522580*1j, -.6379502514039066715773828+.8137453537108761895522580*1j, -.5047606444424766743309967-.9767137477799090692947061*1j, -.5047606444424766743309967+.9767137477799090692947061*1j, -.3108782755645387813283867-1.158552841199330479412225*1j, -.3108782755645387813283867+1.158552841199330479412225*1j] elif N == 17: p = [-.9087141161336397432860029, -.9016273850787285964692844-.1360267995173024591237303*1j, -.9016273850787285964692844+.1360267995173024591237303*1j, -.8801100704438627158492165-.2725347156478803885651973*1j, -.8801100704438627158492165+.2725347156478803885651973*1j, -.8433414495836129204455491-.4100759282910021624185986*1j, -.8433414495836129204455491+.4100759282910021624185986*1j, -.7897644147799708220288138-.5493724405281088674296232*1j, -.7897644147799708220288138+.5493724405281088674296232*1j, -.7166893842372349049842743-.6914936286393609433305754*1j, -.7166893842372349049842743+.6914936286393609433305754*1j, -.6193710717342144521602448-.8382497252826992979368621*1j, -.6193710717342144521602448+.8382497252826992979368621*1j, -.4884629337672704194973683-.9932971956316781632345466*1j, -.4884629337672704194973683+.9932971956316781632345466*1j, -.2998489459990082015466971-1.166761272925668786676672*1j, -.2998489459990082015466971+1.166761272925668786676672*1j] elif N == 18: p = [-.9067004324162775554189031-64279241063930693839360680.0E-27*1j, -.9067004324162775554189031+64279241063930693839360680.0E-27*1j, -.8939764278132455733032155-.1930374640894758606940586*1j, -.8939764278132455733032155+.1930374640894758606940586*1j, -.8681095503628830078317207-.3224204925163257604931634*1j, -.8681095503628830078317207+.3224204925163257604931634*1j, -.8281885016242836608829018-.4529385697815916950149364*1j, -.8281885016242836608829018+.4529385697815916950149364*1j, -.7726285030739558780127746-.5852778162086640620016316*1j, -.7726285030739558780127746+.5852778162086640620016316*1j, -.6987821445005273020051878-.7204696509726630531663123*1j, -.6987821445005273020051878+.7204696509726630531663123*1j, -.6020482668090644386627299-.8602708961893664447167418*1j, -.6020482668090644386627299+.8602708961893664447167418*1j, -.4734268069916151511140032-1.008234300314801077034158*1j, -.4734268069916151511140032+1.008234300314801077034158*1j, -.2897592029880489845789953-1.174183010600059128532230*1j, -.2897592029880489845789953+1.174183010600059128532230*1j] elif N == 19: p = [-.9078934217899404528985092, -.9021937639390660668922536-.1219568381872026517578164*1j, -.9021937639390660668922536+.1219568381872026517578164*1j, -.8849290585034385274001112-.2442590757549818229026280*1j, -.8849290585034385274001112+.2442590757549818229026280*1j, -.8555768765618421591093993-.3672925896399872304734923*1j, -.8555768765618421591093993+.3672925896399872304734923*1j, -.8131725551578197705476160-.4915365035562459055630005*1j, -.8131725551578197705476160+.4915365035562459055630005*1j, -.7561260971541629355231897-.6176483917970178919174173*1j, -.7561260971541629355231897+.6176483917970178919174173*1j, -.6818424412912442033411634-.7466272357947761283262338*1j, -.6818424412912442033411634+.7466272357947761283262338*1j, -.5858613321217832644813602-.8801817131014566284786759*1j, -.5858613321217832644813602+.8801817131014566284786759*1j, -.4595043449730988600785456-1.021768776912671221830298*1j, -.4595043449730988600785456+1.021768776912671221830298*1j, -.2804866851439370027628724-1.180931628453291873626003*1j, -.2804866851439370027628724+1.180931628453291873626003*1j] elif N == 20: p = [-.9062570115576771146523497-57961780277849516990208850.0E-27*1j, -.9062570115576771146523497+57961780277849516990208850.0E-27*1j, -.8959150941925768608568248-.1740317175918705058595844*1j, -.8959150941925768608568248+.1740317175918705058595844*1j, -.8749560316673332850673214-.2905559296567908031706902*1j, -.8749560316673332850673214+.2905559296567908031706902*1j, -.8427907479956670633544106-.4078917326291934082132821*1j, -.8427907479956670633544106+.4078917326291934082132821*1j, -.7984251191290606875799876-.5264942388817132427317659*1j, -.7984251191290606875799876+.5264942388817132427317659*1j, -.7402780309646768991232610-.6469975237605228320268752*1j, -.7402780309646768991232610+.6469975237605228320268752*1j, -.6658120544829934193890626-.7703721701100763015154510*1j, -.6658120544829934193890626+.7703721701100763015154510*1j, -.5707026806915714094398061-.8982829066468255593407161*1j, -.5707026806915714094398061+.8982829066468255593407161*1j, -.4465700698205149555701841-1.034097702560842962315411*1j, -.4465700698205149555701841+1.034097702560842962315411*1j, -.2719299580251652601727704-1.187099379810885886139638*1j, -.2719299580251652601727704+1.187099379810885886139638*1j] elif N == 21: p = [-.9072262653142957028884077, -.9025428073192696303995083-.1105252572789856480992275*1j, -.9025428073192696303995083+.1105252572789856480992275*1j, -.8883808106664449854431605-.2213069215084350419975358*1j, -.8883808106664449854431605+.2213069215084350419975358*1j, -.8643915813643204553970169-.3326258512522187083009453*1j, -.8643915813643204553970169+.3326258512522187083009453*1j, -.8299435470674444100273463-.4448177739407956609694059*1j, -.8299435470674444100273463+.4448177739407956609694059*1j, -.7840287980408341576100581-.5583186348022854707564856*1j, -.7840287980408341576100581+.5583186348022854707564856*1j, -.7250839687106612822281339-.6737426063024382240549898*1j, -.7250839687106612822281339+.6737426063024382240549898*1j, -.6506315378609463397807996-.7920349342629491368548074*1j, -.6506315378609463397807996+.7920349342629491368548074*1j, -.5564766488918562465935297-.9148198405846724121600860*1j, -.5564766488918562465935297+.9148198405846724121600860*1j, -.4345168906815271799687308-1.045382255856986531461592*1j, -.4345168906815271799687308+1.045382255856986531461592*1j, -.2640041595834031147954813-1.192762031948052470183960*1j, -.2640041595834031147954813+1.192762031948052470183960*1j] elif N == 22: p = [-.9058702269930872551848625-52774908289999045189007100.0E-27*1j, -.9058702269930872551848625+52774908289999045189007100.0E-27*1j, -.8972983138153530955952835-.1584351912289865608659759*1j, -.8972983138153530955952835+.1584351912289865608659759*1j, -.8799661455640176154025352-.2644363039201535049656450*1j, -.8799661455640176154025352+.2644363039201535049656450*1j, -.8534754036851687233084587-.3710389319482319823405321*1j, -.8534754036851687233084587+.3710389319482319823405321*1j, -.8171682088462720394344996-.4785619492202780899653575*1j, -.8171682088462720394344996+.4785619492202780899653575*1j, -.7700332930556816872932937-.5874255426351153211965601*1j, -.7700332930556816872932937+.5874255426351153211965601*1j, -.7105305456418785989070935-.6982266265924524000098548*1j, -.7105305456418785989070935+.6982266265924524000098548*1j, -.6362427683267827226840153-.8118875040246347267248508*1j, -.6362427683267827226840153+.8118875040246347267248508*1j, -.5430983056306302779658129-.9299947824439872998916657*1j, -.5430983056306302779658129+.9299947824439872998916657*1j, -.4232528745642628461715044-1.055755605227545931204656*1j, -.4232528745642628461715044+1.055755605227545931204656*1j, -.2566376987939318038016012-1.197982433555213008346532*1j, -.2566376987939318038016012+1.197982433555213008346532*1j] elif N == 23: p = [-.9066732476324988168207439, -.9027564979912504609412993-.1010534335314045013252480*1j, -.9027564979912504609412993+.1010534335314045013252480*1j, -.8909283242471251458653994-.2023024699381223418195228*1j, -.8909283242471251458653994+.2023024699381223418195228*1j, -.8709469395587416239596874-.3039581993950041588888925*1j, -.8709469395587416239596874+.3039581993950041588888925*1j, -.8423805948021127057054288-.4062657948237602726779246*1j, -.8423805948021127057054288+.4062657948237602726779246*1j, -.8045561642053176205623187-.5095305912227258268309528*1j, -.8045561642053176205623187+.5095305912227258268309528*1j, -.7564660146829880581478138-.6141594859476032127216463*1j, -.7564660146829880581478138+.6141594859476032127216463*1j, -.6965966033912705387505040-.7207341374753046970247055*1j, -.6965966033912705387505040+.7207341374753046970247055*1j, -.6225903228771341778273152-.8301558302812980678845563*1j, -.6225903228771341778273152+.8301558302812980678845563*1j, -.5304922463810191698502226-.9439760364018300083750242*1j, -.5304922463810191698502226+.9439760364018300083750242*1j, -.4126986617510148836149955-1.065328794475513585531053*1j, -.4126986617510148836149955+1.065328794475513585531053*1j, -.2497697202208956030229911-1.202813187870697831365338*1j, -.2497697202208956030229911+1.202813187870697831365338*1j] elif N == 24: p = [-.9055312363372773709269407-48440066540478700874836350.0E-27*1j, -.9055312363372773709269407+48440066540478700874836350.0E-27*1j, -.8983105104397872954053307-.1454056133873610120105857*1j, -.8983105104397872954053307+.1454056133873610120105857*1j, -.8837358034555706623131950-.2426335234401383076544239*1j, -.8837358034555706623131950+.2426335234401383076544239*1j, -.8615278304016353651120610-.3403202112618624773397257*1j, -.8615278304016353651120610+.3403202112618624773397257*1j, -.8312326466813240652679563-.4386985933597305434577492*1j, -.8312326466813240652679563+.4386985933597305434577492*1j, -.7921695462343492518845446-.5380628490968016700338001*1j, -.7921695462343492518845446+.5380628490968016700338001*1j, -.7433392285088529449175873-.6388084216222567930378296*1j, -.7433392285088529449175873+.6388084216222567930378296*1j, -.6832565803536521302816011-.7415032695091650806797753*1j, -.6832565803536521302816011+.7415032695091650806797753*1j, -.6096221567378335562589532-.8470292433077202380020454*1j, -.6096221567378335562589532+.8470292433077202380020454*1j, -.5185914574820317343536707-.9569048385259054576937721*1j, -.5185914574820317343536707+.9569048385259054576937721*1j, -.4027853855197518014786978-1.074195196518674765143729*1j, -.4027853855197518014786978+1.074195196518674765143729*1j, -.2433481337524869675825448-1.207298683731972524975429*1j, -.2433481337524869675825448+1.207298683731972524975429*1j] elif N == 25: p = [-.9062073871811708652496104, -.9028833390228020537142561-93077131185102967450643820.0E-27*1j, -.9028833390228020537142561+93077131185102967450643820.0E-27*1j, -.8928551459883548836774529-.1863068969804300712287138*1j, -.8928551459883548836774529+.1863068969804300712287138*1j, -.8759497989677857803656239-.2798521321771408719327250*1j, -.8759497989677857803656239+.2798521321771408719327250*1j, -.8518616886554019782346493-.3738977875907595009446142*1j, -.8518616886554019782346493+.3738977875907595009446142*1j, -.8201226043936880253962552-.4686668574656966589020580*1j, -.8201226043936880253962552+.4686668574656966589020580*1j, -.7800496278186497225905443-.5644441210349710332887354*1j, -.7800496278186497225905443+.5644441210349710332887354*1j, -.7306549271849967721596735-.6616149647357748681460822*1j, -.7306549271849967721596735+.6616149647357748681460822*1j, -.6704827128029559528610523-.7607348858167839877987008*1j, -.6704827128029559528610523+.7607348858167839877987008*1j, -.5972898661335557242320528-.8626676330388028512598538*1j, -.5972898661335557242320528+.8626676330388028512598538*1j, -.5073362861078468845461362-.9689006305344868494672405*1j, -.5073362861078468845461362+.9689006305344868494672405*1j, -.3934529878191079606023847-1.082433927173831581956863*1j, -.3934529878191079606023847+1.082433927173831581956863*1j, -.2373280669322028974199184-1.211476658382565356579418*1j, -.2373280669322028974199184+1.211476658382565356579418*1j] else: raise ValueError, "Bessel Filter not supported for order %d" % N return z, p, k
p = [-.9058702269930872551848625-52774908289999045189007100.0E-27*1j, -.9058702269930872551848625+52774908289999045189007100.0E-27*1j,
p = [-.9058702269930872551848625-52774908289999045189007100.0e-27*1j, -.9058702269930872551848625+52774908289999045189007100.0e-27*1j,
def besselap(N): """Return (z,p,k) zero, pole, gain for analog prototype of an Nth order Bessel filter.""" z = [] k = 1 if N == 0: p = []; elif N == 1: p = [-1] elif N == 2: p = [-.8660254037844386467637229+.4999999999999999999999996*1j, -.8660254037844386467637229-.4999999999999999999999996*1j] elif N == 3: p = [-.9416000265332067855971980, -.7456403858480766441810907-.7113666249728352680992154*1j, -.7456403858480766441810907+.7113666249728352680992154*1j] elif N == 4: p = [-.6572111716718829545787781-.8301614350048733772399715*1j, -.6572111716718829545787788+.8301614350048733772399715*1j, -.9047587967882449459642637-.2709187330038746636700923*1j, -.9047587967882449459642624+.2709187330038746636700926*1j] elif N == 5: p = [-.9264420773877602247196260, -.8515536193688395541722677-.4427174639443327209850002*1j, -.8515536193688395541722677+.4427174639443327209850002*1j, -.5905759446119191779319432-.9072067564574549539291747*1j, -.5905759446119191779319432+.9072067564574549539291747*1j] elif N == 6: p = [-.9093906830472271808050953-.1856964396793046769246397*1j, -.9093906830472271808050953+.1856964396793046769246397*1j, -.7996541858328288520243325-.5621717346937317988594118*1j, -.7996541858328288520243325+.5621717346937317988594118*1j, -.5385526816693109683073792-.9616876881954277199245657*1j, -.5385526816693109683073792+.9616876881954277199245657*1j] elif N == 7: p = [-.9194871556490290014311619, -.8800029341523374639772340-.3216652762307739398381830*1j, -.8800029341523374639772340+.3216652762307739398381830*1j, -.7527355434093214462291616-.6504696305522550699212995*1j, -.7527355434093214462291616+.6504696305522550699212995*1j, -.4966917256672316755024763-1.002508508454420401230220*1j, -.4966917256672316755024763+1.002508508454420401230220*1j] elif N == 8: p = [-.9096831546652910216327629-.1412437976671422927888150*1j, -.9096831546652910216327629+.1412437976671422927888150*1j, -.8473250802359334320103023-.4259017538272934994996429*1j, -.8473250802359334320103023+.4259017538272934994996429*1j, -.7111381808485399250796172-.7186517314108401705762571*1j, -.7111381808485399250796172+.7186517314108401705762571*1j, -.4621740412532122027072175-1.034388681126901058116589*1j, -.4621740412532122027072175+1.034388681126901058116589*1j] elif N == 9: p = [-.9154957797499037686769223, -.8911217017079759323183848-.2526580934582164192308115*1j, -.8911217017079759323183848+.2526580934582164192308115*1j, -.8148021112269012975514135-.5085815689631499483745341*1j, -.8148021112269012975514135+.5085815689631499483745341*1j, -.6743622686854761980403401-.7730546212691183706919682*1j, -.6743622686854761980403401+.7730546212691183706919682*1j, -.4331415561553618854685942-1.060073670135929666774323*1j, -.4331415561553618854685942+1.060073670135929666774323*1j] elif N == 10: p = [-.9091347320900502436826431-.1139583137335511169927714*1j, -.9091347320900502436826431+.1139583137335511169927714*1j, -.8688459641284764527921864-.3430008233766309973110589*1j, -.8688459641284764527921864+.3430008233766309973110589*1j, -.7837694413101441082655890-.5759147538499947070009852*1j, -.7837694413101441082655890+.5759147538499947070009852*1j, -.6417513866988316136190854-.8175836167191017226233947*1j, -.6417513866988316136190854+.8175836167191017226233947*1j, -.4083220732868861566219785-1.081274842819124562037210*1j, -.4083220732868861566219785+1.081274842819124562037210*1j] elif N == 11: p = [-.9129067244518981934637318, -.8963656705721166099815744-.2080480375071031919692341*1j -.8963656705721166099815744+.2080480375071031919692341*1j, -.8453044014712962954184557-.4178696917801248292797448*1j, -.8453044014712962954184557+.4178696917801248292797448*1j, -.7546938934722303128102142-.6319150050721846494520941*1j, -.7546938934722303128102142+.6319150050721846494520941*1j, -.6126871554915194054182909-.8547813893314764631518509*1j, -.6126871554915194054182909+.8547813893314764631518509*1j, -.3868149510055090879155425-1.099117466763120928733632*1j, -.3868149510055090879155425+1.099117466763120928733632*1j] elif N == 12: p = [-.9084478234140682638817772-95506365213450398415258360.0e-27*1j, -.9084478234140682638817772+95506365213450398415258360.0e-27*1j, -.8802534342016826507901575-.2871779503524226723615457*1j, -.8802534342016826507901575+.2871779503524226723615457*1j, -.8217296939939077285792834-.4810212115100676440620548*1j, -.8217296939939077285792834+.4810212115100676440620548*1j, -.7276681615395159454547013-.6792961178764694160048987*1j, -.7276681615395159454547013+.6792961178764694160048987*1j, -.5866369321861477207528215-.8863772751320727026622149*1j, -.5866369321861477207528215+.8863772751320727026622149*1j, -.3679640085526312839425808-1.114373575641546257595657*1j, -.3679640085526312839425808+1.114373575641546257595657*1j] elif N == 13: p = [-.9110914665984182781070663, -.8991314665475196220910718-.1768342956161043620980863*1j, -.8991314665475196220910718+.1768342956161043620980863*1j, -.8625094198260548711573628-.3547413731172988997754038*1j, -.8625094198260548711573628+.3547413731172988997754038*1j, -.7987460692470972510394686-.5350752120696801938272504*1j, -.7987460692470972510394686+.5350752120696801938272504*1j, -.7026234675721275653944062-.7199611890171304131266374*1j, -.7026234675721275653944062+.7199611890171304131266374*1j, -.5631559842430199266325818-.9135900338325109684927731*1j, -.5631559842430199266325818+.9135900338325109684927731*1j, -.3512792323389821669401925-1.127591548317705678613239*1j, -.3512792323389821669401925+1.127591548317705678613239*1j] elif N == 14: p = [-.9077932138396487614720659-82196399419401501888968130.0E-27*1j, -.9077932138396487614720659+82196399419401501888968130.0E-27*1j, -.8869506674916445312089167-.2470079178765333183201435*1j, -.8869506674916445312089167+.2470079178765333183201435*1j, -.8441199160909851197897667-.4131653825102692595237260*1j, -.8441199160909851197897667+.4131653825102692595237260*1j, -.7766591387063623897344648-.5819170677377608590492434*1j, -.7766591387063623897344648+.5819170677377608590492434*1j, -.6794256425119233117869491-.7552857305042033418417492*1j, -.6794256425119233117869491+.7552857305042033418417492*1j, -.5418766775112297376541293-.9373043683516919569183099*1j, -.5418766775112297376541293+.9373043683516919569183099*1j, -.3363868224902037330610040-1.139172297839859991370924*1j, -.3363868224902037330610040+1.139172297839859991370924*1j] elif N == 15: p = [-.9097482363849064167228581, -.9006981694176978324932918-.1537681197278439351298882*1j, -.9006981694176978324932918+.1537681197278439351298882*1j, -.8731264620834984978337843-.3082352470564267657715883*1j, -.8731264620834984978337843+.3082352470564267657715883*1j, -.8256631452587146506294553-.4642348752734325631275134*1j, -.8256631452587146506294553+.4642348752734325631275134*1j, -.7556027168970728127850416-.6229396358758267198938604*1j, -.7556027168970728127850416+.6229396358758267198938604*1j, -.6579196593110998676999362-.7862895503722515897065645*1j, -.6579196593110998676999362+.7862895503722515897065645*1j, -.5224954069658330616875186-.9581787261092526478889345*1j, -.5224954069658330616875186+.9581787261092526478889345*1j, -.3229963059766444287113517-1.149416154583629539665297*1j, -.3229963059766444287113517+1.149416154583629539665297*1j] elif N == 16: p = [-.9072099595087001356491337-72142113041117326028823950.0E-27*1j, -.9072099595087001356491337+72142113041117326028823950.0E-27*1j, -.8911723070323647674780132-.2167089659900576449410059*1j, -.8911723070323647674780132+.2167089659900576449410059*1j, -.8584264231521330481755780-.3621697271802065647661080*1j, -.8584264231521330481755780+.3621697271802065647661080*1j, -.8074790293236003885306146-.5092933751171800179676218*1j, -.8074790293236003885306146+.5092933751171800179676218*1j, -.7356166304713115980927279-.6591950877860393745845254*1j, -.7356166304713115980927279+.6591950877860393745845254*1j, -.6379502514039066715773828-.8137453537108761895522580*1j, -.6379502514039066715773828+.8137453537108761895522580*1j, -.5047606444424766743309967-.9767137477799090692947061*1j, -.5047606444424766743309967+.9767137477799090692947061*1j, -.3108782755645387813283867-1.158552841199330479412225*1j, -.3108782755645387813283867+1.158552841199330479412225*1j] elif N == 17: p = [-.9087141161336397432860029, -.9016273850787285964692844-.1360267995173024591237303*1j, -.9016273850787285964692844+.1360267995173024591237303*1j, -.8801100704438627158492165-.2725347156478803885651973*1j, -.8801100704438627158492165+.2725347156478803885651973*1j, -.8433414495836129204455491-.4100759282910021624185986*1j, -.8433414495836129204455491+.4100759282910021624185986*1j, -.7897644147799708220288138-.5493724405281088674296232*1j, -.7897644147799708220288138+.5493724405281088674296232*1j, -.7166893842372349049842743-.6914936286393609433305754*1j, -.7166893842372349049842743+.6914936286393609433305754*1j, -.6193710717342144521602448-.8382497252826992979368621*1j, -.6193710717342144521602448+.8382497252826992979368621*1j, -.4884629337672704194973683-.9932971956316781632345466*1j, -.4884629337672704194973683+.9932971956316781632345466*1j, -.2998489459990082015466971-1.166761272925668786676672*1j, -.2998489459990082015466971+1.166761272925668786676672*1j] elif N == 18: p = [-.9067004324162775554189031-64279241063930693839360680.0E-27*1j, -.9067004324162775554189031+64279241063930693839360680.0E-27*1j, -.8939764278132455733032155-.1930374640894758606940586*1j, -.8939764278132455733032155+.1930374640894758606940586*1j, -.8681095503628830078317207-.3224204925163257604931634*1j, -.8681095503628830078317207+.3224204925163257604931634*1j, -.8281885016242836608829018-.4529385697815916950149364*1j, -.8281885016242836608829018+.4529385697815916950149364*1j, -.7726285030739558780127746-.5852778162086640620016316*1j, -.7726285030739558780127746+.5852778162086640620016316*1j, -.6987821445005273020051878-.7204696509726630531663123*1j, -.6987821445005273020051878+.7204696509726630531663123*1j, -.6020482668090644386627299-.8602708961893664447167418*1j, -.6020482668090644386627299+.8602708961893664447167418*1j, -.4734268069916151511140032-1.008234300314801077034158*1j, -.4734268069916151511140032+1.008234300314801077034158*1j, -.2897592029880489845789953-1.174183010600059128532230*1j, -.2897592029880489845789953+1.174183010600059128532230*1j] elif N == 19: p = [-.9078934217899404528985092, -.9021937639390660668922536-.1219568381872026517578164*1j, -.9021937639390660668922536+.1219568381872026517578164*1j, -.8849290585034385274001112-.2442590757549818229026280*1j, -.8849290585034385274001112+.2442590757549818229026280*1j, -.8555768765618421591093993-.3672925896399872304734923*1j, -.8555768765618421591093993+.3672925896399872304734923*1j, -.8131725551578197705476160-.4915365035562459055630005*1j, -.8131725551578197705476160+.4915365035562459055630005*1j, -.7561260971541629355231897-.6176483917970178919174173*1j, -.7561260971541629355231897+.6176483917970178919174173*1j, -.6818424412912442033411634-.7466272357947761283262338*1j, -.6818424412912442033411634+.7466272357947761283262338*1j, -.5858613321217832644813602-.8801817131014566284786759*1j, -.5858613321217832644813602+.8801817131014566284786759*1j, -.4595043449730988600785456-1.021768776912671221830298*1j, -.4595043449730988600785456+1.021768776912671221830298*1j, -.2804866851439370027628724-1.180931628453291873626003*1j, -.2804866851439370027628724+1.180931628453291873626003*1j] elif N == 20: p = [-.9062570115576771146523497-57961780277849516990208850.0E-27*1j, -.9062570115576771146523497+57961780277849516990208850.0E-27*1j, -.8959150941925768608568248-.1740317175918705058595844*1j, -.8959150941925768608568248+.1740317175918705058595844*1j, -.8749560316673332850673214-.2905559296567908031706902*1j, -.8749560316673332850673214+.2905559296567908031706902*1j, -.8427907479956670633544106-.4078917326291934082132821*1j, -.8427907479956670633544106+.4078917326291934082132821*1j, -.7984251191290606875799876-.5264942388817132427317659*1j, -.7984251191290606875799876+.5264942388817132427317659*1j, -.7402780309646768991232610-.6469975237605228320268752*1j, -.7402780309646768991232610+.6469975237605228320268752*1j, -.6658120544829934193890626-.7703721701100763015154510*1j, -.6658120544829934193890626+.7703721701100763015154510*1j, -.5707026806915714094398061-.8982829066468255593407161*1j, -.5707026806915714094398061+.8982829066468255593407161*1j, -.4465700698205149555701841-1.034097702560842962315411*1j, -.4465700698205149555701841+1.034097702560842962315411*1j, -.2719299580251652601727704-1.187099379810885886139638*1j, -.2719299580251652601727704+1.187099379810885886139638*1j] elif N == 21: p = [-.9072262653142957028884077, -.9025428073192696303995083-.1105252572789856480992275*1j, -.9025428073192696303995083+.1105252572789856480992275*1j, -.8883808106664449854431605-.2213069215084350419975358*1j, -.8883808106664449854431605+.2213069215084350419975358*1j, -.8643915813643204553970169-.3326258512522187083009453*1j, -.8643915813643204553970169+.3326258512522187083009453*1j, -.8299435470674444100273463-.4448177739407956609694059*1j, -.8299435470674444100273463+.4448177739407956609694059*1j, -.7840287980408341576100581-.5583186348022854707564856*1j, -.7840287980408341576100581+.5583186348022854707564856*1j, -.7250839687106612822281339-.6737426063024382240549898*1j, -.7250839687106612822281339+.6737426063024382240549898*1j, -.6506315378609463397807996-.7920349342629491368548074*1j, -.6506315378609463397807996+.7920349342629491368548074*1j, -.5564766488918562465935297-.9148198405846724121600860*1j, -.5564766488918562465935297+.9148198405846724121600860*1j, -.4345168906815271799687308-1.045382255856986531461592*1j, -.4345168906815271799687308+1.045382255856986531461592*1j, -.2640041595834031147954813-1.192762031948052470183960*1j, -.2640041595834031147954813+1.192762031948052470183960*1j] elif N == 22: p = [-.9058702269930872551848625-52774908289999045189007100.0E-27*1j, -.9058702269930872551848625+52774908289999045189007100.0E-27*1j, -.8972983138153530955952835-.1584351912289865608659759*1j, -.8972983138153530955952835+.1584351912289865608659759*1j, -.8799661455640176154025352-.2644363039201535049656450*1j, -.8799661455640176154025352+.2644363039201535049656450*1j, -.8534754036851687233084587-.3710389319482319823405321*1j, -.8534754036851687233084587+.3710389319482319823405321*1j, -.8171682088462720394344996-.4785619492202780899653575*1j, -.8171682088462720394344996+.4785619492202780899653575*1j, -.7700332930556816872932937-.5874255426351153211965601*1j, -.7700332930556816872932937+.5874255426351153211965601*1j, -.7105305456418785989070935-.6982266265924524000098548*1j, -.7105305456418785989070935+.6982266265924524000098548*1j, -.6362427683267827226840153-.8118875040246347267248508*1j, -.6362427683267827226840153+.8118875040246347267248508*1j, -.5430983056306302779658129-.9299947824439872998916657*1j, -.5430983056306302779658129+.9299947824439872998916657*1j, -.4232528745642628461715044-1.055755605227545931204656*1j, -.4232528745642628461715044+1.055755605227545931204656*1j, -.2566376987939318038016012-1.197982433555213008346532*1j, -.2566376987939318038016012+1.197982433555213008346532*1j] elif N == 23: p = [-.9066732476324988168207439, -.9027564979912504609412993-.1010534335314045013252480*1j, -.9027564979912504609412993+.1010534335314045013252480*1j, -.8909283242471251458653994-.2023024699381223418195228*1j, -.8909283242471251458653994+.2023024699381223418195228*1j, -.8709469395587416239596874-.3039581993950041588888925*1j, -.8709469395587416239596874+.3039581993950041588888925*1j, -.8423805948021127057054288-.4062657948237602726779246*1j, -.8423805948021127057054288+.4062657948237602726779246*1j, -.8045561642053176205623187-.5095305912227258268309528*1j, -.8045561642053176205623187+.5095305912227258268309528*1j, -.7564660146829880581478138-.6141594859476032127216463*1j, -.7564660146829880581478138+.6141594859476032127216463*1j, -.6965966033912705387505040-.7207341374753046970247055*1j, -.6965966033912705387505040+.7207341374753046970247055*1j, -.6225903228771341778273152-.8301558302812980678845563*1j, -.6225903228771341778273152+.8301558302812980678845563*1j, -.5304922463810191698502226-.9439760364018300083750242*1j, -.5304922463810191698502226+.9439760364018300083750242*1j, -.4126986617510148836149955-1.065328794475513585531053*1j, -.4126986617510148836149955+1.065328794475513585531053*1j, -.2497697202208956030229911-1.202813187870697831365338*1j, -.2497697202208956030229911+1.202813187870697831365338*1j] elif N == 24: p = [-.9055312363372773709269407-48440066540478700874836350.0E-27*1j, -.9055312363372773709269407+48440066540478700874836350.0E-27*1j, -.8983105104397872954053307-.1454056133873610120105857*1j, -.8983105104397872954053307+.1454056133873610120105857*1j, -.8837358034555706623131950-.2426335234401383076544239*1j, -.8837358034555706623131950+.2426335234401383076544239*1j, -.8615278304016353651120610-.3403202112618624773397257*1j, -.8615278304016353651120610+.3403202112618624773397257*1j, -.8312326466813240652679563-.4386985933597305434577492*1j, -.8312326466813240652679563+.4386985933597305434577492*1j, -.7921695462343492518845446-.5380628490968016700338001*1j, -.7921695462343492518845446+.5380628490968016700338001*1j, -.7433392285088529449175873-.6388084216222567930378296*1j, -.7433392285088529449175873+.6388084216222567930378296*1j, -.6832565803536521302816011-.7415032695091650806797753*1j, -.6832565803536521302816011+.7415032695091650806797753*1j, -.6096221567378335562589532-.8470292433077202380020454*1j, -.6096221567378335562589532+.8470292433077202380020454*1j, -.5185914574820317343536707-.9569048385259054576937721*1j, -.5185914574820317343536707+.9569048385259054576937721*1j, -.4027853855197518014786978-1.074195196518674765143729*1j, -.4027853855197518014786978+1.074195196518674765143729*1j, -.2433481337524869675825448-1.207298683731972524975429*1j, -.2433481337524869675825448+1.207298683731972524975429*1j] elif N == 25: p = [-.9062073871811708652496104, -.9028833390228020537142561-93077131185102967450643820.0E-27*1j, -.9028833390228020537142561+93077131185102967450643820.0E-27*1j, -.8928551459883548836774529-.1863068969804300712287138*1j, -.8928551459883548836774529+.1863068969804300712287138*1j, -.8759497989677857803656239-.2798521321771408719327250*1j, -.8759497989677857803656239+.2798521321771408719327250*1j, -.8518616886554019782346493-.3738977875907595009446142*1j, -.8518616886554019782346493+.3738977875907595009446142*1j, -.8201226043936880253962552-.4686668574656966589020580*1j, -.8201226043936880253962552+.4686668574656966589020580*1j, -.7800496278186497225905443-.5644441210349710332887354*1j, -.7800496278186497225905443+.5644441210349710332887354*1j, -.7306549271849967721596735-.6616149647357748681460822*1j, -.7306549271849967721596735+.6616149647357748681460822*1j, -.6704827128029559528610523-.7607348858167839877987008*1j, -.6704827128029559528610523+.7607348858167839877987008*1j, -.5972898661335557242320528-.8626676330388028512598538*1j, -.5972898661335557242320528+.8626676330388028512598538*1j, -.5073362861078468845461362-.9689006305344868494672405*1j, -.5073362861078468845461362+.9689006305344868494672405*1j, -.3934529878191079606023847-1.082433927173831581956863*1j, -.3934529878191079606023847+1.082433927173831581956863*1j, -.2373280669322028974199184-1.211476658382565356579418*1j, -.2373280669322028974199184+1.211476658382565356579418*1j] else: raise ValueError, "Bessel Filter not supported for order %d" % N return z, p, k
p = [-.9055312363372773709269407-48440066540478700874836350.0E-27*1j, -.9055312363372773709269407+48440066540478700874836350.0E-27*1j,
p = [-.9055312363372773709269407-48440066540478700874836350.0e-27*1j, -.9055312363372773709269407+48440066540478700874836350.0e-27*1j,
def besselap(N): """Return (z,p,k) zero, pole, gain for analog prototype of an Nth order Bessel filter.""" z = [] k = 1 if N == 0: p = []; elif N == 1: p = [-1] elif N == 2: p = [-.8660254037844386467637229+.4999999999999999999999996*1j, -.8660254037844386467637229-.4999999999999999999999996*1j] elif N == 3: p = [-.9416000265332067855971980, -.7456403858480766441810907-.7113666249728352680992154*1j, -.7456403858480766441810907+.7113666249728352680992154*1j] elif N == 4: p = [-.6572111716718829545787781-.8301614350048733772399715*1j, -.6572111716718829545787788+.8301614350048733772399715*1j, -.9047587967882449459642637-.2709187330038746636700923*1j, -.9047587967882449459642624+.2709187330038746636700926*1j] elif N == 5: p = [-.9264420773877602247196260, -.8515536193688395541722677-.4427174639443327209850002*1j, -.8515536193688395541722677+.4427174639443327209850002*1j, -.5905759446119191779319432-.9072067564574549539291747*1j, -.5905759446119191779319432+.9072067564574549539291747*1j] elif N == 6: p = [-.9093906830472271808050953-.1856964396793046769246397*1j, -.9093906830472271808050953+.1856964396793046769246397*1j, -.7996541858328288520243325-.5621717346937317988594118*1j, -.7996541858328288520243325+.5621717346937317988594118*1j, -.5385526816693109683073792-.9616876881954277199245657*1j, -.5385526816693109683073792+.9616876881954277199245657*1j] elif N == 7: p = [-.9194871556490290014311619, -.8800029341523374639772340-.3216652762307739398381830*1j, -.8800029341523374639772340+.3216652762307739398381830*1j, -.7527355434093214462291616-.6504696305522550699212995*1j, -.7527355434093214462291616+.6504696305522550699212995*1j, -.4966917256672316755024763-1.002508508454420401230220*1j, -.4966917256672316755024763+1.002508508454420401230220*1j] elif N == 8: p = [-.9096831546652910216327629-.1412437976671422927888150*1j, -.9096831546652910216327629+.1412437976671422927888150*1j, -.8473250802359334320103023-.4259017538272934994996429*1j, -.8473250802359334320103023+.4259017538272934994996429*1j, -.7111381808485399250796172-.7186517314108401705762571*1j, -.7111381808485399250796172+.7186517314108401705762571*1j, -.4621740412532122027072175-1.034388681126901058116589*1j, -.4621740412532122027072175+1.034388681126901058116589*1j] elif N == 9: p = [-.9154957797499037686769223, -.8911217017079759323183848-.2526580934582164192308115*1j, -.8911217017079759323183848+.2526580934582164192308115*1j, -.8148021112269012975514135-.5085815689631499483745341*1j, -.8148021112269012975514135+.5085815689631499483745341*1j, -.6743622686854761980403401-.7730546212691183706919682*1j, -.6743622686854761980403401+.7730546212691183706919682*1j, -.4331415561553618854685942-1.060073670135929666774323*1j, -.4331415561553618854685942+1.060073670135929666774323*1j] elif N == 10: p = [-.9091347320900502436826431-.1139583137335511169927714*1j, -.9091347320900502436826431+.1139583137335511169927714*1j, -.8688459641284764527921864-.3430008233766309973110589*1j, -.8688459641284764527921864+.3430008233766309973110589*1j, -.7837694413101441082655890-.5759147538499947070009852*1j, -.7837694413101441082655890+.5759147538499947070009852*1j, -.6417513866988316136190854-.8175836167191017226233947*1j, -.6417513866988316136190854+.8175836167191017226233947*1j, -.4083220732868861566219785-1.081274842819124562037210*1j, -.4083220732868861566219785+1.081274842819124562037210*1j] elif N == 11: p = [-.9129067244518981934637318, -.8963656705721166099815744-.2080480375071031919692341*1j -.8963656705721166099815744+.2080480375071031919692341*1j, -.8453044014712962954184557-.4178696917801248292797448*1j, -.8453044014712962954184557+.4178696917801248292797448*1j, -.7546938934722303128102142-.6319150050721846494520941*1j, -.7546938934722303128102142+.6319150050721846494520941*1j, -.6126871554915194054182909-.8547813893314764631518509*1j, -.6126871554915194054182909+.8547813893314764631518509*1j, -.3868149510055090879155425-1.099117466763120928733632*1j, -.3868149510055090879155425+1.099117466763120928733632*1j] elif N == 12: p = [-.9084478234140682638817772-95506365213450398415258360.0e-27*1j, -.9084478234140682638817772+95506365213450398415258360.0e-27*1j, -.8802534342016826507901575-.2871779503524226723615457*1j, -.8802534342016826507901575+.2871779503524226723615457*1j, -.8217296939939077285792834-.4810212115100676440620548*1j, -.8217296939939077285792834+.4810212115100676440620548*1j, -.7276681615395159454547013-.6792961178764694160048987*1j, -.7276681615395159454547013+.6792961178764694160048987*1j, -.5866369321861477207528215-.8863772751320727026622149*1j, -.5866369321861477207528215+.8863772751320727026622149*1j, -.3679640085526312839425808-1.114373575641546257595657*1j, -.3679640085526312839425808+1.114373575641546257595657*1j] elif N == 13: p = [-.9110914665984182781070663, -.8991314665475196220910718-.1768342956161043620980863*1j, -.8991314665475196220910718+.1768342956161043620980863*1j, -.8625094198260548711573628-.3547413731172988997754038*1j, -.8625094198260548711573628+.3547413731172988997754038*1j, -.7987460692470972510394686-.5350752120696801938272504*1j, -.7987460692470972510394686+.5350752120696801938272504*1j, -.7026234675721275653944062-.7199611890171304131266374*1j, -.7026234675721275653944062+.7199611890171304131266374*1j, -.5631559842430199266325818-.9135900338325109684927731*1j, -.5631559842430199266325818+.9135900338325109684927731*1j, -.3512792323389821669401925-1.127591548317705678613239*1j, -.3512792323389821669401925+1.127591548317705678613239*1j] elif N == 14: p = [-.9077932138396487614720659-82196399419401501888968130.0E-27*1j, -.9077932138396487614720659+82196399419401501888968130.0E-27*1j, -.8869506674916445312089167-.2470079178765333183201435*1j, -.8869506674916445312089167+.2470079178765333183201435*1j, -.8441199160909851197897667-.4131653825102692595237260*1j, -.8441199160909851197897667+.4131653825102692595237260*1j, -.7766591387063623897344648-.5819170677377608590492434*1j, -.7766591387063623897344648+.5819170677377608590492434*1j, -.6794256425119233117869491-.7552857305042033418417492*1j, -.6794256425119233117869491+.7552857305042033418417492*1j, -.5418766775112297376541293-.9373043683516919569183099*1j, -.5418766775112297376541293+.9373043683516919569183099*1j, -.3363868224902037330610040-1.139172297839859991370924*1j, -.3363868224902037330610040+1.139172297839859991370924*1j] elif N == 15: p = [-.9097482363849064167228581, -.9006981694176978324932918-.1537681197278439351298882*1j, -.9006981694176978324932918+.1537681197278439351298882*1j, -.8731264620834984978337843-.3082352470564267657715883*1j, -.8731264620834984978337843+.3082352470564267657715883*1j, -.8256631452587146506294553-.4642348752734325631275134*1j, -.8256631452587146506294553+.4642348752734325631275134*1j, -.7556027168970728127850416-.6229396358758267198938604*1j, -.7556027168970728127850416+.6229396358758267198938604*1j, -.6579196593110998676999362-.7862895503722515897065645*1j, -.6579196593110998676999362+.7862895503722515897065645*1j, -.5224954069658330616875186-.9581787261092526478889345*1j, -.5224954069658330616875186+.9581787261092526478889345*1j, -.3229963059766444287113517-1.149416154583629539665297*1j, -.3229963059766444287113517+1.149416154583629539665297*1j] elif N == 16: p = [-.9072099595087001356491337-72142113041117326028823950.0E-27*1j, -.9072099595087001356491337+72142113041117326028823950.0E-27*1j, -.8911723070323647674780132-.2167089659900576449410059*1j, -.8911723070323647674780132+.2167089659900576449410059*1j, -.8584264231521330481755780-.3621697271802065647661080*1j, -.8584264231521330481755780+.3621697271802065647661080*1j, -.8074790293236003885306146-.5092933751171800179676218*1j, -.8074790293236003885306146+.5092933751171800179676218*1j, -.7356166304713115980927279-.6591950877860393745845254*1j, -.7356166304713115980927279+.6591950877860393745845254*1j, -.6379502514039066715773828-.8137453537108761895522580*1j, -.6379502514039066715773828+.8137453537108761895522580*1j, -.5047606444424766743309967-.9767137477799090692947061*1j, -.5047606444424766743309967+.9767137477799090692947061*1j, -.3108782755645387813283867-1.158552841199330479412225*1j, -.3108782755645387813283867+1.158552841199330479412225*1j] elif N == 17: p = [-.9087141161336397432860029, -.9016273850787285964692844-.1360267995173024591237303*1j, -.9016273850787285964692844+.1360267995173024591237303*1j, -.8801100704438627158492165-.2725347156478803885651973*1j, -.8801100704438627158492165+.2725347156478803885651973*1j, -.8433414495836129204455491-.4100759282910021624185986*1j, -.8433414495836129204455491+.4100759282910021624185986*1j, -.7897644147799708220288138-.5493724405281088674296232*1j, -.7897644147799708220288138+.5493724405281088674296232*1j, -.7166893842372349049842743-.6914936286393609433305754*1j, -.7166893842372349049842743+.6914936286393609433305754*1j, -.6193710717342144521602448-.8382497252826992979368621*1j, -.6193710717342144521602448+.8382497252826992979368621*1j, -.4884629337672704194973683-.9932971956316781632345466*1j, -.4884629337672704194973683+.9932971956316781632345466*1j, -.2998489459990082015466971-1.166761272925668786676672*1j, -.2998489459990082015466971+1.166761272925668786676672*1j] elif N == 18: p = [-.9067004324162775554189031-64279241063930693839360680.0E-27*1j, -.9067004324162775554189031+64279241063930693839360680.0E-27*1j, -.8939764278132455733032155-.1930374640894758606940586*1j, -.8939764278132455733032155+.1930374640894758606940586*1j, -.8681095503628830078317207-.3224204925163257604931634*1j, -.8681095503628830078317207+.3224204925163257604931634*1j, -.8281885016242836608829018-.4529385697815916950149364*1j, -.8281885016242836608829018+.4529385697815916950149364*1j, -.7726285030739558780127746-.5852778162086640620016316*1j, -.7726285030739558780127746+.5852778162086640620016316*1j, -.6987821445005273020051878-.7204696509726630531663123*1j, -.6987821445005273020051878+.7204696509726630531663123*1j, -.6020482668090644386627299-.8602708961893664447167418*1j, -.6020482668090644386627299+.8602708961893664447167418*1j, -.4734268069916151511140032-1.008234300314801077034158*1j, -.4734268069916151511140032+1.008234300314801077034158*1j, -.2897592029880489845789953-1.174183010600059128532230*1j, -.2897592029880489845789953+1.174183010600059128532230*1j] elif N == 19: p = [-.9078934217899404528985092, -.9021937639390660668922536-.1219568381872026517578164*1j, -.9021937639390660668922536+.1219568381872026517578164*1j, -.8849290585034385274001112-.2442590757549818229026280*1j, -.8849290585034385274001112+.2442590757549818229026280*1j, -.8555768765618421591093993-.3672925896399872304734923*1j, -.8555768765618421591093993+.3672925896399872304734923*1j, -.8131725551578197705476160-.4915365035562459055630005*1j, -.8131725551578197705476160+.4915365035562459055630005*1j, -.7561260971541629355231897-.6176483917970178919174173*1j, -.7561260971541629355231897+.6176483917970178919174173*1j, -.6818424412912442033411634-.7466272357947761283262338*1j, -.6818424412912442033411634+.7466272357947761283262338*1j, -.5858613321217832644813602-.8801817131014566284786759*1j, -.5858613321217832644813602+.8801817131014566284786759*1j, -.4595043449730988600785456-1.021768776912671221830298*1j, -.4595043449730988600785456+1.021768776912671221830298*1j, -.2804866851439370027628724-1.180931628453291873626003*1j, -.2804866851439370027628724+1.180931628453291873626003*1j] elif N == 20: p = [-.9062570115576771146523497-57961780277849516990208850.0E-27*1j, -.9062570115576771146523497+57961780277849516990208850.0E-27*1j, -.8959150941925768608568248-.1740317175918705058595844*1j, -.8959150941925768608568248+.1740317175918705058595844*1j, -.8749560316673332850673214-.2905559296567908031706902*1j, -.8749560316673332850673214+.2905559296567908031706902*1j, -.8427907479956670633544106-.4078917326291934082132821*1j, -.8427907479956670633544106+.4078917326291934082132821*1j, -.7984251191290606875799876-.5264942388817132427317659*1j, -.7984251191290606875799876+.5264942388817132427317659*1j, -.7402780309646768991232610-.6469975237605228320268752*1j, -.7402780309646768991232610+.6469975237605228320268752*1j, -.6658120544829934193890626-.7703721701100763015154510*1j, -.6658120544829934193890626+.7703721701100763015154510*1j, -.5707026806915714094398061-.8982829066468255593407161*1j, -.5707026806915714094398061+.8982829066468255593407161*1j, -.4465700698205149555701841-1.034097702560842962315411*1j, -.4465700698205149555701841+1.034097702560842962315411*1j, -.2719299580251652601727704-1.187099379810885886139638*1j, -.2719299580251652601727704+1.187099379810885886139638*1j] elif N == 21: p = [-.9072262653142957028884077, -.9025428073192696303995083-.1105252572789856480992275*1j, -.9025428073192696303995083+.1105252572789856480992275*1j, -.8883808106664449854431605-.2213069215084350419975358*1j, -.8883808106664449854431605+.2213069215084350419975358*1j, -.8643915813643204553970169-.3326258512522187083009453*1j, -.8643915813643204553970169+.3326258512522187083009453*1j, -.8299435470674444100273463-.4448177739407956609694059*1j, -.8299435470674444100273463+.4448177739407956609694059*1j, -.7840287980408341576100581-.5583186348022854707564856*1j, -.7840287980408341576100581+.5583186348022854707564856*1j, -.7250839687106612822281339-.6737426063024382240549898*1j, -.7250839687106612822281339+.6737426063024382240549898*1j, -.6506315378609463397807996-.7920349342629491368548074*1j, -.6506315378609463397807996+.7920349342629491368548074*1j, -.5564766488918562465935297-.9148198405846724121600860*1j, -.5564766488918562465935297+.9148198405846724121600860*1j, -.4345168906815271799687308-1.045382255856986531461592*1j, -.4345168906815271799687308+1.045382255856986531461592*1j, -.2640041595834031147954813-1.192762031948052470183960*1j, -.2640041595834031147954813+1.192762031948052470183960*1j] elif N == 22: p = [-.9058702269930872551848625-52774908289999045189007100.0E-27*1j, -.9058702269930872551848625+52774908289999045189007100.0E-27*1j, -.8972983138153530955952835-.1584351912289865608659759*1j, -.8972983138153530955952835+.1584351912289865608659759*1j, -.8799661455640176154025352-.2644363039201535049656450*1j, -.8799661455640176154025352+.2644363039201535049656450*1j, -.8534754036851687233084587-.3710389319482319823405321*1j, -.8534754036851687233084587+.3710389319482319823405321*1j, -.8171682088462720394344996-.4785619492202780899653575*1j, -.8171682088462720394344996+.4785619492202780899653575*1j, -.7700332930556816872932937-.5874255426351153211965601*1j, -.7700332930556816872932937+.5874255426351153211965601*1j, -.7105305456418785989070935-.6982266265924524000098548*1j, -.7105305456418785989070935+.6982266265924524000098548*1j, -.6362427683267827226840153-.8118875040246347267248508*1j, -.6362427683267827226840153+.8118875040246347267248508*1j, -.5430983056306302779658129-.9299947824439872998916657*1j, -.5430983056306302779658129+.9299947824439872998916657*1j, -.4232528745642628461715044-1.055755605227545931204656*1j, -.4232528745642628461715044+1.055755605227545931204656*1j, -.2566376987939318038016012-1.197982433555213008346532*1j, -.2566376987939318038016012+1.197982433555213008346532*1j] elif N == 23: p = [-.9066732476324988168207439, -.9027564979912504609412993-.1010534335314045013252480*1j, -.9027564979912504609412993+.1010534335314045013252480*1j, -.8909283242471251458653994-.2023024699381223418195228*1j, -.8909283242471251458653994+.2023024699381223418195228*1j, -.8709469395587416239596874-.3039581993950041588888925*1j, -.8709469395587416239596874+.3039581993950041588888925*1j, -.8423805948021127057054288-.4062657948237602726779246*1j, -.8423805948021127057054288+.4062657948237602726779246*1j, -.8045561642053176205623187-.5095305912227258268309528*1j, -.8045561642053176205623187+.5095305912227258268309528*1j, -.7564660146829880581478138-.6141594859476032127216463*1j, -.7564660146829880581478138+.6141594859476032127216463*1j, -.6965966033912705387505040-.7207341374753046970247055*1j, -.6965966033912705387505040+.7207341374753046970247055*1j, -.6225903228771341778273152-.8301558302812980678845563*1j, -.6225903228771341778273152+.8301558302812980678845563*1j, -.5304922463810191698502226-.9439760364018300083750242*1j, -.5304922463810191698502226+.9439760364018300083750242*1j, -.4126986617510148836149955-1.065328794475513585531053*1j, -.4126986617510148836149955+1.065328794475513585531053*1j, -.2497697202208956030229911-1.202813187870697831365338*1j, -.2497697202208956030229911+1.202813187870697831365338*1j] elif N == 24: p = [-.9055312363372773709269407-48440066540478700874836350.0E-27*1j, -.9055312363372773709269407+48440066540478700874836350.0E-27*1j, -.8983105104397872954053307-.1454056133873610120105857*1j, -.8983105104397872954053307+.1454056133873610120105857*1j, -.8837358034555706623131950-.2426335234401383076544239*1j, -.8837358034555706623131950+.2426335234401383076544239*1j, -.8615278304016353651120610-.3403202112618624773397257*1j, -.8615278304016353651120610+.3403202112618624773397257*1j, -.8312326466813240652679563-.4386985933597305434577492*1j, -.8312326466813240652679563+.4386985933597305434577492*1j, -.7921695462343492518845446-.5380628490968016700338001*1j, -.7921695462343492518845446+.5380628490968016700338001*1j, -.7433392285088529449175873-.6388084216222567930378296*1j, -.7433392285088529449175873+.6388084216222567930378296*1j, -.6832565803536521302816011-.7415032695091650806797753*1j, -.6832565803536521302816011+.7415032695091650806797753*1j, -.6096221567378335562589532-.8470292433077202380020454*1j, -.6096221567378335562589532+.8470292433077202380020454*1j, -.5185914574820317343536707-.9569048385259054576937721*1j, -.5185914574820317343536707+.9569048385259054576937721*1j, -.4027853855197518014786978-1.074195196518674765143729*1j, -.4027853855197518014786978+1.074195196518674765143729*1j, -.2433481337524869675825448-1.207298683731972524975429*1j, -.2433481337524869675825448+1.207298683731972524975429*1j] elif N == 25: p = [-.9062073871811708652496104, -.9028833390228020537142561-93077131185102967450643820.0E-27*1j, -.9028833390228020537142561+93077131185102967450643820.0E-27*1j, -.8928551459883548836774529-.1863068969804300712287138*1j, -.8928551459883548836774529+.1863068969804300712287138*1j, -.8759497989677857803656239-.2798521321771408719327250*1j, -.8759497989677857803656239+.2798521321771408719327250*1j, -.8518616886554019782346493-.3738977875907595009446142*1j, -.8518616886554019782346493+.3738977875907595009446142*1j, -.8201226043936880253962552-.4686668574656966589020580*1j, -.8201226043936880253962552+.4686668574656966589020580*1j, -.7800496278186497225905443-.5644441210349710332887354*1j, -.7800496278186497225905443+.5644441210349710332887354*1j, -.7306549271849967721596735-.6616149647357748681460822*1j, -.7306549271849967721596735+.6616149647357748681460822*1j, -.6704827128029559528610523-.7607348858167839877987008*1j, -.6704827128029559528610523+.7607348858167839877987008*1j, -.5972898661335557242320528-.8626676330388028512598538*1j, -.5972898661335557242320528+.8626676330388028512598538*1j, -.5073362861078468845461362-.9689006305344868494672405*1j, -.5073362861078468845461362+.9689006305344868494672405*1j, -.3934529878191079606023847-1.082433927173831581956863*1j, -.3934529878191079606023847+1.082433927173831581956863*1j, -.2373280669322028974199184-1.211476658382565356579418*1j, -.2373280669322028974199184+1.211476658382565356579418*1j] else: raise ValueError, "Bessel Filter not supported for order %d" % N return z, p, k
-.9028833390228020537142561-93077131185102967450643820.0E-27*1j, -.9028833390228020537142561+93077131185102967450643820.0E-27*1j,
-.9028833390228020537142561-93077131185102967450643820.0e-27*1j, -.9028833390228020537142561+93077131185102967450643820.0e-27*1j,
def besselap(N): """Return (z,p,k) zero, pole, gain for analog prototype of an Nth order Bessel filter.""" z = [] k = 1 if N == 0: p = []; elif N == 1: p = [-1] elif N == 2: p = [-.8660254037844386467637229+.4999999999999999999999996*1j, -.8660254037844386467637229-.4999999999999999999999996*1j] elif N == 3: p = [-.9416000265332067855971980, -.7456403858480766441810907-.7113666249728352680992154*1j, -.7456403858480766441810907+.7113666249728352680992154*1j] elif N == 4: p = [-.6572111716718829545787781-.8301614350048733772399715*1j, -.6572111716718829545787788+.8301614350048733772399715*1j, -.9047587967882449459642637-.2709187330038746636700923*1j, -.9047587967882449459642624+.2709187330038746636700926*1j] elif N == 5: p = [-.9264420773877602247196260, -.8515536193688395541722677-.4427174639443327209850002*1j, -.8515536193688395541722677+.4427174639443327209850002*1j, -.5905759446119191779319432-.9072067564574549539291747*1j, -.5905759446119191779319432+.9072067564574549539291747*1j] elif N == 6: p = [-.9093906830472271808050953-.1856964396793046769246397*1j, -.9093906830472271808050953+.1856964396793046769246397*1j, -.7996541858328288520243325-.5621717346937317988594118*1j, -.7996541858328288520243325+.5621717346937317988594118*1j, -.5385526816693109683073792-.9616876881954277199245657*1j, -.5385526816693109683073792+.9616876881954277199245657*1j] elif N == 7: p = [-.9194871556490290014311619, -.8800029341523374639772340-.3216652762307739398381830*1j, -.8800029341523374639772340+.3216652762307739398381830*1j, -.7527355434093214462291616-.6504696305522550699212995*1j, -.7527355434093214462291616+.6504696305522550699212995*1j, -.4966917256672316755024763-1.002508508454420401230220*1j, -.4966917256672316755024763+1.002508508454420401230220*1j] elif N == 8: p = [-.9096831546652910216327629-.1412437976671422927888150*1j, -.9096831546652910216327629+.1412437976671422927888150*1j, -.8473250802359334320103023-.4259017538272934994996429*1j, -.8473250802359334320103023+.4259017538272934994996429*1j, -.7111381808485399250796172-.7186517314108401705762571*1j, -.7111381808485399250796172+.7186517314108401705762571*1j, -.4621740412532122027072175-1.034388681126901058116589*1j, -.4621740412532122027072175+1.034388681126901058116589*1j] elif N == 9: p = [-.9154957797499037686769223, -.8911217017079759323183848-.2526580934582164192308115*1j, -.8911217017079759323183848+.2526580934582164192308115*1j, -.8148021112269012975514135-.5085815689631499483745341*1j, -.8148021112269012975514135+.5085815689631499483745341*1j, -.6743622686854761980403401-.7730546212691183706919682*1j, -.6743622686854761980403401+.7730546212691183706919682*1j, -.4331415561553618854685942-1.060073670135929666774323*1j, -.4331415561553618854685942+1.060073670135929666774323*1j] elif N == 10: p = [-.9091347320900502436826431-.1139583137335511169927714*1j, -.9091347320900502436826431+.1139583137335511169927714*1j, -.8688459641284764527921864-.3430008233766309973110589*1j, -.8688459641284764527921864+.3430008233766309973110589*1j, -.7837694413101441082655890-.5759147538499947070009852*1j, -.7837694413101441082655890+.5759147538499947070009852*1j, -.6417513866988316136190854-.8175836167191017226233947*1j, -.6417513866988316136190854+.8175836167191017226233947*1j, -.4083220732868861566219785-1.081274842819124562037210*1j, -.4083220732868861566219785+1.081274842819124562037210*1j] elif N == 11: p = [-.9129067244518981934637318, -.8963656705721166099815744-.2080480375071031919692341*1j -.8963656705721166099815744+.2080480375071031919692341*1j, -.8453044014712962954184557-.4178696917801248292797448*1j, -.8453044014712962954184557+.4178696917801248292797448*1j, -.7546938934722303128102142-.6319150050721846494520941*1j, -.7546938934722303128102142+.6319150050721846494520941*1j, -.6126871554915194054182909-.8547813893314764631518509*1j, -.6126871554915194054182909+.8547813893314764631518509*1j, -.3868149510055090879155425-1.099117466763120928733632*1j, -.3868149510055090879155425+1.099117466763120928733632*1j] elif N == 12: p = [-.9084478234140682638817772-95506365213450398415258360.0e-27*1j, -.9084478234140682638817772+95506365213450398415258360.0e-27*1j, -.8802534342016826507901575-.2871779503524226723615457*1j, -.8802534342016826507901575+.2871779503524226723615457*1j, -.8217296939939077285792834-.4810212115100676440620548*1j, -.8217296939939077285792834+.4810212115100676440620548*1j, -.7276681615395159454547013-.6792961178764694160048987*1j, -.7276681615395159454547013+.6792961178764694160048987*1j, -.5866369321861477207528215-.8863772751320727026622149*1j, -.5866369321861477207528215+.8863772751320727026622149*1j, -.3679640085526312839425808-1.114373575641546257595657*1j, -.3679640085526312839425808+1.114373575641546257595657*1j] elif N == 13: p = [-.9110914665984182781070663, -.8991314665475196220910718-.1768342956161043620980863*1j, -.8991314665475196220910718+.1768342956161043620980863*1j, -.8625094198260548711573628-.3547413731172988997754038*1j, -.8625094198260548711573628+.3547413731172988997754038*1j, -.7987460692470972510394686-.5350752120696801938272504*1j, -.7987460692470972510394686+.5350752120696801938272504*1j, -.7026234675721275653944062-.7199611890171304131266374*1j, -.7026234675721275653944062+.7199611890171304131266374*1j, -.5631559842430199266325818-.9135900338325109684927731*1j, -.5631559842430199266325818+.9135900338325109684927731*1j, -.3512792323389821669401925-1.127591548317705678613239*1j, -.3512792323389821669401925+1.127591548317705678613239*1j] elif N == 14: p = [-.9077932138396487614720659-82196399419401501888968130.0E-27*1j, -.9077932138396487614720659+82196399419401501888968130.0E-27*1j, -.8869506674916445312089167-.2470079178765333183201435*1j, -.8869506674916445312089167+.2470079178765333183201435*1j, -.8441199160909851197897667-.4131653825102692595237260*1j, -.8441199160909851197897667+.4131653825102692595237260*1j, -.7766591387063623897344648-.5819170677377608590492434*1j, -.7766591387063623897344648+.5819170677377608590492434*1j, -.6794256425119233117869491-.7552857305042033418417492*1j, -.6794256425119233117869491+.7552857305042033418417492*1j, -.5418766775112297376541293-.9373043683516919569183099*1j, -.5418766775112297376541293+.9373043683516919569183099*1j, -.3363868224902037330610040-1.139172297839859991370924*1j, -.3363868224902037330610040+1.139172297839859991370924*1j] elif N == 15: p = [-.9097482363849064167228581, -.9006981694176978324932918-.1537681197278439351298882*1j, -.9006981694176978324932918+.1537681197278439351298882*1j, -.8731264620834984978337843-.3082352470564267657715883*1j, -.8731264620834984978337843+.3082352470564267657715883*1j, -.8256631452587146506294553-.4642348752734325631275134*1j, -.8256631452587146506294553+.4642348752734325631275134*1j, -.7556027168970728127850416-.6229396358758267198938604*1j, -.7556027168970728127850416+.6229396358758267198938604*1j, -.6579196593110998676999362-.7862895503722515897065645*1j, -.6579196593110998676999362+.7862895503722515897065645*1j, -.5224954069658330616875186-.9581787261092526478889345*1j, -.5224954069658330616875186+.9581787261092526478889345*1j, -.3229963059766444287113517-1.149416154583629539665297*1j, -.3229963059766444287113517+1.149416154583629539665297*1j] elif N == 16: p = [-.9072099595087001356491337-72142113041117326028823950.0E-27*1j, -.9072099595087001356491337+72142113041117326028823950.0E-27*1j, -.8911723070323647674780132-.2167089659900576449410059*1j, -.8911723070323647674780132+.2167089659900576449410059*1j, -.8584264231521330481755780-.3621697271802065647661080*1j, -.8584264231521330481755780+.3621697271802065647661080*1j, -.8074790293236003885306146-.5092933751171800179676218*1j, -.8074790293236003885306146+.5092933751171800179676218*1j, -.7356166304713115980927279-.6591950877860393745845254*1j, -.7356166304713115980927279+.6591950877860393745845254*1j, -.6379502514039066715773828-.8137453537108761895522580*1j, -.6379502514039066715773828+.8137453537108761895522580*1j, -.5047606444424766743309967-.9767137477799090692947061*1j, -.5047606444424766743309967+.9767137477799090692947061*1j, -.3108782755645387813283867-1.158552841199330479412225*1j, -.3108782755645387813283867+1.158552841199330479412225*1j] elif N == 17: p = [-.9087141161336397432860029, -.9016273850787285964692844-.1360267995173024591237303*1j, -.9016273850787285964692844+.1360267995173024591237303*1j, -.8801100704438627158492165-.2725347156478803885651973*1j, -.8801100704438627158492165+.2725347156478803885651973*1j, -.8433414495836129204455491-.4100759282910021624185986*1j, -.8433414495836129204455491+.4100759282910021624185986*1j, -.7897644147799708220288138-.5493724405281088674296232*1j, -.7897644147799708220288138+.5493724405281088674296232*1j, -.7166893842372349049842743-.6914936286393609433305754*1j, -.7166893842372349049842743+.6914936286393609433305754*1j, -.6193710717342144521602448-.8382497252826992979368621*1j, -.6193710717342144521602448+.8382497252826992979368621*1j, -.4884629337672704194973683-.9932971956316781632345466*1j, -.4884629337672704194973683+.9932971956316781632345466*1j, -.2998489459990082015466971-1.166761272925668786676672*1j, -.2998489459990082015466971+1.166761272925668786676672*1j] elif N == 18: p = [-.9067004324162775554189031-64279241063930693839360680.0E-27*1j, -.9067004324162775554189031+64279241063930693839360680.0E-27*1j, -.8939764278132455733032155-.1930374640894758606940586*1j, -.8939764278132455733032155+.1930374640894758606940586*1j, -.8681095503628830078317207-.3224204925163257604931634*1j, -.8681095503628830078317207+.3224204925163257604931634*1j, -.8281885016242836608829018-.4529385697815916950149364*1j, -.8281885016242836608829018+.4529385697815916950149364*1j, -.7726285030739558780127746-.5852778162086640620016316*1j, -.7726285030739558780127746+.5852778162086640620016316*1j, -.6987821445005273020051878-.7204696509726630531663123*1j, -.6987821445005273020051878+.7204696509726630531663123*1j, -.6020482668090644386627299-.8602708961893664447167418*1j, -.6020482668090644386627299+.8602708961893664447167418*1j, -.4734268069916151511140032-1.008234300314801077034158*1j, -.4734268069916151511140032+1.008234300314801077034158*1j, -.2897592029880489845789953-1.174183010600059128532230*1j, -.2897592029880489845789953+1.174183010600059128532230*1j] elif N == 19: p = [-.9078934217899404528985092, -.9021937639390660668922536-.1219568381872026517578164*1j, -.9021937639390660668922536+.1219568381872026517578164*1j, -.8849290585034385274001112-.2442590757549818229026280*1j, -.8849290585034385274001112+.2442590757549818229026280*1j, -.8555768765618421591093993-.3672925896399872304734923*1j, -.8555768765618421591093993+.3672925896399872304734923*1j, -.8131725551578197705476160-.4915365035562459055630005*1j, -.8131725551578197705476160+.4915365035562459055630005*1j, -.7561260971541629355231897-.6176483917970178919174173*1j, -.7561260971541629355231897+.6176483917970178919174173*1j, -.6818424412912442033411634-.7466272357947761283262338*1j, -.6818424412912442033411634+.7466272357947761283262338*1j, -.5858613321217832644813602-.8801817131014566284786759*1j, -.5858613321217832644813602+.8801817131014566284786759*1j, -.4595043449730988600785456-1.021768776912671221830298*1j, -.4595043449730988600785456+1.021768776912671221830298*1j, -.2804866851439370027628724-1.180931628453291873626003*1j, -.2804866851439370027628724+1.180931628453291873626003*1j] elif N == 20: p = [-.9062570115576771146523497-57961780277849516990208850.0E-27*1j, -.9062570115576771146523497+57961780277849516990208850.0E-27*1j, -.8959150941925768608568248-.1740317175918705058595844*1j, -.8959150941925768608568248+.1740317175918705058595844*1j, -.8749560316673332850673214-.2905559296567908031706902*1j, -.8749560316673332850673214+.2905559296567908031706902*1j, -.8427907479956670633544106-.4078917326291934082132821*1j, -.8427907479956670633544106+.4078917326291934082132821*1j, -.7984251191290606875799876-.5264942388817132427317659*1j, -.7984251191290606875799876+.5264942388817132427317659*1j, -.7402780309646768991232610-.6469975237605228320268752*1j, -.7402780309646768991232610+.6469975237605228320268752*1j, -.6658120544829934193890626-.7703721701100763015154510*1j, -.6658120544829934193890626+.7703721701100763015154510*1j, -.5707026806915714094398061-.8982829066468255593407161*1j, -.5707026806915714094398061+.8982829066468255593407161*1j, -.4465700698205149555701841-1.034097702560842962315411*1j, -.4465700698205149555701841+1.034097702560842962315411*1j, -.2719299580251652601727704-1.187099379810885886139638*1j, -.2719299580251652601727704+1.187099379810885886139638*1j] elif N == 21: p = [-.9072262653142957028884077, -.9025428073192696303995083-.1105252572789856480992275*1j, -.9025428073192696303995083+.1105252572789856480992275*1j, -.8883808106664449854431605-.2213069215084350419975358*1j, -.8883808106664449854431605+.2213069215084350419975358*1j, -.8643915813643204553970169-.3326258512522187083009453*1j, -.8643915813643204553970169+.3326258512522187083009453*1j, -.8299435470674444100273463-.4448177739407956609694059*1j, -.8299435470674444100273463+.4448177739407956609694059*1j, -.7840287980408341576100581-.5583186348022854707564856*1j, -.7840287980408341576100581+.5583186348022854707564856*1j, -.7250839687106612822281339-.6737426063024382240549898*1j, -.7250839687106612822281339+.6737426063024382240549898*1j, -.6506315378609463397807996-.7920349342629491368548074*1j, -.6506315378609463397807996+.7920349342629491368548074*1j, -.5564766488918562465935297-.9148198405846724121600860*1j, -.5564766488918562465935297+.9148198405846724121600860*1j, -.4345168906815271799687308-1.045382255856986531461592*1j, -.4345168906815271799687308+1.045382255856986531461592*1j, -.2640041595834031147954813-1.192762031948052470183960*1j, -.2640041595834031147954813+1.192762031948052470183960*1j] elif N == 22: p = [-.9058702269930872551848625-52774908289999045189007100.0E-27*1j, -.9058702269930872551848625+52774908289999045189007100.0E-27*1j, -.8972983138153530955952835-.1584351912289865608659759*1j, -.8972983138153530955952835+.1584351912289865608659759*1j, -.8799661455640176154025352-.2644363039201535049656450*1j, -.8799661455640176154025352+.2644363039201535049656450*1j, -.8534754036851687233084587-.3710389319482319823405321*1j, -.8534754036851687233084587+.3710389319482319823405321*1j, -.8171682088462720394344996-.4785619492202780899653575*1j, -.8171682088462720394344996+.4785619492202780899653575*1j, -.7700332930556816872932937-.5874255426351153211965601*1j, -.7700332930556816872932937+.5874255426351153211965601*1j, -.7105305456418785989070935-.6982266265924524000098548*1j, -.7105305456418785989070935+.6982266265924524000098548*1j, -.6362427683267827226840153-.8118875040246347267248508*1j, -.6362427683267827226840153+.8118875040246347267248508*1j, -.5430983056306302779658129-.9299947824439872998916657*1j, -.5430983056306302779658129+.9299947824439872998916657*1j, -.4232528745642628461715044-1.055755605227545931204656*1j, -.4232528745642628461715044+1.055755605227545931204656*1j, -.2566376987939318038016012-1.197982433555213008346532*1j, -.2566376987939318038016012+1.197982433555213008346532*1j] elif N == 23: p = [-.9066732476324988168207439, -.9027564979912504609412993-.1010534335314045013252480*1j, -.9027564979912504609412993+.1010534335314045013252480*1j, -.8909283242471251458653994-.2023024699381223418195228*1j, -.8909283242471251458653994+.2023024699381223418195228*1j, -.8709469395587416239596874-.3039581993950041588888925*1j, -.8709469395587416239596874+.3039581993950041588888925*1j, -.8423805948021127057054288-.4062657948237602726779246*1j, -.8423805948021127057054288+.4062657948237602726779246*1j, -.8045561642053176205623187-.5095305912227258268309528*1j, -.8045561642053176205623187+.5095305912227258268309528*1j, -.7564660146829880581478138-.6141594859476032127216463*1j, -.7564660146829880581478138+.6141594859476032127216463*1j, -.6965966033912705387505040-.7207341374753046970247055*1j, -.6965966033912705387505040+.7207341374753046970247055*1j, -.6225903228771341778273152-.8301558302812980678845563*1j, -.6225903228771341778273152+.8301558302812980678845563*1j, -.5304922463810191698502226-.9439760364018300083750242*1j, -.5304922463810191698502226+.9439760364018300083750242*1j, -.4126986617510148836149955-1.065328794475513585531053*1j, -.4126986617510148836149955+1.065328794475513585531053*1j, -.2497697202208956030229911-1.202813187870697831365338*1j, -.2497697202208956030229911+1.202813187870697831365338*1j] elif N == 24: p = [-.9055312363372773709269407-48440066540478700874836350.0E-27*1j, -.9055312363372773709269407+48440066540478700874836350.0E-27*1j, -.8983105104397872954053307-.1454056133873610120105857*1j, -.8983105104397872954053307+.1454056133873610120105857*1j, -.8837358034555706623131950-.2426335234401383076544239*1j, -.8837358034555706623131950+.2426335234401383076544239*1j, -.8615278304016353651120610-.3403202112618624773397257*1j, -.8615278304016353651120610+.3403202112618624773397257*1j, -.8312326466813240652679563-.4386985933597305434577492*1j, -.8312326466813240652679563+.4386985933597305434577492*1j, -.7921695462343492518845446-.5380628490968016700338001*1j, -.7921695462343492518845446+.5380628490968016700338001*1j, -.7433392285088529449175873-.6388084216222567930378296*1j, -.7433392285088529449175873+.6388084216222567930378296*1j, -.6832565803536521302816011-.7415032695091650806797753*1j, -.6832565803536521302816011+.7415032695091650806797753*1j, -.6096221567378335562589532-.8470292433077202380020454*1j, -.6096221567378335562589532+.8470292433077202380020454*1j, -.5185914574820317343536707-.9569048385259054576937721*1j, -.5185914574820317343536707+.9569048385259054576937721*1j, -.4027853855197518014786978-1.074195196518674765143729*1j, -.4027853855197518014786978+1.074195196518674765143729*1j, -.2433481337524869675825448-1.207298683731972524975429*1j, -.2433481337524869675825448+1.207298683731972524975429*1j] elif N == 25: p = [-.9062073871811708652496104, -.9028833390228020537142561-93077131185102967450643820.0E-27*1j, -.9028833390228020537142561+93077131185102967450643820.0E-27*1j, -.8928551459883548836774529-.1863068969804300712287138*1j, -.8928551459883548836774529+.1863068969804300712287138*1j, -.8759497989677857803656239-.2798521321771408719327250*1j, -.8759497989677857803656239+.2798521321771408719327250*1j, -.8518616886554019782346493-.3738977875907595009446142*1j, -.8518616886554019782346493+.3738977875907595009446142*1j, -.8201226043936880253962552-.4686668574656966589020580*1j, -.8201226043936880253962552+.4686668574656966589020580*1j, -.7800496278186497225905443-.5644441210349710332887354*1j, -.7800496278186497225905443+.5644441210349710332887354*1j, -.7306549271849967721596735-.6616149647357748681460822*1j, -.7306549271849967721596735+.6616149647357748681460822*1j, -.6704827128029559528610523-.7607348858167839877987008*1j, -.6704827128029559528610523+.7607348858167839877987008*1j, -.5972898661335557242320528-.8626676330388028512598538*1j, -.5972898661335557242320528+.8626676330388028512598538*1j, -.5073362861078468845461362-.9689006305344868494672405*1j, -.5073362861078468845461362+.9689006305344868494672405*1j, -.3934529878191079606023847-1.082433927173831581956863*1j, -.3934529878191079606023847+1.082433927173831581956863*1j, -.2373280669322028974199184-1.211476658382565356579418*1j, -.2373280669322028974199184+1.211476658382565356579418*1j] else: raise ValueError, "Bessel Filter not supported for order %d" % N return z, p, k
b = io.read_array(fname,atype=N.Int)
b = io.read_array(fname,atype=a.dtypechar)
def check_integer(self): from scipy import stats a = stats.randint.rvs(1,20,size=(3,4)) fname = tempfile.mktemp('.dat') io.write_array(fname,a) b = io.read_array(fname,atype=N.Int) assert_array_equal(a,b) os.remove(fname)
Ap = apply(approx_fhess_p,(xk,psupi,fprime,espilon)+args)
Ap = apply(approx_fhess_p,(xk,psupi,fprime,epsilon)+args)
def fmin_ncg(f, x0, fprime, fhess_p=None, fhess=None, args=(), avextol=1e-5, epsilon=1e-8, maxiter=None, full_output=0, disp=1): """Description: Minimize the function, f, whose gradient is given by fprime using the Newton-CG method. fhess_p must compute the hessian times an arbitrary vector. If it is not given, finite-differences on fprime are used to compute it. See Wright, and Nocedal 'Numerical Optimization', 1999, pg. 140. Inputs: f -- the Python function or method to be minimized. x0 -- the initial guess for the minimizer. fprime -- a function to compute the gradient of f: fprime(x, *args) fhess_p -- a function to compute the Hessian of f times an arbitrary vector: fhess_p (x, p, *args) fhess -- a function to compute the Hessian matrix of f. args -- extra arguments for f, fprime, fhess_p, and fhess (the same set of extra arguments is supplied to all of these functions). epsilon -- if fhess is approximated use this value for the step size (can be scalar or vector) Outputs: (xopt, {fopt, fcalls, gcalls, hcalls, warnflag}) xopt -- the minimizer of f fopt -- the value of the function at xopt: fopt = f(xopt) fcalls -- the number of function calls. gcalls -- the number of gradient calls. hcalls -- the number of hessian calls. warnflag -- algorithm warnings: 1 : 'Maximum number of iterations exceeded.' Additional Inputs: avextol -- Convergence is assumed when the average relative error in the minimizer falls below this amount. maxiter -- Maximum number of iterations to allow. full_output -- If non-zero return the optional outputs. disp -- If non-zero print convergence message. Remarks: Only one of fhess_p or fhess need be given. If fhess is provided, then fhess_p will be ignored. If neither fhess nor fhess_p is provided, then the hessian product will be approximated using finite differences on fprime. """ x0 = asarray(x0) fcalls = 0 gcalls = 0 hcalls = 0 if maxiter is None: maxiter = len(x0)*200 xtol = len(x0)*avextol update = [2*xtol] xk = x0 k = 0 old_fval = f(x0,*args) fcalls += 1 while (Num.add.reduce(abs(update)) > xtol) and (k < maxiter): # Compute a search direction pk by applying the CG method to # del2 f(xk) p = - grad f(xk) starting from 0. b = -apply(fprime,(xk,)+args) gcalls = gcalls + 1 maggrad = Num.add.reduce(abs(b)) eta = min([0.5,Num.sqrt(maggrad)]) termcond = eta * maggrad xsupi = 0 ri = -b psupi = -ri i = 0 dri0 = Num.dot(ri,ri) if fhess is not None: # you want to compute hessian once. A = apply(fhess,(xk,)+args) hcalls = hcalls + 1 while Num.add.reduce(abs(ri)) > termcond: if fhess is None: if fhess_p is None: Ap = apply(approx_fhess_p,(xk,psupi,fprime,espilon)+args) gcalls = gcalls + 2 else: Ap = apply(fhess_p,(xk,psupi)+args) hcalls = hcalls + 1 else: Ap = Num.dot(A,psupi) # check curvature curv = Num.dot(psupi,Ap) if (curv <= 0): if (i > 0): break else: xsupi = xsupi + dri0/curv * psupi break alphai = dri0 / curv xsupi = xsupi + alphai * psupi ri = ri + alphai * Ap dri1 = Num.dot(ri,ri) betai = dri1 / dri0 psupi = -ri + betai * psupi i = i + 1 dri0 = dri1 # update Num.dot(ri,ri) for next time. pk = xsupi # search direction is solution to system. gfk = -b # gradient at xk alphak, fc, gc, old_fval = line_search_BFGS(f,xk,pk,gfk,old_fval,args) fcalls = fcalls + fc gcalls = gcalls + gc update = alphak * pk xk = xk + update k = k + 1 if disp or full_output: fval = old_fval if k >= maxiter: warnflag = 1 if disp: print "Warning: Maximum number of iterations has been exceeded" print " Current function value: %f" % fval print " Iterations: %d" % k print " Function evaluations: %d" % fcalls print " Gradient evaluations: %d" % gcalls print " Hessian evaluations: %d" % hcalls else: warnflag = 0 if disp: print "Optimization terminated successfully." print " Current function value: %f" % fval print " Iterations: %d" % k print " Function evaluations: %d" % fcalls print " Gradient evaluations: %d" % gcalls print " Hessian evaluations: %d" % hcalls if full_output: return xk, fval, fcalls, gcalls, hcalls, warnflag else: return xk
e = 0.0
deltax= 0.0
def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500): """ Given a function of one-variable and a possible bracketing interval, return the minimum of the function isolated to a fractional precision of tol. A bracketing interval is a triple (a,b,c) where (a<b<c) and func(b) < func(a),func(c). If bracket is two numbers then they are assumed to be a starting interval for a downhill bracket search (see bracket) Uses inverse interpolation when possible to speed up convergence. """ _mintol = 1.0e-11 _cg = 0.3819660 if brack is None: xa,xb,xc,fa,fb,fc,funcalls = bracket(func, args=args) elif len(brack) == 2: xa,xb,xc,fa,fb,fc,funcalls = bracket(func, xa=brack[0], xb=brack[1], args=args) elif len(brack) == 3: xa,xb,xc = brack if (xa > xc): # swap so xa < xc can be assumed dum = xa; xa=xc; xc=dum assert ((xa < xb) and (xb < xc)), "Not a bracketing interval." fa = apply(func, (xa,)+args) fb = apply(func, (xb,)+args) fc = apply(func, (xc,)+args) assert ((fb<fa) and (fb < fc)), "Not a bracketing interval." funcalls = 3 else: raise ValuError, "Bracketing interval must be length 2 or 3 sequence." x=w=v=xb fw=fv=fx=apply(func, (x,)+args) if (xa < xc): a = xa; b = xc else: a = xc; b = xa e = 0.0 funcalls = 1 iter = 0 while (iter < maxiter): tol1 = tol*abs(x) + _mintol tol2 = 2.0*tol1 xmid = 0.5*(a+b) if abs(x-xmid) < (tol2-0.5*(b-a)): # check for convergence xmin=x; fval=fx break if (abs(e) <= tol1): # do a parabolic fit if (x>=xmid): e=a-x else: e=b-x d = _cg*e else: tmp1 = (x-w)*(fx-fv) tmp2 = (x-v)*(fx-fw) p = (x-v)*tmp2 - (x-w)*tmp1; tmp2 = 2.0*(tmp2-tmp1) if (tmp2 > 0.0): p = -p tmp2 = abs(tmp2) etemp = e e = d # check parabolic fit if ((p > tmp2*(a-x)) and (p < tmp2*(b-x)) and (abs(p) < abs(0.5*tmp2*etemp))): d = p*1.0/tmp2 # if it's good use it. u = x + d if ((u-a) < tol2 or (b-u) < tol2): if xmid-x >= 0: d = tol1 else: d = -tol1 else: if (x>=xmid): e=a-x # if it's bad do a golden section step else: e=b-x d = _cg*e if (abs(d) < tol1): if d >= 0: u = x + tol1 else: u = x - tol1 else: u = x + d fu = apply(func, (u,)+args) funcalls += 1 if (fu > fx): if (u<x): a=u else: b=u if (fu<=fw) or (w==x): v=w; w=u; fv=fw; fw=fu elif (fu<=fv) or (v==x) or (v==w): v=u; fv=fu else: if (u >= x): a = x else: b = x v=w; w=x; x=u fv=fw; fw=fx; fx=fu xmin = x fval = fx if full_output: return xmin, fval, iter, funcalls else: return xmin
if (abs(e) <= tol1): if (x>=xmid): e=a-x else: e=b-x d = _cg*e else:
if (abs(deltax) <= tol1): if (x>=xmid): deltax=a-x else: deltax=b-x rat = _cg*deltax else:
def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500): """ Given a function of one-variable and a possible bracketing interval, return the minimum of the function isolated to a fractional precision of tol. A bracketing interval is a triple (a,b,c) where (a<b<c) and func(b) < func(a),func(c). If bracket is two numbers then they are assumed to be a starting interval for a downhill bracket search (see bracket) Uses inverse interpolation when possible to speed up convergence. """ _mintol = 1.0e-11 _cg = 0.3819660 if brack is None: xa,xb,xc,fa,fb,fc,funcalls = bracket(func, args=args) elif len(brack) == 2: xa,xb,xc,fa,fb,fc,funcalls = bracket(func, xa=brack[0], xb=brack[1], args=args) elif len(brack) == 3: xa,xb,xc = brack if (xa > xc): # swap so xa < xc can be assumed dum = xa; xa=xc; xc=dum assert ((xa < xb) and (xb < xc)), "Not a bracketing interval." fa = apply(func, (xa,)+args) fb = apply(func, (xb,)+args) fc = apply(func, (xc,)+args) assert ((fb<fa) and (fb < fc)), "Not a bracketing interval." funcalls = 3 else: raise ValuError, "Bracketing interval must be length 2 or 3 sequence." x=w=v=xb fw=fv=fx=apply(func, (x,)+args) if (xa < xc): a = xa; b = xc else: a = xc; b = xa e = 0.0 funcalls = 1 iter = 0 while (iter < maxiter): tol1 = tol*abs(x) + _mintol tol2 = 2.0*tol1 xmid = 0.5*(a+b) if abs(x-xmid) < (tol2-0.5*(b-a)): # check for convergence xmin=x; fval=fx break if (abs(e) <= tol1): # do a parabolic fit if (x>=xmid): e=a-x else: e=b-x d = _cg*e else: tmp1 = (x-w)*(fx-fv) tmp2 = (x-v)*(fx-fw) p = (x-v)*tmp2 - (x-w)*tmp1; tmp2 = 2.0*(tmp2-tmp1) if (tmp2 > 0.0): p = -p tmp2 = abs(tmp2) etemp = e e = d # check parabolic fit if ((p > tmp2*(a-x)) and (p < tmp2*(b-x)) and (abs(p) < abs(0.5*tmp2*etemp))): d = p*1.0/tmp2 # if it's good use it. u = x + d if ((u-a) < tol2 or (b-u) < tol2): if xmid-x >= 0: d = tol1 else: d = -tol1 else: if (x>=xmid): e=a-x # if it's bad do a golden section step else: e=b-x d = _cg*e if (abs(d) < tol1): if d >= 0: u = x + tol1 else: u = x - tol1 else: u = x + d fu = apply(func, (u,)+args) funcalls += 1 if (fu > fx): if (u<x): a=u else: b=u if (fu<=fw) or (w==x): v=w; w=u; fv=fw; fw=fu elif (fu<=fv) or (v==x) or (v==w): v=u; fv=fu else: if (u >= x): a = x else: b = x v=w; w=x; x=u fv=fw; fw=fx; fx=fu xmin = x fval = fx if full_output: return xmin, fval, iter, funcalls else: return xmin
etemp = e e = d
dx_temp = deltax deltax= rat
def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500): """ Given a function of one-variable and a possible bracketing interval, return the minimum of the function isolated to a fractional precision of tol. A bracketing interval is a triple (a,b,c) where (a<b<c) and func(b) < func(a),func(c). If bracket is two numbers then they are assumed to be a starting interval for a downhill bracket search (see bracket) Uses inverse interpolation when possible to speed up convergence. """ _mintol = 1.0e-11 _cg = 0.3819660 if brack is None: xa,xb,xc,fa,fb,fc,funcalls = bracket(func, args=args) elif len(brack) == 2: xa,xb,xc,fa,fb,fc,funcalls = bracket(func, xa=brack[0], xb=brack[1], args=args) elif len(brack) == 3: xa,xb,xc = brack if (xa > xc): # swap so xa < xc can be assumed dum = xa; xa=xc; xc=dum assert ((xa < xb) and (xb < xc)), "Not a bracketing interval." fa = apply(func, (xa,)+args) fb = apply(func, (xb,)+args) fc = apply(func, (xc,)+args) assert ((fb<fa) and (fb < fc)), "Not a bracketing interval." funcalls = 3 else: raise ValuError, "Bracketing interval must be length 2 or 3 sequence." x=w=v=xb fw=fv=fx=apply(func, (x,)+args) if (xa < xc): a = xa; b = xc else: a = xc; b = xa e = 0.0 funcalls = 1 iter = 0 while (iter < maxiter): tol1 = tol*abs(x) + _mintol tol2 = 2.0*tol1 xmid = 0.5*(a+b) if abs(x-xmid) < (tol2-0.5*(b-a)): # check for convergence xmin=x; fval=fx break if (abs(e) <= tol1): # do a parabolic fit if (x>=xmid): e=a-x else: e=b-x d = _cg*e else: tmp1 = (x-w)*(fx-fv) tmp2 = (x-v)*(fx-fw) p = (x-v)*tmp2 - (x-w)*tmp1; tmp2 = 2.0*(tmp2-tmp1) if (tmp2 > 0.0): p = -p tmp2 = abs(tmp2) etemp = e e = d # check parabolic fit if ((p > tmp2*(a-x)) and (p < tmp2*(b-x)) and (abs(p) < abs(0.5*tmp2*etemp))): d = p*1.0/tmp2 # if it's good use it. u = x + d if ((u-a) < tol2 or (b-u) < tol2): if xmid-x >= 0: d = tol1 else: d = -tol1 else: if (x>=xmid): e=a-x # if it's bad do a golden section step else: e=b-x d = _cg*e if (abs(d) < tol1): if d >= 0: u = x + tol1 else: u = x - tol1 else: u = x + d fu = apply(func, (u,)+args) funcalls += 1 if (fu > fx): if (u<x): a=u else: b=u if (fu<=fw) or (w==x): v=w; w=u; fv=fw; fw=fu elif (fu<=fv) or (v==x) or (v==w): v=u; fv=fu else: if (u >= x): a = x else: b = x v=w; w=x; x=u fv=fw; fw=fx; fx=fu xmin = x fval = fx if full_output: return xmin, fval, iter, funcalls else: return xmin
if ((p > tmp2*(a-x)) and (p < tmp2*(b-x)) and (abs(p) < abs(0.5*tmp2*etemp))): d = p*1.0/tmp2 u = x + d
if ((p > tmp2*(a-x)) and (p < tmp2*(b-x)) and (abs(p) < abs(0.5*tmp2*dx_temp))): rat = p*1.0/tmp2 u = x + rat
def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500): """ Given a function of one-variable and a possible bracketing interval, return the minimum of the function isolated to a fractional precision of tol. A bracketing interval is a triple (a,b,c) where (a<b<c) and func(b) < func(a),func(c). If bracket is two numbers then they are assumed to be a starting interval for a downhill bracket search (see bracket) Uses inverse interpolation when possible to speed up convergence. """ _mintol = 1.0e-11 _cg = 0.3819660 if brack is None: xa,xb,xc,fa,fb,fc,funcalls = bracket(func, args=args) elif len(brack) == 2: xa,xb,xc,fa,fb,fc,funcalls = bracket(func, xa=brack[0], xb=brack[1], args=args) elif len(brack) == 3: xa,xb,xc = brack if (xa > xc): # swap so xa < xc can be assumed dum = xa; xa=xc; xc=dum assert ((xa < xb) and (xb < xc)), "Not a bracketing interval." fa = apply(func, (xa,)+args) fb = apply(func, (xb,)+args) fc = apply(func, (xc,)+args) assert ((fb<fa) and (fb < fc)), "Not a bracketing interval." funcalls = 3 else: raise ValuError, "Bracketing interval must be length 2 or 3 sequence." x=w=v=xb fw=fv=fx=apply(func, (x,)+args) if (xa < xc): a = xa; b = xc else: a = xc; b = xa e = 0.0 funcalls = 1 iter = 0 while (iter < maxiter): tol1 = tol*abs(x) + _mintol tol2 = 2.0*tol1 xmid = 0.5*(a+b) if abs(x-xmid) < (tol2-0.5*(b-a)): # check for convergence xmin=x; fval=fx break if (abs(e) <= tol1): # do a parabolic fit if (x>=xmid): e=a-x else: e=b-x d = _cg*e else: tmp1 = (x-w)*(fx-fv) tmp2 = (x-v)*(fx-fw) p = (x-v)*tmp2 - (x-w)*tmp1; tmp2 = 2.0*(tmp2-tmp1) if (tmp2 > 0.0): p = -p tmp2 = abs(tmp2) etemp = e e = d # check parabolic fit if ((p > tmp2*(a-x)) and (p < tmp2*(b-x)) and (abs(p) < abs(0.5*tmp2*etemp))): d = p*1.0/tmp2 # if it's good use it. u = x + d if ((u-a) < tol2 or (b-u) < tol2): if xmid-x >= 0: d = tol1 else: d = -tol1 else: if (x>=xmid): e=a-x # if it's bad do a golden section step else: e=b-x d = _cg*e if (abs(d) < tol1): if d >= 0: u = x + tol1 else: u = x - tol1 else: u = x + d fu = apply(func, (u,)+args) funcalls += 1 if (fu > fx): if (u<x): a=u else: b=u if (fu<=fw) or (w==x): v=w; w=u; fv=fw; fw=fu elif (fu<=fv) or (v==x) or (v==w): v=u; fv=fu else: if (u >= x): a = x else: b = x v=w; w=x; x=u fv=fw; fw=fx; fx=fu xmin = x fval = fx if full_output: return xmin, fval, iter, funcalls else: return xmin
if xmid-x >= 0: d = tol1 else: d = -tol1
if xmid-x >= 0: rat = tol1 else: rat = -tol1
def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500): """ Given a function of one-variable and a possible bracketing interval, return the minimum of the function isolated to a fractional precision of tol. A bracketing interval is a triple (a,b,c) where (a<b<c) and func(b) < func(a),func(c). If bracket is two numbers then they are assumed to be a starting interval for a downhill bracket search (see bracket) Uses inverse interpolation when possible to speed up convergence. """ _mintol = 1.0e-11 _cg = 0.3819660 if brack is None: xa,xb,xc,fa,fb,fc,funcalls = bracket(func, args=args) elif len(brack) == 2: xa,xb,xc,fa,fb,fc,funcalls = bracket(func, xa=brack[0], xb=brack[1], args=args) elif len(brack) == 3: xa,xb,xc = brack if (xa > xc): # swap so xa < xc can be assumed dum = xa; xa=xc; xc=dum assert ((xa < xb) and (xb < xc)), "Not a bracketing interval." fa = apply(func, (xa,)+args) fb = apply(func, (xb,)+args) fc = apply(func, (xc,)+args) assert ((fb<fa) and (fb < fc)), "Not a bracketing interval." funcalls = 3 else: raise ValuError, "Bracketing interval must be length 2 or 3 sequence." x=w=v=xb fw=fv=fx=apply(func, (x,)+args) if (xa < xc): a = xa; b = xc else: a = xc; b = xa e = 0.0 funcalls = 1 iter = 0 while (iter < maxiter): tol1 = tol*abs(x) + _mintol tol2 = 2.0*tol1 xmid = 0.5*(a+b) if abs(x-xmid) < (tol2-0.5*(b-a)): # check for convergence xmin=x; fval=fx break if (abs(e) <= tol1): # do a parabolic fit if (x>=xmid): e=a-x else: e=b-x d = _cg*e else: tmp1 = (x-w)*(fx-fv) tmp2 = (x-v)*(fx-fw) p = (x-v)*tmp2 - (x-w)*tmp1; tmp2 = 2.0*(tmp2-tmp1) if (tmp2 > 0.0): p = -p tmp2 = abs(tmp2) etemp = e e = d # check parabolic fit if ((p > tmp2*(a-x)) and (p < tmp2*(b-x)) and (abs(p) < abs(0.5*tmp2*etemp))): d = p*1.0/tmp2 # if it's good use it. u = x + d if ((u-a) < tol2 or (b-u) < tol2): if xmid-x >= 0: d = tol1 else: d = -tol1 else: if (x>=xmid): e=a-x # if it's bad do a golden section step else: e=b-x d = _cg*e if (abs(d) < tol1): if d >= 0: u = x + tol1 else: u = x - tol1 else: u = x + d fu = apply(func, (u,)+args) funcalls += 1 if (fu > fx): if (u<x): a=u else: b=u if (fu<=fw) or (w==x): v=w; w=u; fv=fw; fw=fu elif (fu<=fv) or (v==x) or (v==w): v=u; fv=fu else: if (u >= x): a = x else: b = x v=w; w=x; x=u fv=fw; fw=fx; fx=fu xmin = x fval = fx if full_output: return xmin, fval, iter, funcalls else: return xmin
if (x>=xmid): e=a-x else: e=b-x d = _cg*e if (abs(d) < tol1): if d >= 0: u = x + tol1
if (x>=xmid): deltax=a-x else: deltax=b-x rat = _cg*deltax if (abs(rat) < tol1): if rat >= 0: u = x + tol1
def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500): """ Given a function of one-variable and a possible bracketing interval, return the minimum of the function isolated to a fractional precision of tol. A bracketing interval is a triple (a,b,c) where (a<b<c) and func(b) < func(a),func(c). If bracket is two numbers then they are assumed to be a starting interval for a downhill bracket search (see bracket) Uses inverse interpolation when possible to speed up convergence. """ _mintol = 1.0e-11 _cg = 0.3819660 if brack is None: xa,xb,xc,fa,fb,fc,funcalls = bracket(func, args=args) elif len(brack) == 2: xa,xb,xc,fa,fb,fc,funcalls = bracket(func, xa=brack[0], xb=brack[1], args=args) elif len(brack) == 3: xa,xb,xc = brack if (xa > xc): # swap so xa < xc can be assumed dum = xa; xa=xc; xc=dum assert ((xa < xb) and (xb < xc)), "Not a bracketing interval." fa = apply(func, (xa,)+args) fb = apply(func, (xb,)+args) fc = apply(func, (xc,)+args) assert ((fb<fa) and (fb < fc)), "Not a bracketing interval." funcalls = 3 else: raise ValuError, "Bracketing interval must be length 2 or 3 sequence." x=w=v=xb fw=fv=fx=apply(func, (x,)+args) if (xa < xc): a = xa; b = xc else: a = xc; b = xa e = 0.0 funcalls = 1 iter = 0 while (iter < maxiter): tol1 = tol*abs(x) + _mintol tol2 = 2.0*tol1 xmid = 0.5*(a+b) if abs(x-xmid) < (tol2-0.5*(b-a)): # check for convergence xmin=x; fval=fx break if (abs(e) <= tol1): # do a parabolic fit if (x>=xmid): e=a-x else: e=b-x d = _cg*e else: tmp1 = (x-w)*(fx-fv) tmp2 = (x-v)*(fx-fw) p = (x-v)*tmp2 - (x-w)*tmp1; tmp2 = 2.0*(tmp2-tmp1) if (tmp2 > 0.0): p = -p tmp2 = abs(tmp2) etemp = e e = d # check parabolic fit if ((p > tmp2*(a-x)) and (p < tmp2*(b-x)) and (abs(p) < abs(0.5*tmp2*etemp))): d = p*1.0/tmp2 # if it's good use it. u = x + d if ((u-a) < tol2 or (b-u) < tol2): if xmid-x >= 0: d = tol1 else: d = -tol1 else: if (x>=xmid): e=a-x # if it's bad do a golden section step else: e=b-x d = _cg*e if (abs(d) < tol1): if d >= 0: u = x + tol1 else: u = x - tol1 else: u = x + d fu = apply(func, (u,)+args) funcalls += 1 if (fu > fx): if (u<x): a=u else: b=u if (fu<=fw) or (w==x): v=w; w=u; fv=fw; fw=fu elif (fu<=fv) or (v==x) or (v==w): v=u; fv=fu else: if (u >= x): a = x else: b = x v=w; w=x; x=u fv=fw; fw=fx; fx=fu xmin = x fval = fx if full_output: return xmin, fval, iter, funcalls else: return xmin
u = x + d fu = apply(func, (u,)+args)
u = x + rat fu = apply(func, (u,)+args)
def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500): """ Given a function of one-variable and a possible bracketing interval, return the minimum of the function isolated to a fractional precision of tol. A bracketing interval is a triple (a,b,c) where (a<b<c) and func(b) < func(a),func(c). If bracket is two numbers then they are assumed to be a starting interval for a downhill bracket search (see bracket) Uses inverse interpolation when possible to speed up convergence. """ _mintol = 1.0e-11 _cg = 0.3819660 if brack is None: xa,xb,xc,fa,fb,fc,funcalls = bracket(func, args=args) elif len(brack) == 2: xa,xb,xc,fa,fb,fc,funcalls = bracket(func, xa=brack[0], xb=brack[1], args=args) elif len(brack) == 3: xa,xb,xc = brack if (xa > xc): # swap so xa < xc can be assumed dum = xa; xa=xc; xc=dum assert ((xa < xb) and (xb < xc)), "Not a bracketing interval." fa = apply(func, (xa,)+args) fb = apply(func, (xb,)+args) fc = apply(func, (xc,)+args) assert ((fb<fa) and (fb < fc)), "Not a bracketing interval." funcalls = 3 else: raise ValuError, "Bracketing interval must be length 2 or 3 sequence." x=w=v=xb fw=fv=fx=apply(func, (x,)+args) if (xa < xc): a = xa; b = xc else: a = xc; b = xa e = 0.0 funcalls = 1 iter = 0 while (iter < maxiter): tol1 = tol*abs(x) + _mintol tol2 = 2.0*tol1 xmid = 0.5*(a+b) if abs(x-xmid) < (tol2-0.5*(b-a)): # check for convergence xmin=x; fval=fx break if (abs(e) <= tol1): # do a parabolic fit if (x>=xmid): e=a-x else: e=b-x d = _cg*e else: tmp1 = (x-w)*(fx-fv) tmp2 = (x-v)*(fx-fw) p = (x-v)*tmp2 - (x-w)*tmp1; tmp2 = 2.0*(tmp2-tmp1) if (tmp2 > 0.0): p = -p tmp2 = abs(tmp2) etemp = e e = d # check parabolic fit if ((p > tmp2*(a-x)) and (p < tmp2*(b-x)) and (abs(p) < abs(0.5*tmp2*etemp))): d = p*1.0/tmp2 # if it's good use it. u = x + d if ((u-a) < tol2 or (b-u) < tol2): if xmid-x >= 0: d = tol1 else: d = -tol1 else: if (x>=xmid): e=a-x # if it's bad do a golden section step else: e=b-x d = _cg*e if (abs(d) < tol1): if d >= 0: u = x + tol1 else: u = x - tol1 else: u = x + d fu = apply(func, (u,)+args) funcalls += 1 if (fu > fx): if (u<x): a=u else: b=u if (fu<=fw) or (w==x): v=w; w=u; fv=fw; fw=fu elif (fu<=fv) or (v==x) or (v==w): v=u; fv=fu else: if (u >= x): a = x else: b = x v=w; w=x; x=u fv=fw; fw=fx; fx=fu xmin = x fval = fx if full_output: return xmin, fval, iter, funcalls else: return xmin
if data.dtype.char == 'f' and data2.dtype.char == 'f': new = zeros(data.shape,'F') new.real = data new.imag = data2 data = new del(new) del(data2)
new = zeros(data.shape,data.dtype.char.capitalize()) new.real = data new.imag = data2 data = new del(new) del(data2)
def loadmat(name, dict=None, appendmat=1, basename='raw'): """Load the MATLAB(tm) mat file. If name is a full path name load it in. Otherwise search for the file on the sys.path list and load the first one found (the current directory is searched first). Both v4 (Level 1.0) and v6 matfiles are supported. Version 7.0 files are not yet supported. Inputs: name -- name of the mat file (don't need .mat extension if appendmat=1) dict -- the dictionary to insert into. If none the variables will be returned in a dictionary. appendmat -- non-zero to append the .mat extension to the end of the given filename. basename -- for MATLAB(tm) v5 matfiles raw data will have this basename. Outputs: If dict is None, then a dictionary of names and objects representing the stored arrays is returned. """ if appendmat and name[-4:] == ".mat": name = name[:-4] if os.sep in name: full_name = name if appendmat: full_name = name + ".mat" else: full_name = None junk,name = os.path.split(name) for path in sys.path: test_name = os.path.join(path,name) if appendmat: test_name += ".mat" try: fid = open(test_name,'rb') fid.close() full_name = test_name break except IOError: pass if full_name is None: raise IOError, "%s not found on the path." % name fid = fopen(full_name,'rb') test_vals = fid.fread(4,'byte') if not (0 in test_vals): # MATLAB version 5 format fid.rewind() thisdict = _loadv5(fid,basename) if dict is not None: dict.update(thisdict) return else: return thisdict testtype = struct.unpack('i',test_vals.tostring()) # Check to see if the number is positive and less than 5000. if testtype[0] < 0 or testtype[0] > 4999: # wrong byte-order if LittleEndian: format = 'ieee-be' else: format = 'ieee-le' else: # otherwise we are O.K. if LittleEndian: format = 'ieee-le' else: format = 'ieee-be' fid.setformat(format) length = fid.size() fid.rewind() # back to the begining defnames = [] thisdict = {} while 1: if (fid.tell() == length): break header = fid.fread(5,'int') if len(header) != 5: fid.close() print "Warning: Read error in file." break M,rest = divmod(header[0],1000) O,rest = divmod(rest,100) P,rest = divmod(rest,10) T = rest if (M > 1): fid.close() raise ValueError, "Unsupported binary format." if (O != 0): fid.close() raise ValuError, "Hundreds digit of first integer should be zero." if (T not in [0,1]): fid.close() raise ValueError, "Cannot handle sparse matrices, yet." storage = {0:'d',1:'f',2:'i',3:'h',4:'H',5:'B'}[P] varname = fid.fread(header[-1],'char')[:-1] varname = varname.tostring() defnames.append(varname) numels = header[1]*header[2] if T == 0: # Text data data = atleast_1d(fid.fread(numels,storage)) if header[3]: # imaginary data data2 = fid.fread(numels,storage) if data.dtype.char == 'f' and data2.dtype.char == 'f': new = zeros(data.shape,'F') new.real = data new.imag = data2 data = new del(new) del(data2) if len(data) > 1: data=data.reshape((header[2], header[1]) ) thisdict[varname] = transpose(squeeze(data)) else: thisdict[varname] = data else: data = atleast_1d(fid.fread(numels,storage,'char')) if len(data) > 1: data=data.reshape((header[2], header[1])) thisdict[varname] = transpose(squeeze(data)) else: thisdict[varname] = data fid.close() if dict is not None: print "Names defined = ", defnames dict.update(thisdict) else: return thisdict
def is_numeric_array(x): try: x.typecode() in ['c','b','l','d','f','D','F'] return 1 except AttributeError: pass return 0
def is_immutable(x): """ Checks if object is completely immutable. A tuple is not considered completely immutable since it could contain references to objects that could change. Returns 1 if it is immutable or 0 if object is mutable.""" imm = () try: imm = (types.StringType, types.FloatType, types.IntType, types.ComplexType, types.NoneType, types.UnicodeType) except AttributeError: imm = (types.StringType, types.FloatType, types.IntType, types.ComplexType, type.NoneType) if type(x) in imm: return 1 else: return 0
exec exec_code
exec exec_code in globals, globals
def exec_code(code,inputs,returns,global_vars,addendum=None): if addendum: inputs.update(addendum) if not returns: returns = () if type(returns) == type(''): raise TypeError, 'returns must be a sequence object - not a string' exec_code = build_globals(global_vars) exec_code = exec_code + build_inputs(inputs) exec_code = exec_code + code exec exec_code #perhaps do something here to catch errors if len(returns) == 1: results = eval(returns[0]) elif len(returns) > 1: results = [] for i in returns: results.append(eval(i)) results = tuple(results) else: results = None return results
exec exec_code
exec exec_code in globals, globals
def loop_code(code,loop_var,inputs,returns,global_vars,addendum=None): if type(returns) == type(''): raise TypeError, 'returns must be a sequence object - not a string' if addendum: inputs.update(addendum) _loop_data = inputs[loop_var] del inputs[loop_var] #not strictly necessary exec_code = build_loop_code(code,loop_var,inputs,returns,global_vars) exec exec_code return _all_results
m,n (m<=n) and argument theta and phi: Y^m_n(theta,phi)
m,n (|m|<=n) and argument theta and phi: Y^m_n(theta,phi)
def _sph_harmonic(m,n,theta,phi): """inputs of (m,n,theta,phi) returns spherical harmonic of order m,n (m<=n) and argument theta and phi: Y^m_n(theta,phi) """ x = cos(phi) m,n = int(m), int(n) Pmn,Pmnd = lpmn(m,n,x) val = Pmn[m,n] val *= sqrt((2*m+1)/4.0/pi) val *= exp(0.5*gammaln(n-m+1)-gammaln(n+m+1)) val *= exp(1j*m*theta) return val
val *= sqrt((2*m+1)/4.0/pi)
val *= sqrt((2*n+1)/4.0/pi)
def _sph_harmonic(m,n,theta,phi): """inputs of (m,n,theta,phi) returns spherical harmonic of order m,n (m<=n) and argument theta and phi: Y^m_n(theta,phi) """ x = cos(phi) m,n = int(m), int(n) Pmn,Pmnd = lpmn(m,n,x) val = Pmn[m,n] val *= sqrt((2*m+1)/4.0/pi) val *= exp(0.5*gammaln(n-m+1)-gammaln(n+m+1)) val *= exp(1j*m*theta) return val
sources = ['cobyla.pyf','cobyla2.f']
sources = ['cobyla.pyf','cobyla2.f','trstlp.f']
def configuration(parent_package='',parent_path=None): package = 'optimize' config = default_config_dict(package, parent_package) local_path = get_path(__name__,parent_path) minpack = ('minpack',{'sources': glob(os.path.join(local_path,'minpack','*.f'))}) sources = ['_minpackmodule.c'] sources = [os.path.join(local_path,x) for x in sources] ext = Extension(dot_join(parent_package, package, '_minpack'), sources, libraries = [minpack]) config['ext_modules'].append(ext) rootfind = glob(os.path.join(local_path,'Zeros','*.c')) roothead = os.path.join(local_path,'zeros.h') config['libraries'].append(('rootfind',{'sources':rootfind, 'headers':roothead})) sources = ['zeros.c'] sources = [os.path.join(local_path,x) for x in sources] ext = Extension(dot_join(parent_package, package, '_zeros'), sources, libraries=['rootfind']) config['ext_modules'].append(ext) lapack = system_info.lapack_opt_info().get_info() sources = ['lbfgsb.pyf','routines.f'] sources = [os.path.join(local_path,'lbfgsb-0.9',x) for x in sources] ext = Extension(dot_join(parent_package, package, "_lbfgsb"), sources=sources, **lapack) config['ext_modules'].append(ext) sources = ['moduleTNC.c', 'tnc.c'] sources = [os.path.join(local_path,'tnc',x) for x in sources] ext = Extension(dot_join(parent_package, package, 'moduleTNC'), sources=sources) config['ext_modules'].append(ext) sources = ['cobyla.pyf','cobyla2.f'] sources = [os.path.join(local_path,'cobyla',x) for x in sources] ext = Extension(dot_join(parent_package, package, '_cobyla'), sources=sources) config['ext_modules'].append(ext) sources = ['minpack2.pyf', 'dcsrch.f', 'dcstep.f'] sources = [os.path.join(local_path,'minpack2',x) for x in sources] ext = Extension(dot_join(parent_package, package, 'minpack2'), sources=sources) config['ext_modules'].append(ext) return config
def day(self): return self.getDate().day def day_of_week(self): return self.getDate().day_of_week def month(self): return self.getDate().month def quarter(self): return monthToQuarter(self.getDate().month) def year(self): return self.getDate().year def seconds(self): return int(self.getDate().second) def minute(self): return int(self.getDate().minute) def hour(self): return int(self.getDate().hour)
def day(self): return self.mxDate().day def day_of_week(self): return self.mxDate().day_of_week def month(self): return self.mxDate().month def quarter(self): return monthToQuarter(self.mxDate().month) def year(self): return self.mxDate().year def seconds(self): return int(self.mxDate().second) def minute(self): return int(self.mxDate().minute) def hour(self): return int(self.mxDate().hour)
def day(self): return self.getDate().day
def get_eig_func(): try: import scipy.linalg eig = scipy.linalg.eig except ImportError: try: import linalg eig = linalg.eig except ImportError: try: import LinearAlgebra eig = LinearAlgebra.eigenvectors except: raise ImportError, \ "You must have scipy.linalg or LinearAlgebra to "\ "use this function." return eig
def __init__(self, roots, weights=None, hn=1.0, An=1.0, wfunc=None, limits=None, monic=0): poly1d.__init__(self, roots, r=1)
from scipy.linalg import eig
eig = get_eig_func()
def gen_roots_and_weights(n,an_func,sqrt_bn_func,mu): """[x,w] = gen_roots_and_weights(n,an_func,sqrt_bn_func,mu) Returns the roots (x) of an nth order orthogonal polynomail, and weights (w) to use in appropriate Gaussian quadrature with that orthogonal polynomial. The polynomials have the recurrence relation P_n+1(x) = (x - A_n) P_n(x) - B_n P_n-1(x) an_func(n) should return A_n sqrt_bn_func(n) should return sqrt(B_n) mu ( = h_0 ) is the integral of the weight over the orthogonal interval """ # XXX: shouldn't import linalg inside a function from scipy.linalg import eig nn = arange(1.0,n) sqrt_bn = sqrt_bn_func(nn) an = an_func(concatenate(([0],nn))) [x,v] = eig((diag(an)+diag(sqrt_bn,1)+diag(sqrt_bn,-1))) answer = [] sortind = argsort(real(x)) answer.append(take(x,sortind)) answer.append(take(mu*v[0]**2,sortind)) return answer
lena = scipy.array(cPickle.load(f))
lena = array(cPickle.load(f))
def lena(): import cPickle, os fname = os.path.join(os.path.dirname(__file__),'plt','lena.dat') f = open(fname,'rb') lena = scipy.array(cPickle.load(f)) f.close() return lena
g = Numeric.array([[5,6,4,3],[3,5,6,2],[2,3,5,6],[1,6,9,7]],'d') correct = Numeric.array([[2.16374269,3.2222222222, 2.8888888889, 1.6666666667],[2.666666667, 4.33333333333, 4.44444444444, 2.8888888888],[2.222222222, 4.4444444444, 5.4444444444, 4.801066874837],[1.33333333333, 3.92735042735, 6.0712560386, 5.0404040404]]) h = wiener(g)
g = array([[5,6,4,3],[3,5,6,2],[2,3,5,6],[1,6,9,7]],'d') correct = array([[2.16374269,3.2222222222, 2.8888888889, 1.6666666667],[2.666666667, 4.33333333333, 4.44444444444, 2.8888888888],[2.222222222, 4.4444444444, 5.4444444444, 4.801066874837],[1.33333333333, 3.92735042735, 6.0712560386, 5.0404040404]]) h = signal.wiener(g)
def check_basic(self): g = Numeric.array([[5,6,4,3],[3,5,6,2],[2,3,5,6],[1,6,9,7]],'d') correct = Numeric.array([[2.16374269,3.2222222222, 2.8888888889, 1.6666666667],[2.666666667, 4.33333333333, 4.44444444444, 2.8888888888],[2.222222222, 4.4444444444, 5.4444444444, 4.801066874837],[1.33333333333, 3.92735042735, 6.0712560386, 5.0404040404]]) h = wiener(g) assert_array_almost_equal(h,correct,decimal=6)
artype = b.typecode() if artype not in ['F','D','f','d']: artype = Num.Float
artype = mintypecode((a,b))
def lp2bp(b,a,wo=1.0, bw=1.0): """Return a band-pass filter with center frequency wo and bandwidth bw from a low-pass filter prototype with unity cutoff frequency. """ a,b = map(atleast_1d,(a,b)) D = len(a) - 1 N = len(b) - 1 artype = b.typecode() if artype not in ['F','D','f','d']: artype = Num.Float ma = max([N,D]) Np = N + ma Dp = D + ma bprime = Num.zeros(Np+1,artype) aprime = Num.zeros(Dp+1,artype) wosq = wo*wo for j in range(Np+1): val = 0.0 for i in range(0,N+1): for k in range(0,i+1): if ma-i+2*k == j: val += comb(i,k)*b[N-i]*(wosq)**(i-k) / bw**i bprime[Np-j] = val for j in range(Dp+1): val = 0.0 for i in range(0,D+1): for k in range(0,i+1): if ma-i+2*k == j: val += comb(i,k)*a[D-i]*(wosq)**(i-k) / bw**i aprime[Dp-j] = val return normalize(bprime, aprime)
artype = b.typecode() if artype not in ['F','D','f','d']: artype = Num.Float
artype = mintypecode((a,b))
def lp2bs(b,a,wo=1,bw=1): """Return a band-stop filter with center frequency wo and bandwidth bw from a low-pass filter prototype with unity cutoff frequency. """ a,b = map(atleast_1d,(a,b)) D = len(a) - 1 N = len(b) - 1 artype = b.typecode() if artype not in ['F','D','f','d']: artype = Num.Float M = max([N,D]) Np = M + M Dp = M + M bprime = Num.zeros(Np+1,artype) aprime = Num.zeros(Dp+1,artype) wosq = wo*wo for j in range(Np+1): val = 0.0 for i in range(0,N+1): for k in range(0,M-i+1): if i+2*k == j: val += comb(M-i,k)*b[N-i]*(wosq)**(M-i-k) * bw**i bprime[Np-j] = val for j in range(Dp+1): val = 0.0 for i in range(0,D+1): for k in range(0,M-i+1): if i+2*k == j: val += comb(M-i,k)*a[D-i]*(wosq)**(M-i-k) * bw**i aprime[Dp-j] = val return normalize(bprime, aprime)
nnz = sum(ravel(s != 0.0))
nnz = (s != 0.0).sum()
def __init__(self, arg1, dims=None, nzmax=100, dtype=None, copy=False): spmatrix.__init__(self) if isdense(arg1): self.dtype = getdtype(dtype, arg1) # Convert the dense array or matrix arg1 to CSC format if rank(arg1) == 1: # Convert to a row vector arg1 = arg1.reshape(1, arg1.shape[0]) if rank(arg1) == 2: #s = asarray(arg1) s = arg1 if s.dtype.char not in 'fdFD': # Use a double array as the source (but leave it alone) s = s*1.0 if (rank(s) == 2): M, N = s.shape dtype = s.dtype func = getattr(sparsetools, _transtabl[dtype.char]+'fulltocsc') ierr = irow = jcol = 0 nnz = sum(ravel(s != 0.0)) a = zeros((nnz,), self.dtype) rowa = zeros((nnz,), intc) ptra = zeros((N+1,), intc) while 1: a, rowa, ptra, irow, jcol, ierr = \ func(s, a, rowa, ptra, irow, jcol, ierr) if (ierr == 0): break nnz = nnz + ALLOCSIZE a = resize1d(a, nnz) rowa = resize1d(rowa, nnz) self.data = a self.rowind = rowa self.indptr = ptra self.shape = (M, N) else: raise ValueError, "dense array must have rank 1 or 2" elif isspmatrix(arg1): s = arg1 self.dtype = getdtype(dtype, s) if isinstance(s, csc_matrix): # do nothing but copy information self.shape = s.shape if copy: self.data = s.data.copy() self.rowind = s.rowind.copy() self.indptr = s.indptr.copy() else: self.data = s.data self.rowind = s.rowind self.indptr = s.indptr elif isinstance(s, csr_matrix): self.shape = s.shape func = getattr(sparsetools, s.ftype+'transp') self.data, self.rowind, self.indptr = \ func(s.shape[1], s.data, s.colind, s.indptr) else: temp = s.tocsc() self.data = temp.data self.rowind = temp.rowind self.indptr = temp.indptr self.shape = temp.shape elif type(arg1) == tuple: if isshape(arg1): self.dtype = getdtype(dtype, default=float) # It's a tuple of matrix dimensions (M, N) M, N = arg1 self.data = zeros((nzmax,), self.dtype) self.rowind = zeros((nzmax,), intc) self.indptr = zeros((N+1,), intc) self.shape = (M, N) else: try: # Try interpreting it as (data, ij) (s, ij) = arg1 assert isinstance(ij, ArrayType) and (rank(ij) == 2) and (shape(ij) == (len(s), 2)) except (AssertionError, TypeError, ValueError): try: # Try interpreting it as (data, rowind, indptr) (s, rowind, indptr) = arg1 self.dtype = getdtype(dtype, s) if copy: self.data = array(s) self.rowind = array(rowind) self.indptr = array(indptr) else: self.data = asarray(s) self.rowind = asarray(rowind) self.indptr = asarray(indptr) except: raise ValueError, "unrecognized form for csc_matrix constructor" else: # (data, ij) format self.dtype = getdtype(dtype, s) temp = coo_matrix((s, ij), dims=dims, dtype=dtype).tocsc() self.shape = temp.shape self.data = temp.data self.rowind = temp.rowind self.indptr = temp.indptr else: raise ValueError, "unrecognized form for csc_matrix constructor"
percent_to_go = 1- (1.0*kcol) / N
print "Resizing...", kcol, irow, ierr percent_to_go = 1- (1.0*kcol*M + irow) / (N*M)
def matmat(self, other): if isspmatrix(other): M, K1 = self.shape K2, N = other.shape if (K1 != K2): raise ValueError, "shape mismatch error" a, rowa, ptra = self.data, self.rowind, self.indptr if isinstance(other, csr_matrix): other._check() dtypechar = _coerce_rules[(self.dtype.char, other.dtype.char)] ftype = _transtabl[dtypechar] func = getattr(sparsetools, ftype+'cscmucsr') b = other.data rowb = other.colind ptrb = other.indptr elif isinstance(other, csc_matrix): other._check() dtypechar = _coerce_rules[(self.dtype.char, other.dtype.char)] ftype = _transtabl[dtypechar] func = getattr(sparsetools, ftype+'cscmucsc') b = other.data rowb = other.rowind ptrb = other.indptr else: other = other.tocsc() dtypechar = _coerce_rules[(self.dtype.char, other.dtype.char)] ftype = _transtabl[dtypechar] func = getattr(sparsetools, ftype+'cscmucsc') b = other.data rowb = other.rowind ptrb = other.indptr a, b = _convert_data(a, b, dtypechar) newshape = (M, N) ptrc = zeros((N+1,), intc) nnzc = 2*max(ptra[-1], ptrb[-1]) c = zeros((nnzc,), dtypechar) rowc = zeros((nnzc,), intc) ierr = irow = kcol = 0 while True: c, rowc, ptrc, irow, kcol, ierr = func(M, a, rowa, ptra, b, rowb, ptrb, c, rowc, ptrc, irow, kcol, ierr) if (ierr==0): break # otherwise we were too small and must resize # calculations continue where they left off... percent_to_go = 1- (1.0*kcol) / N newnnzc = int(ceil((1+percent_to_go)*nnzc)) c = resize1d(c, newnnzc) rowc = resize1d(rowc, newnnzc) nnzc = newnnzc return csc_matrix((c, rowc, ptrc), dims=(M, N)) elif isdense(other): # This is SLOW! We need a more efficient implementation # of sparse * dense matrix multiplication! return self.matmat(csc_matrix(other)) else: raise TypeError, "need a dense or sparse matrix"
if amax(ravel(abs(new.imag))) == 0:
if abs(new.imag).max() == 0:
def toarray(self): new = zeros(self.shape, dtype=self.dtype) for key in self: ikey0 = int(key[0]) ikey1 = int(key[1]) new[ikey0, ikey1] = self[key] if amax(ravel(abs(new.imag))) == 0: new = new.real return new
slice1 = [slice(None)]*nd slice2 = [slice(None)]*nd slice1[axis] = slice(1,None) slice2[axis] = slice(None,-1)
slice1 = tupleset((slice(None),)*nd, axis, slice(1, None)) slice2 = tupleset((slice(None),)*nd, axis, slice(None, -1))
def cumtrapz(y, x=None, dx=1.0, axis=-1): """Cumulatively integrate y(x) using samples along the given axis and the composite trapezoidal rule. If x is None, spacing given by dx is assumed. """ y = asarray(y) if x is None: d = dx else: d = diff(x,axis=axis) nd = len(y.shape) slice1 = [slice(None)]*nd slice2 = [slice(None)]*nd slice1[axis] = slice(1,None) slice2[axis] = slice(None,-1) return add.accumulate(d * (y[slice1]+y[slice2])/2.0,axis)
slice0 = [slice(None)]*nd slice1 = [slice(None)]*nd slice2 = [slice(None)]*nd
def _basic_simps(y,start,stop,x,dx,axis): nd = len(y.shape) slice0 = [slice(None)]*nd slice1 = [slice(None)]*nd slice2 = [slice(None)]*nd if start is None: start = 0 step = 2 slice0[axis] = slice(start,stop,step) slice1[axis] = slice(start+1,stop+1,step) slice2[axis] = slice(start+2,stop+2,step) if x is None: # Even spaced Simpson's rule. result = add.reduce(dx/3.0* (y[slice0]+4*y[slice1]+y[slice2]), axis) else: # Account for possibly different spacings. # Simpson's rule changes a bit. h = diff(x,axis=axis) sl0 = [slice(None)]*nd sl1 = [slice(None)]*nd sl0[axis] = slice(start,stop,step) sl1[axis] = slice(start+1,stop+1,step) h0 = h[sl0] h1 = h[sl1] hsum = h0 + h1 hprod = h0 * h1 h0divh1 = h0 / h1 result = add.reduce(hsum/6.0*(y[slice0]*(2-1.0/h0divh1) + \ y[slice1]*hsum*hsum/hprod + \ y[slice2]*(2-h0divh1)),axis) return result
slice0[axis] = slice(start,stop,step) slice1[axis] = slice(start+1,stop+1,step) slice2[axis] = slice(start+2,stop+2,step)
all = (slice(None),)*nd slice0 = tupleset(all, axis, slice(start, stop, step)) slice1 = tupleset(all, axis, slice(start+1, stop+1, step)) slice2 = tupleset(all, axis, slice(start+2, stop+2, step))
def _basic_simps(y,start,stop,x,dx,axis): nd = len(y.shape) slice0 = [slice(None)]*nd slice1 = [slice(None)]*nd slice2 = [slice(None)]*nd if start is None: start = 0 step = 2 slice0[axis] = slice(start,stop,step) slice1[axis] = slice(start+1,stop+1,step) slice2[axis] = slice(start+2,stop+2,step) if x is None: # Even spaced Simpson's rule. result = add.reduce(dx/3.0* (y[slice0]+4*y[slice1]+y[slice2]), axis) else: # Account for possibly different spacings. # Simpson's rule changes a bit. h = diff(x,axis=axis) sl0 = [slice(None)]*nd sl1 = [slice(None)]*nd sl0[axis] = slice(start,stop,step) sl1[axis] = slice(start+1,stop+1,step) h0 = h[sl0] h1 = h[sl1] hsum = h0 + h1 hprod = h0 * h1 h0divh1 = h0 / h1 result = add.reduce(hsum/6.0*(y[slice0]*(2-1.0/h0divh1) + \ y[slice1]*hsum*hsum/hprod + \ y[slice2]*(2-h0divh1)),axis) return result
sl0 = [slice(None)]*nd sl1 = [slice(None)]*nd sl0[axis] = slice(start,stop,step) sl1[axis] = slice(start+1,stop+1,step)
sl0 = tupleset(all, axis, slice(start, stop, step)) sl1 = tupleset(all, axis, slice(start+1, stop+1, step))
def _basic_simps(y,start,stop,x,dx,axis): nd = len(y.shape) slice0 = [slice(None)]*nd slice1 = [slice(None)]*nd slice2 = [slice(None)]*nd if start is None: start = 0 step = 2 slice0[axis] = slice(start,stop,step) slice1[axis] = slice(start+1,stop+1,step) slice2[axis] = slice(start+2,stop+2,step) if x is None: # Even spaced Simpson's rule. result = add.reduce(dx/3.0* (y[slice0]+4*y[slice1]+y[slice2]), axis) else: # Account for possibly different spacings. # Simpson's rule changes a bit. h = diff(x,axis=axis) sl0 = [slice(None)]*nd sl1 = [slice(None)]*nd sl0[axis] = slice(start,stop,step) sl1[axis] = slice(start+1,stop+1,step) h0 = h[sl0] h1 = h[sl1] hsum = h0 + h1 hprod = h0 * h1 h0divh1 = h0 / h1 result = add.reduce(hsum/6.0*(y[slice0]*(2-1.0/h0divh1) + \ y[slice1]*hsum*hsum/hprod + \ y[slice2]*(2-h0divh1)),axis) return result
slice1 = [slice(None)]*nd slice2 = [slice(None)]*nd
slice1 = (slice(None),)*nd slice2 = (slice(None),)*nd
def simps(y, x=None, dx=1, axis=-1, even='avg'): """Integrate y(x) using samples along the given axis and the composite Simpson's rule. If x is None, spacing of dx is assumed. If there are an even number of samples, N, then there are an odd number of intervals (N-1), but Simpson's rule requires an even number of intervals. The parameter 'even' controls how this is handled as follows: even='avg': Average two results: 1) use the first N-2 intervals with a trapezoidal rule on the last interval and 2) use the last N-2 intervals with a trapezoidal rule on the first interval even='first': Use Simpson's rule for the first N-2 intervals with a trapezoidal rule on the last interval. even='last': Use Simpson's rule for the last N-2 intervals with a trapezoidal rule on the first interval. For an odd number of samples that are equally spaced the result is exact if the function is a polynomial of order 3 or less. If the samples are not equally spaced, then the result is exact only if the function is a polynomial of order 2 or less. """ y = asarray(y) nd = len(y.shape) N = y.shape[axis] last_dx = dx first_dx = dx returnshape = 0 if not x is None: x = asarray(x) if len(x.shape) == 1: shapex = ones(nd) shapex[axis] = x.shape[0] saveshape = x.shape returnshape = 1 x=x.reshape(tuple(shapex)) elif len(x.shape) != len(y.shape): raise ValueError, "If given, shape of x must be 1-d or the " \ "same as y." if x.shape[axis] != N: raise ValueError, "If given, length of x along axis must be the " \ "same as y." if N % 2 == 0: val = 0.0 result = 0.0 slice1 = [slice(None)]*nd slice2 = [slice(None)]*nd if not even in ['avg', 'last', 'first']: raise ValueError, \ "Parameter 'even' must be 'avg', 'last', or 'first'." # Compute using Simpson's rule on first intervals if even in ['avg', 'first']: slice1[axis] = -1 slice2[axis] = -2 if not x is None: last_dx = x[slice1] - x[slice2] val += 0.5*last_dx*(y[slice1]+y[slice2]) result = _basic_simps(y,0,N-3,x,dx,axis) # Compute using Simpson's rule on last set of intervals if even in ['avg', 'last']: slice1[axis] = 0 slice2[axis] = 1 if not x is None: first_dx = x[slice2] - x[slice1] val += 0.5*first_dx*(y[slice2]+y[slice1]) result += _basic_simps(y,1,N-2,x,dx,axis) if even == 'avg': val /= 2.0 result /= 2.0 result = result + val else: result = _basic_simps(y,0,N-2,x,dx,axis) if returnshape: x = x.reshape(saveshape) return result
slice1[axis] = -1 slice2[axis] = -2
slice1 = tupleset(slice1, axis, -1) slice2 = tupleset(slice2, axis, -2)
def simps(y, x=None, dx=1, axis=-1, even='avg'): """Integrate y(x) using samples along the given axis and the composite Simpson's rule. If x is None, spacing of dx is assumed. If there are an even number of samples, N, then there are an odd number of intervals (N-1), but Simpson's rule requires an even number of intervals. The parameter 'even' controls how this is handled as follows: even='avg': Average two results: 1) use the first N-2 intervals with a trapezoidal rule on the last interval and 2) use the last N-2 intervals with a trapezoidal rule on the first interval even='first': Use Simpson's rule for the first N-2 intervals with a trapezoidal rule on the last interval. even='last': Use Simpson's rule for the last N-2 intervals with a trapezoidal rule on the first interval. For an odd number of samples that are equally spaced the result is exact if the function is a polynomial of order 3 or less. If the samples are not equally spaced, then the result is exact only if the function is a polynomial of order 2 or less. """ y = asarray(y) nd = len(y.shape) N = y.shape[axis] last_dx = dx first_dx = dx returnshape = 0 if not x is None: x = asarray(x) if len(x.shape) == 1: shapex = ones(nd) shapex[axis] = x.shape[0] saveshape = x.shape returnshape = 1 x=x.reshape(tuple(shapex)) elif len(x.shape) != len(y.shape): raise ValueError, "If given, shape of x must be 1-d or the " \ "same as y." if x.shape[axis] != N: raise ValueError, "If given, length of x along axis must be the " \ "same as y." if N % 2 == 0: val = 0.0 result = 0.0 slice1 = [slice(None)]*nd slice2 = [slice(None)]*nd if not even in ['avg', 'last', 'first']: raise ValueError, \ "Parameter 'even' must be 'avg', 'last', or 'first'." # Compute using Simpson's rule on first intervals if even in ['avg', 'first']: slice1[axis] = -1 slice2[axis] = -2 if not x is None: last_dx = x[slice1] - x[slice2] val += 0.5*last_dx*(y[slice1]+y[slice2]) result = _basic_simps(y,0,N-3,x,dx,axis) # Compute using Simpson's rule on last set of intervals if even in ['avg', 'last']: slice1[axis] = 0 slice2[axis] = 1 if not x is None: first_dx = x[slice2] - x[slice1] val += 0.5*first_dx*(y[slice2]+y[slice1]) result += _basic_simps(y,1,N-2,x,dx,axis) if even == 'avg': val /= 2.0 result /= 2.0 result = result + val else: result = _basic_simps(y,0,N-2,x,dx,axis) if returnshape: x = x.reshape(saveshape) return result
slice1[axis] = 0 slice2[axis] = 1
slice1 = tupleset(slice1, axis, 0) slice2 = tupleset(slice2, axis, 1)
def simps(y, x=None, dx=1, axis=-1, even='avg'): """Integrate y(x) using samples along the given axis and the composite Simpson's rule. If x is None, spacing of dx is assumed. If there are an even number of samples, N, then there are an odd number of intervals (N-1), but Simpson's rule requires an even number of intervals. The parameter 'even' controls how this is handled as follows: even='avg': Average two results: 1) use the first N-2 intervals with a trapezoidal rule on the last interval and 2) use the last N-2 intervals with a trapezoidal rule on the first interval even='first': Use Simpson's rule for the first N-2 intervals with a trapezoidal rule on the last interval. even='last': Use Simpson's rule for the last N-2 intervals with a trapezoidal rule on the first interval. For an odd number of samples that are equally spaced the result is exact if the function is a polynomial of order 3 or less. If the samples are not equally spaced, then the result is exact only if the function is a polynomial of order 2 or less. """ y = asarray(y) nd = len(y.shape) N = y.shape[axis] last_dx = dx first_dx = dx returnshape = 0 if not x is None: x = asarray(x) if len(x.shape) == 1: shapex = ones(nd) shapex[axis] = x.shape[0] saveshape = x.shape returnshape = 1 x=x.reshape(tuple(shapex)) elif len(x.shape) != len(y.shape): raise ValueError, "If given, shape of x must be 1-d or the " \ "same as y." if x.shape[axis] != N: raise ValueError, "If given, length of x along axis must be the " \ "same as y." if N % 2 == 0: val = 0.0 result = 0.0 slice1 = [slice(None)]*nd slice2 = [slice(None)]*nd if not even in ['avg', 'last', 'first']: raise ValueError, \ "Parameter 'even' must be 'avg', 'last', or 'first'." # Compute using Simpson's rule on first intervals if even in ['avg', 'first']: slice1[axis] = -1 slice2[axis] = -2 if not x is None: last_dx = x[slice1] - x[slice2] val += 0.5*last_dx*(y[slice1]+y[slice2]) result = _basic_simps(y,0,N-3,x,dx,axis) # Compute using Simpson's rule on last set of intervals if even in ['avg', 'last']: slice1[axis] = 0 slice2[axis] = 1 if not x is None: first_dx = x[slice2] - x[slice1] val += 0.5*first_dx*(y[slice2]+y[slice1]) result += _basic_simps(y,1,N-2,x,dx,axis) if even == 'avg': val /= 2.0 result /= 2.0 result = result + val else: result = _basic_simps(y,0,N-2,x,dx,axis) if returnshape: x = x.reshape(saveshape) return result
first_dx = x[slice2] - x[slice1]
first_dx = x[tuple(slice2)] - x[tuple(slice1)]
def simps(y, x=None, dx=1, axis=-1, even='avg'): """Integrate y(x) using samples along the given axis and the composite Simpson's rule. If x is None, spacing of dx is assumed. If there are an even number of samples, N, then there are an odd number of intervals (N-1), but Simpson's rule requires an even number of intervals. The parameter 'even' controls how this is handled as follows: even='avg': Average two results: 1) use the first N-2 intervals with a trapezoidal rule on the last interval and 2) use the last N-2 intervals with a trapezoidal rule on the first interval even='first': Use Simpson's rule for the first N-2 intervals with a trapezoidal rule on the last interval. even='last': Use Simpson's rule for the last N-2 intervals with a trapezoidal rule on the first interval. For an odd number of samples that are equally spaced the result is exact if the function is a polynomial of order 3 or less. If the samples are not equally spaced, then the result is exact only if the function is a polynomial of order 2 or less. """ y = asarray(y) nd = len(y.shape) N = y.shape[axis] last_dx = dx first_dx = dx returnshape = 0 if not x is None: x = asarray(x) if len(x.shape) == 1: shapex = ones(nd) shapex[axis] = x.shape[0] saveshape = x.shape returnshape = 1 x=x.reshape(tuple(shapex)) elif len(x.shape) != len(y.shape): raise ValueError, "If given, shape of x must be 1-d or the " \ "same as y." if x.shape[axis] != N: raise ValueError, "If given, length of x along axis must be the " \ "same as y." if N % 2 == 0: val = 0.0 result = 0.0 slice1 = [slice(None)]*nd slice2 = [slice(None)]*nd if not even in ['avg', 'last', 'first']: raise ValueError, \ "Parameter 'even' must be 'avg', 'last', or 'first'." # Compute using Simpson's rule on first intervals if even in ['avg', 'first']: slice1[axis] = -1 slice2[axis] = -2 if not x is None: last_dx = x[slice1] - x[slice2] val += 0.5*last_dx*(y[slice1]+y[slice2]) result = _basic_simps(y,0,N-3,x,dx,axis) # Compute using Simpson's rule on last set of intervals if even in ['avg', 'last']: slice1[axis] = 0 slice2[axis] = 1 if not x is None: first_dx = x[slice2] - x[slice1] val += 0.5*first_dx*(y[slice2]+y[slice1]) result += _basic_simps(y,1,N-2,x,dx,axis) if even == 'avg': val /= 2.0 result /= 2.0 result = result + val else: result = _basic_simps(y,0,N-2,x,dx,axis) if returnshape: x = x.reshape(saveshape) return result
slice0 = [slice(None)]*nd slice0[axis] = 0 slicem1 = [slice(None)]*nd slicem1[axis] = -1
all = (slice(None),) * nd slice0 = tupleset(all, axis, 0) slicem1 = tupleset(all, axis, -1)
def romb(y, dx=1.0, axis=-1, show=0): """Uses Romberg integration to integrate y(x) using N samples along the given axis which are assumed equally spaced with distance dx. The number of samples must be 1 + a non-negative power of two: N=2**k + 1 """ y = asarray(y) nd = len(y.shape) Nsamps = y.shape[axis] Ninterv = Nsamps-1 n = 1 k = 0 while n < Ninterv: n <<= 1 k += 1 if n != Ninterv: raise ValueError, \ "Number of samples must be one plus a non-negative power of 2." R = {} slice0 = [slice(None)]*nd slice0[axis] = 0 slicem1 = [slice(None)]*nd slicem1[axis] = -1 h = Ninterv*asarray(dx)*1.0 R[(1,1)] = (y[slice0] + y[slicem1])/2.0*h slice_R = [slice(None)]*nd start = stop = step = Ninterv for i in range(2,k+1): start >>= 1 slice_R[axis] = slice(start,stop,step) step >>= 1 R[(i,1)] = 0.5*(R[(i-1,1)] + h*add.reduce(y[slice_R],axis)) for j in range(2,i+1): R[(i,j)] = R[(i,j-1)] + \ (R[(i,j-1)]-R[(i-1,j-1)]) / ((1 << (2*(j-1)))-1) h = h / 2.0 if show: if not isscalar(R[(1,1)]): print "*** Printing table only supported for integrals" + \ " of a single data set." else: try: precis = show[0] except (TypeError, IndexError): precis = 5 try: width = show[1] except (TypeError, IndexError): width = 8 formstr = "%" + str(width) + '.' + str(precis)+'f' print "\n Richardson Extrapolation Table for Romberg Integration " print "====================================================================" for i in range(1,k+1): for j in range(1,i+1): print formstr % R[(i,j)], print print "====================================================================\n" return R[(k,k)]
slice_R = [slice(None)]*nd
slice_R = all
def romb(y, dx=1.0, axis=-1, show=0): """Uses Romberg integration to integrate y(x) using N samples along the given axis which are assumed equally spaced with distance dx. The number of samples must be 1 + a non-negative power of two: N=2**k + 1 """ y = asarray(y) nd = len(y.shape) Nsamps = y.shape[axis] Ninterv = Nsamps-1 n = 1 k = 0 while n < Ninterv: n <<= 1 k += 1 if n != Ninterv: raise ValueError, \ "Number of samples must be one plus a non-negative power of 2." R = {} slice0 = [slice(None)]*nd slice0[axis] = 0 slicem1 = [slice(None)]*nd slicem1[axis] = -1 h = Ninterv*asarray(dx)*1.0 R[(1,1)] = (y[slice0] + y[slicem1])/2.0*h slice_R = [slice(None)]*nd start = stop = step = Ninterv for i in range(2,k+1): start >>= 1 slice_R[axis] = slice(start,stop,step) step >>= 1 R[(i,1)] = 0.5*(R[(i-1,1)] + h*add.reduce(y[slice_R],axis)) for j in range(2,i+1): R[(i,j)] = R[(i,j-1)] + \ (R[(i,j-1)]-R[(i-1,j-1)]) / ((1 << (2*(j-1)))-1) h = h / 2.0 if show: if not isscalar(R[(1,1)]): print "*** Printing table only supported for integrals" + \ " of a single data set." else: try: precis = show[0] except (TypeError, IndexError): precis = 5 try: width = show[1] except (TypeError, IndexError): width = 8 formstr = "%" + str(width) + '.' + str(precis)+'f' print "\n Richardson Extrapolation Table for Romberg Integration " print "====================================================================" for i in range(1,k+1): for j in range(1,i+1): print formstr % R[(i,j)], print print "====================================================================\n" return R[(k,k)]
slice_R[axis] = slice(start,stop,step)
slice_R = tupleset(slice_R, slice(start,stop,step))
def romb(y, dx=1.0, axis=-1, show=0): """Uses Romberg integration to integrate y(x) using N samples along the given axis which are assumed equally spaced with distance dx. The number of samples must be 1 + a non-negative power of two: N=2**k + 1 """ y = asarray(y) nd = len(y.shape) Nsamps = y.shape[axis] Ninterv = Nsamps-1 n = 1 k = 0 while n < Ninterv: n <<= 1 k += 1 if n != Ninterv: raise ValueError, \ "Number of samples must be one plus a non-negative power of 2." R = {} slice0 = [slice(None)]*nd slice0[axis] = 0 slicem1 = [slice(None)]*nd slicem1[axis] = -1 h = Ninterv*asarray(dx)*1.0 R[(1,1)] = (y[slice0] + y[slicem1])/2.0*h slice_R = [slice(None)]*nd start = stop = step = Ninterv for i in range(2,k+1): start >>= 1 slice_R[axis] = slice(start,stop,step) step >>= 1 R[(i,1)] = 0.5*(R[(i-1,1)] + h*add.reduce(y[slice_R],axis)) for j in range(2,i+1): R[(i,j)] = R[(i,j-1)] + \ (R[(i,j-1)]-R[(i-1,j-1)]) / ((1 << (2*(j-1)))-1) h = h / 2.0 if show: if not isscalar(R[(1,1)]): print "*** Printing table only supported for integrals" + \ " of a single data set." else: try: precis = show[0] except (TypeError, IndexError): precis = 5 try: width = show[1] except (TypeError, IndexError): width = 8 formstr = "%" + str(width) + '.' + str(precis)+'f' print "\n Richardson Extrapolation Table for Romberg Integration " print "====================================================================" for i in range(1,k+1): for j in range(1,i+1): print formstr % R[(i,j)], print print "====================================================================\n" return R[(k,k)]
argument 'n' indicates the number of rows (observations).
argument 'nrow' indicates the number of rows (observations).
def __call__(self, *args, **kw):
if (nzmax>0) and (max(self.rowind[:nnz]) >= M):
if (nzmax < nnz): raise ValueError, "Nzmax must not be less than nnz." if (nnz>0) and (max(self.rowind[:nnz]) >= M):
def _check(self): M,N = self.shape nnz = self.indptr[-1] nzmax = len(self.rowind)
if (len(self.colind)>0) and (max(self.colind) >= N):
if (nzmax < nnz): raise ValueError, "Nzmax must not be less than nnz." if (nnz>0) and (max(self.colind[:nnz]) >= M):
def _check(self): M,N = self.shape if (rank(self.data) != 1) or (rank(self.colind) != 1) or \ (rank(self.indptr) != 1): raise ValueError, "Data, colind, and indptr arrays "\ "should be rank 1." if (len(self.data) != len(self.colind)): raise ValueError, "Data and row list should have same length" if (len(self.indptr) != M+1): raise ValueError, "Index pointer should be of length #rows + 1" if (len(self.colind)>0) and (max(self.colind) >= N): raise ValueError, "Column-values must be < N." if (self.indptr[-1] > len(self.colind)): raise ValueError, \ "Last value of index list should be less than "\ "the size of data list" self.nnz = self.indptr[-1] self.nzmax = len(self.colind) self.typecode = self.data.typecode() if self.typecode not in 'fdFD': self.typecode = 'd' self.data = self.data.astype('d') self.ftype = _transtabl[self.typecode]
"""Minimze Description: Optimize the function, f, whose gradient is given by fprime using the
"""Description: Minimize the function, f, whose gradient is given by fprime using the
def fmin_ncg(f, x0, fprime, fhess_p=None, fhess=None, args=(), avextol=1e-5, maxiter=None, full_output=0, disp=1): """Minimze Description: Optimize the function, f, whose gradient is given by fprime using the Newton-CG method. fhess_p must compute the hessian times an arbitrary vector. If it is not given, finite-differences on fprime are used to compute it. See Wright, and Nocedal 'Numerical Optimization', 1999, pg. 140. Inputs: f -- the Python function or method to be minimized. x0 -- the initial guess for the minimizer. fprime -- a function to compute the gradient of f: fprime(x, *args) fhess_p -- a function to compute the Hessian of f times an arbitrary vector: fhess_p (x, p, *args) fhess -- a function to compute the Hessian matrix of f. args -- extra arguments for f, fprime, fhess_p, and fhess (the same set of extra arguments is supplied to all of these functions). Outputs: (xopt, {fopt, fcalls, gcalls, hcalls, warnflag}) xopt -- the minimizer of f fopt -- the value of the function at xopt: fopt = f(xopt) fcalls -- the number of function calls. gcalls -- the number of gradient calls. hcalls -- the number of hessian calls. warnflag -- algorithm warnings: 1 : 'Maximum number of iterations exceeded.' Additional Inputs: avextol -- Convergence is assumed when the average relative error in the minimizer falls below this amount. maxiter -- Maximum number of iterations to allow. full_output -- If non-zero return the optional outputs. disp -- If non-zero print convergence message. Remarks: Only one of fhess_p or fhess need be given. If fhess is provided, then fhess_p will be ignored. If neither fhess nor fhess_p is provided, then the hessian product will be approximated using finite differences on fprime. """ x0 = asarray(x0) fcalls = 0 gcalls = 0 hcalls = 0 if maxiter is None: maxiter = len(x0)*200 xtol = len(x0)*avextol update = [2*xtol] xk = x0 k = 0 while (Num.add.reduce(abs(update)) > xtol) and (k < maxiter): # Compute a search direction pk by applying the CG method to # del2 f(xk) p = - grad f(xk) starting from 0. b = -apply(fprime,(xk,)+args) gcalls = gcalls + 1 maggrad = Num.add.reduce(abs(b)) eta = min([0.5,Num.sqrt(maggrad)]) termcond = eta * maggrad xsupi = 0 ri = -b psupi = -ri i = 0 dri0 = Num.dot(ri,ri) if fhess is not None: # you want to compute hessian once. A = apply(fhess,(xk,)+args) hcalls = hcalls + 1 while Num.add.reduce(abs(ri)) > termcond: if fhess is None: if fhess_p is None: Ap = apply(approx_fhess_p,(xk,psupi,fprime)+args) gcalls = gcalls + 2 else: Ap = apply(fhess_p,(xk,psupi)+args) hcalls = hcalls + 1 else: Ap = Num.dot(A,psupi) # check curvature curv = Num.dot(psupi,Ap) if (curv <= 0): if (i > 0): break else: xsupi = xsupi + dri0/curv * psupi break alphai = dri0 / curv xsupi = xsupi + alphai * psupi ri = ri + alphai * Ap dri1 = Num.dot(ri,ri) betai = dri1 / dri0 psupi = -ri + betai * psupi i = i + 1 dri0 = dri1 # update Num.dot(ri,ri) for next time. pk = xsupi # search direction is solution to system. gfk = -b # gradient at xk alphak, fc, gc = line_search_BFGS(f,xk,pk,gfk,args) fcalls = fcalls + fc gcalls = gcalls + gc update = alphak * pk xk = xk + update k = k + 1 if disp or full_output: fval = apply(f,(xk,)+args) if k >= maxiter: warnflag = 1 if disp: print "Warning: Maximum number of iterations has been exceeded" print " Current function value: %f" % fval print " Iterations: %d" % k print " Function evaluations: %d" % fcalls print " Gradient evaluations: %d" % gcalls print " Hessian evaluations: %d" % hcalls else: warnflag = 0 if disp: print "Optimization terminated successfully." print " Current function value: %f" % fval print " Iterations: %d" % k print " Function evaluations: %d" % fcalls print " Gradient evaluations: %d" % gcalls print " Hessian evaluations: %d" % hcalls if full_output: return xk, fval, fcalls, gcalls, hcalls, warnflag else: return xk
save_file = './saved_values.py' if not os.path.exists(save_file): save_file = '../saved_values.py'
x11_info = get_x11_info() if not x11_info: return
def configuration(parent_package=''): """ gist only works with an X-windows server This will install *.gs and *.gp files to '%spython%s/site-packages/scipy/xplt' % (sys.prefix,sys.version[:3]) """ # Check for X11 libraries save_file = './saved_values.py' if not os.path.exists(save_file): save_file = '../saved_values.py' try: exec(open(save_file).read()) try: X11 = X11 except NameError: X11 = check_and_save() except IOError: X11 = check_and_save() if X11: config = default_config_dict() if parent_package: parent_package = parent_package + '.' local_path = get_path(__name__) config['packages'].append(parent_package+'xplt') from scipy_distutils.core import Extension sources = ['gistCmodule.c'] sources = [os.path.join(local_path,x) for x in sources] ext = Extension(parent_package+'xplt.gistC', sources, include_dirs = ['/usr/include/X11'], library_dirs = ['/usr/X11R6/lib'], libraries = ['X11','m']) config['ext_modules'].append(ext) from glob import glob gist = glob(os.path.join(local_path,'gist','*.c')) # libraries are C static libraries config['libraries'].append(('gist',{'sources':gist, 'macros':[('STDC_HEADERS',1)]})) file_ext = ['*.gs','*.gp', '*.ps', '*.help'] xplt_files = [glob(os.path.join(local_path,x)) for x in file_ext] xplt_files = reduce(lambda x,y:x+y,xplt_files,[]) xplt_path = os.path.join(local_path,'xplt') config['data_files'].extend( [(xplt_path,xplt_files)]) return config
try: exec(open(save_file).read()) try: X11 = X11 except NameError: X11 = check_and_save() except IOError: X11 = check_and_save() if X11: config = default_config_dict()
config = default_config_dict('xplt',parent_package) local_path = get_path(__name__) sources = ['gistCmodule.c'] sources = [os.path.join(local_path,x) for x in sources] ext = Extension(dot_join(parent_package,'xplt.gistC'), sources, include_dirs = x11_info.get('include_dirs',[]), library_dirs = x11_info.get('library_dirs',[]), libraries = x11_info.get('libraries',[]) + ['m']) config['ext_modules'].append(ext) from glob import glob gist = glob(os.path.join(local_path,'gist','*.c')) config['libraries'].append(('gist',{'sources':gist, 'macros':[('STDC_HEADERS',1)]})) file_ext = ['*.gs','*.gp', '*.ps', '*.help'] xplt_files = [glob(os.path.join(local_path,x)) for x in file_ext] xplt_files = reduce(lambda x,y:x+y,xplt_files,[]) xplt_path = os.path.join(local_path,'xplt') config['data_files'].extend( [(xplt_path,xplt_files)]) return config
def configuration(parent_package=''): """ gist only works with an X-windows server This will install *.gs and *.gp files to '%spython%s/site-packages/scipy/xplt' % (sys.prefix,sys.version[:3]) """ # Check for X11 libraries save_file = './saved_values.py' if not os.path.exists(save_file): save_file = '../saved_values.py' try: exec(open(save_file).read()) try: X11 = X11 except NameError: X11 = check_and_save() except IOError: X11 = check_and_save() if X11: config = default_config_dict() if parent_package: parent_package = parent_package + '.' local_path = get_path(__name__) config['packages'].append(parent_package+'xplt') from scipy_distutils.core import Extension sources = ['gistCmodule.c'] sources = [os.path.join(local_path,x) for x in sources] ext = Extension(parent_package+'xplt.gistC', sources, include_dirs = ['/usr/include/X11'], library_dirs = ['/usr/X11R6/lib'], libraries = ['X11','m']) config['ext_modules'].append(ext) from glob import glob gist = glob(os.path.join(local_path,'gist','*.c')) # libraries are C static libraries config['libraries'].append(('gist',{'sources':gist, 'macros':[('STDC_HEADERS',1)]})) file_ext = ['*.gs','*.gp', '*.ps', '*.help'] xplt_files = [glob(os.path.join(local_path,x)) for x in file_ext] xplt_files = reduce(lambda x,y:x+y,xplt_files,[]) xplt_path = os.path.join(local_path,'xplt') config['data_files'].extend( [(xplt_path,xplt_files)]) return config
if parent_package: parent_package = parent_package + '.' local_path = get_path(__name__) config['packages'].append(parent_package+'xplt') from scipy_distutils.core import Extension sources = ['gistCmodule.c'] sources = [os.path.join(local_path,x) for x in sources] ext = Extension(parent_package+'xplt.gistC', sources, include_dirs = ['/usr/include/X11'], library_dirs = ['/usr/X11R6/lib'], libraries = ['X11','m']) config['ext_modules'].append(ext) from glob import glob gist = glob(os.path.join(local_path,'gist','*.c')) config['libraries'].append(('gist',{'sources':gist, 'macros':[('STDC_HEADERS',1)]})) file_ext = ['*.gs','*.gp', '*.ps', '*.help'] xplt_files = [glob(os.path.join(local_path,x)) for x in file_ext] xplt_files = reduce(lambda x,y:x+y,xplt_files,[]) xplt_path = os.path.join(local_path,'xplt') config['data_files'].extend( [(xplt_path,xplt_files)]) return config def check_and_save(file='saved_values.py'): import commands output = commands.getoutput('find /usr -name "libX11*" -print') X11 = (output != '') fid = open(file,'a') fid.write('X11 = %d\n' % X11) fid.close() return X11
if __name__ == '__main__': from scipy_distutils.core import setup setup(**configuration())
def configuration(parent_package=''): """ gist only works with an X-windows server This will install *.gs and *.gp files to '%spython%s/site-packages/scipy/xplt' % (sys.prefix,sys.version[:3]) """ # Check for X11 libraries save_file = './saved_values.py' if not os.path.exists(save_file): save_file = '../saved_values.py' try: exec(open(save_file).read()) try: X11 = X11 except NameError: X11 = check_and_save() except IOError: X11 = check_and_save() if X11: config = default_config_dict() if parent_package: parent_package = parent_package + '.' local_path = get_path(__name__) config['packages'].append(parent_package+'xplt') from scipy_distutils.core import Extension sources = ['gistCmodule.c'] sources = [os.path.join(local_path,x) for x in sources] ext = Extension(parent_package+'xplt.gistC', sources, include_dirs = ['/usr/include/X11'], library_dirs = ['/usr/X11R6/lib'], libraries = ['X11','m']) config['ext_modules'].append(ext) from glob import glob gist = glob(os.path.join(local_path,'gist','*.c')) # libraries are C static libraries config['libraries'].append(('gist',{'sources':gist, 'macros':[('STDC_HEADERS',1)]})) file_ext = ['*.gs','*.gp', '*.ps', '*.help'] xplt_files = [glob(os.path.join(local_path,x)) for x in file_ext] xplt_files = reduce(lambda x,y:x+y,xplt_files,[]) xplt_path = os.path.join(local_path,'xplt') config['data_files'].extend( [(xplt_path,xplt_files)]) return config
pass
def check_basic(self):
if __name__ == "__main__":
def _testme():
def speye(n, m = None, k = 0, dtype = 'd'): """ speye(n, m) returns a (n x m) matrix stored in CSC sparse matrix format, where the k-th diagonal is all ones, and everything else is zeros. """ diags = ones((1, n), dtype = dtype) return spdiags(diags, k, n, m)
_endprint(x, flag, fval, maxfun, tol, disp)
_endprint(x, flag, fval, maxfun, xtol, disp)
def fminbound(func, x1, x2, args=(), xtol=1e-5, maxfun=500, full_output=0, disp=1): """Bounded minimization for scalar functions. Description: Finds a local minimizer of the scalar function func in the interval x1 < xopt < x2 using Brent's method. (See brent for auto-bracketing). Inputs: func -- the function to be minimized (must accept scalar input and return scalar output). x1, x2 -- the optimization bounds. args -- extra arguments to pass to function. xtol -- the convergence tolerance. maxfun -- maximum function evaluations. full_output -- Non-zero to return optional outputs. disp -- Non-zero to print messages. 0 : no message printing. 1 : non-convergence notification messages only. 2 : print a message on convergence too. 3 : print iteration results. Outputs: (xopt, {fval, ierr, numfunc}) xopt -- The minimizer of the function over the interval. fval -- The function value at the minimum point. ierr -- An error flag (0 if converged, 1 if maximum number of function calls reached). numfunc -- The number of function calls. """ if x1 > x2: raise ValueError, "The lower bound exceeds the upper bound." flag = 0 header = ' Func-count x f(x) Procedure' step=' initial' sqrt_eps = sqrt(2.2e-16) golden_mean = 0.5*(3.0-sqrt(5.0)) a, b = x1, x2 fulc = a + golden_mean*(b-a) nfc, xf = fulc, fulc rat = e = 0.0 x = xf fx = func(x,*args) num = 1 fmin_data = (1, xf, fx) ffulc = fnfc = fx xm = 0.5*(a+b) tol1 = sqrt_eps*abs(xf) + xtol / 3.0 tol2 = 2.0*tol1 if disp > 2: print (" ") print (header) print "%5.0f %12.6g %12.6g %s" % (fmin_data + (step,)) while ( abs(xf-xm) > (tol2 - 0.5*(b-a)) ): golden = 1 # Check for parabolic fit if abs(e) > tol1: golden = 0 r = (xf-nfc)*(fx-ffulc) q = (xf-fulc)*(fx-fnfc) p = (xf-fulc)*q - (xf-nfc)*r q = 2.0*(q-r) if q > 0.0: p = -p q = abs(q) r = e e = rat # Check for acceptability of parabola if ( (abs(p) < abs(0.5*q*r)) and (p > q*(a-xf)) and (p < q*(b-xf))): rat = (p+0.0) / q; x = xf + rat step = ' parabolic' if ((x-a) < tol2) or ((b-x) < tol2): si = Numeric.sign(xm-xf) + ((xm-xf)==0) rat = tol1*si else: # do a golden section step golden = 1 if golden: # Do a golden-section step if xf >= xm: e=a-xf else: e=b-xf rat = golden_mean*e step = ' golden' si = Numeric.sign(rat) + (rat == 0) x = xf + si*max([abs(rat), tol1]) fu = func(x,*args) num += 1 fmin_data = (num, x, fu) if disp > 2: print "%5.0f %12.6g %12.6g %s" % (fmin_data + (step,)) if fu <= fx: if x >= xf: a = xf else: b = xf fulc, ffulc = nfc, fnfc nfc, fnfc = xf, fx xf, fx = x, fu else: if x < xf: a = x else: b = x if (fu <= fnfc) or (nfc == xf): fulc, ffulc = nfc, fnfc nfc, fnfc = x, fu elif (fu <= ffulc) or (fulc == xf) or (fulc == nfc): fulc, ffulc = x, fu xm = 0.5*(a+b) tol1 = sqrt_eps*abs(xf) + xtol/3.0 tol2 = 2.0*tol1 if num >= maxfun: flag = 1 fval = fx if disp > 0: _endprint(x, flag, fval, maxfun, tol, disp) if full_output: return xf, fval, flag, num else: return xf fval = fx if disp > 0: _endprint(x, flag, fval, maxfun, xtol, disp) if full_output: return xf, fval, flag, num else: return xf
raise ValuError, "Bracketing interval must be length 2 or 3 sequence."
raise ValueError, "Bracketing interval must be length 2 or 3 sequence."
def brent(func, args=(), brack=None, tol=1.48e-8, full_output=0, maxiter=500): """ Given a function of one-variable and a possible bracketing interval, return the minimum of the function isolated to a fractional precision of tol. A bracketing interval is a triple (a,b,c) where (a<b<c) and func(b) < func(a),func(c). If bracket is two numbers then they are assumed to be a starting interval for a downhill bracket search (see bracket) Uses inverse parabolic interpolation when possible to speed up convergence of golden section method. """ _mintol = 1.0e-11 _cg = 0.3819660 if brack is None: xa,xb,xc,fa,fb,fc,funcalls = bracket(func, args=args) elif len(brack) == 2: xa,xb,xc,fa,fb,fc,funcalls = bracket(func, xa=brack[0], xb=brack[1], args=args) elif len(brack) == 3: xa,xb,xc = brack if (xa > xc): # swap so xa < xc can be assumed dum = xa; xa=xc; xc=dum assert ((xa < xb) and (xb < xc)), "Not a bracketing interval." fa = apply(func, (xa,)+args) fb = apply(func, (xb,)+args) fc = apply(func, (xc,)+args) assert ((fb<fa) and (fb < fc)), "Not a bracketing interval." funcalls = 3 else: raise ValuError, "Bracketing interval must be length 2 or 3 sequence." x=w=v=xb fw=fv=fx=apply(func, (x,)+args) if (xa < xc): a = xa; b = xc else: a = xc; b = xa deltax= 0.0 funcalls = 1 iter = 0 while (iter < maxiter): tol1 = tol*abs(x) + _mintol tol2 = 2.0*tol1 xmid = 0.5*(a+b) if abs(x-xmid) < (tol2-0.5*(b-a)): # check for convergence xmin=x; fval=fx break if (abs(deltax) <= tol1): if (x>=xmid): deltax=a-x # do a golden section step else: deltax=b-x rat = _cg*deltax else: # do a parabolic step tmp1 = (x-w)*(fx-fv) tmp2 = (x-v)*(fx-fw) p = (x-v)*tmp2 - (x-w)*tmp1; tmp2 = 2.0*(tmp2-tmp1) if (tmp2 > 0.0): p = -p tmp2 = abs(tmp2) dx_temp = deltax deltax= rat # check parabolic fit if ((p > tmp2*(a-x)) and (p < tmp2*(b-x)) and (abs(p) < abs(0.5*tmp2*dx_temp))): rat = p*1.0/tmp2 # if parabolic step is useful. u = x + rat if ((u-a) < tol2 or (b-u) < tol2): if xmid-x >= 0: rat = tol1 else: rat = -tol1 else: if (x>=xmid): deltax=a-x # if it's not do a golden section step else: deltax=b-x rat = _cg*deltax if (abs(rat) < tol1): # update by at least tol1 if rat >= 0: u = x + tol1 else: u = x - tol1 else: u = x + rat fu = apply(func, (u,)+args) # calculate new output value funcalls += 1 if (fu > fx): # if it's bigger than current if (u<x): a=u else: b=u if (fu<=fw) or (w==x): v=w; w=u; fv=fw; fw=fu elif (fu<=fv) or (v==x) or (v==w): v=u; fv=fu else: if (u >= x): a = x else: b = x v=w; w=x; x=u fv=fw; fw=fx; fx=fu xmin = x fval = fx if full_output: return xmin, fval, iter, funcalls else: return xmin
raise ValuError, "Bracketing interval must be length 2 or 3 sequence."
raise ValueError, "Bracketing interval must be length 2 or 3 sequence."
def golden(func, args=(), brack=None, tol=_epsilon, full_output=0): """ Given a function of one-variable and a possible bracketing interval, return the minimum of the function isolated to a fractional precision of tol. A bracketing interval is a triple (a,b,c) where (a<b<c) and func(b) < func(a),func(c). If bracket is two numbers then they are assumed to be a starting interval for a downhill bracket search (see bracket) Uses analog of bisection method to decrease the bracketed interval. """ if brack is None: xa,xb,xc,fa,fb,fc,funcalls = bracket(func, args=args) elif len(brack) == 2: xa,xb,xc,fa,fb,fc,funcalls = bracket(func, xa=brack[0], xb=brack[1], args=args) elif len(brack) == 3: xa,xb,xc = brack if (xa > xc): # swap so xa < xc can be assumed dum = xa; xa=xc; xc=dum assert ((xa < xb) and (xb < xc)), "Not a bracketing interval." fa = apply(func, (xa,)+args) fb = apply(func, (xb,)+args) fc = apply(func, (xc,)+args) assert ((fb<fa) and (fb < fc)), "Not a bracketing interval." funcalls = 3 else: raise ValuError, "Bracketing interval must be length 2 or 3 sequence." _gR = 0.61803399 _gC = 1.0-_gR x3 = xc x0 = xa if (abs(xc-xb) > abs(xb-xa)): x1 = xb x2 = xb + _gC*(xc-xb) else: x2 = xb x1 = xb - _gC*(xb-xa) f1 = apply(func, (x1,)+args) f2 = apply(func, (x2,)+args) funcalls += 2 while (abs(x3-x0) > tol*(abs(x1)+abs(x2))): if (f2 < f1): x0 = x1; x1 = x2; x2 = _gR*x1 + _gC*x3 f1 = f2; f2 = apply(func, (x2,)+args) else: x3 = x2; x2 = x1; x1 = _gR*x2 + _gC*x0 f2 = f1; f1 = apply(func, (x1,)+args) funcalls += 1 if (f1 < f2): xmin = x1 fval = f1 else: xmin = x2 fval = f2 if full_output: return xmin, fval, funcalls else: return xmin
raise RunTimeError, "Too many iterations."
raise RuntimeError, "Too many iterations."
def bracket(func, xa=0.0, xb=1.0, args=(), grow_limit=110.0): """Given a function and distinct initial points, search in the downhill direction (as defined by the initital points) and return new points xa, xb, xc that bracket the minimum of the function: f(xa) > f(xb) < f(xc) """ _gold = 1.618034 _verysmall_num = 1e-21 fa = apply(func, (xa,)+args) fb = apply(func, (xb,)+args) if (fa < fb): # Switch so fa > fb dum = xa; xa = xb; xb = dum dum = fa; fa = fb; fb = dum xc = xb + _gold*(xb-xa) fc = apply(func, (xc,)+args) funcalls = 3 iter = 0 while (fc < fb): tmp1 = (xb - xa)*(fb-fc) tmp2 = (xb - xc)*(fb-fa) val = tmp2-tmp1 if abs(val) < _verysmall_num: denom = 2.0*_verysmall_num else: denom = 2.0*val w = xb - ((xb-xc)*tmp2-(xb-xa)*tmp1)/denom wlim = xb + grow_limit*(xc-xb) if iter > 1000: raise RunTimeError, "Too many iterations." if (w-xc)*(xb-w) > 0.0: fw = apply(func, (w,)+args) funcalls += 1 if (fw < fc): xa = xb; xb=w; fa=fb; fb=fw return xa, xb, xc, fa, fb, fc, funcalls elif (fw > fb): xc = w; fc=fw return xa, xb, xc, fa, fb, fc, funcalls w = xc + _gold*(xc-xb) fw = apply(func, (w,)+args) funcalls += 1 elif (w-wlim)*(wlim-xc) >= 0.0: w = wlim fw = apply(func, (w,)+args) funcalls += 1 elif (w-wlim)*(xc-w) > 0.0: fw = apply(func, (w,)+args) funcalls += 1 if (fw < fc): xb=xc; xc=w; w=xc+_gold*(xc-xb) fb=fc; fc=fw; fw=apply(func, (w,)+args) funcalls += 1 else: w = xc + _gold*(xc-xb) fw = apply(func, (w,)+args) funcalls += 1 xa=xb; xb=xc; xc=w fa=fb; fb=fc; fc=fw return xa, xb, xc, fa, fb, fc, funcalls
(-10,1):0L, (10,-1):0L, (-10,-3):0L,(10,11),0L}
(-10,1):0L, (10,-1):0L, (-10,-3):0L,(10,11):0L}
def check_exact(self): resdict = {(10,2):45L, (10,5):252L, (1000,20):339482811302457603895512614793686020778700L, (1000,975):47641862536236518640933948075167736642053976275040L, (-10,1):0L, (10,-1):0L, (-10,-3):0L,(10,11),0L} for key in resdict.keys(): assert_equal(comb(key[0],key[1],exact=1),resdict[key])
except (AttributeError, TypeError): try: return self.matvec(asarray(other)) except: raise TypeError, "x.dot(y): y must be matrix, vector, or seq" except ValueError: K2 = other.shape[0] N = 1 if N == 1:
elif len(other.shape) == 1: K2, N = other.shape[0], 1 else: raise ValueError, "could not interpret dimensions" if N == 1 or K2 == 1:
def dot(self, other): """ A generic interface for matrix-matrix or matrix-vector multiplication. Returns A.transpose().conj() * other or A.transpose() * other. """ M, K1 = self.shape try: K2, N = other.shape except (AttributeError, TypeError): # Not sparse or dense. Interpret it as a sequence. try: return self.matvec(asarray(other)) except: raise TypeError, "x.dot(y): y must be matrix, vector, or seq" except ValueError: # Assume it's a rank-1 array K2 = other.shape[0] N = 1 if N == 1: return self.matvec(other) else: if K1 != K2: raise ValueError, "dimension mismatch" return self.matmat(other)
with a dense matrix d
with a dense array or matrix d
def save( self, file_name, format = '%d %d %f\n' ): try: fd = open( file_name, 'w' ) except Exception, e: raise e, file_name fd.write( '%d %d\n' % self.shape ) fd.write( '%d\n' % self.size ) for ii in xrange( self.size ): ir, ic = self.rowcol( ii ) data = self.getdata( ii ) fd.write( format % (ir, ic, data) ) fd.close()
def __init__(self, arg1, dims=(None,None), nzmax=100, dtype='d', copy=False):
def __init__(self, arg1, dims=None, nzmax=100, dtype='d', copy=False):
def __init__(self, arg1, dims=(None,None), nzmax=100, dtype='d', copy=False): spmatrix.__init__(self) if isdense(arg1): # Convert the dense matrix arg1 to CSC format if rank(arg1) == 2: s = asarray(arg1) if s.dtype.char not in 'fdFD': # Use a double array as the source (but leave it alone) s = s*1.0 if (rank(s) == 2): M, N = s.shape dtype = s.dtype.char func = getattr(sparsetools, _transtabl[dtype]+'fulltocsc') ierr = irow = jcol = 0 nnz = sum(ravel(s != 0.0)) a = zeros((nnz,), dtype) rowa = zeros((nnz,), 'i') ptra = zeros((N+1,), 'i') while 1: a, rowa, ptra, irow, jcol, ierr = \ func(s, a, rowa, ptra, irow, jcol, ierr) if (ierr == 0): break nnz = nnz + ALLOCSIZE a = resize1d(a, nnz) rowa = resize1d(rowa, nnz) self.data = a self.rowind = rowa self.indptr = ptra self.shape = (M, N) # s = dok_matrix(arg1).tocsc(nzmax) # self.shape = s.shape # self.data = s.data # self.rowind = s.rowind # self.indptr = s.indptr else: raise ValueError, "dense array does not have rank 1 or 2" elif isspmatrix(arg1): s = arg1 if isinstance(s, csc_matrix): # do nothing but copy information self.shape = s.shape if copy: self.data = s.data.copy() self.rowind = s.rowind.copy() self.indptr = s.indptr.copy() else: self.data = s.data self.rowind = s.rowind self.indptr = s.indptr elif isinstance(s, csr_matrix): self.shape = s.shape func = getattr(sparsetools, s.ftype+'transp') self.data, self.rowind, self.indptr = \ func(s.shape[1], s.data, s.colind, s.indptr) else: temp = s.tocsc() self.data = temp.data self.rowind = temp.rowind self.indptr = temp.indptr self.shape = temp.shape elif type(arg1) == tuple: try: # Assume it's a tuple of matrix dimensions (M, N) (M, N) = arg1 M = int(M) # will raise TypeError if (data, ij) N = int(N) self.data = zeros((nzmax,), dtype) self.rowind = zeros((nzmax,), int) self.indptr = zeros((N+1,), int) self.shape = (M, N) except (ValueError, TypeError): try: # Try interpreting it as (data, ij) (s, ij) = arg1 assert isinstance(ij, ArrayType) and (rank(ij) == 2) and (shape(ij) == (len(s), 2)) temp = coo_matrix( s, ij, dims=dims, nzmax=nzmax, \ dtype=dtype).tocsc() self.shape = temp.shape self.data = temp.data self.rowind = temp.rowind self.indptr = temp.indptr except: try: # Try interpreting it as (data, rowind, indptr) (s, rowind, indptr) = arg1 if copy: self.data = array(s) self.rowind = array(rowind) self.indptr = array(indptr) else: self.data = asarray(s) self.rowind = asarray(rowind) self.indptr = asarray(indptr) except: raise ValueError, "unrecognized form for csc_matrix constructor" else: raise ValueError, "unrecognized form for csc_matrix constructor"
s = asarray(arg1)
s = arg1
def __init__(self, arg1, dims=(None,None), nzmax=100, dtype='d', copy=False): spmatrix.__init__(self) if isdense(arg1): # Convert the dense matrix arg1 to CSC format if rank(arg1) == 2: s = asarray(arg1) if s.dtype.char not in 'fdFD': # Use a double array as the source (but leave it alone) s = s*1.0 if (rank(s) == 2): M, N = s.shape dtype = s.dtype.char func = getattr(sparsetools, _transtabl[dtype]+'fulltocsc') ierr = irow = jcol = 0 nnz = sum(ravel(s != 0.0)) a = zeros((nnz,), dtype) rowa = zeros((nnz,), 'i') ptra = zeros((N+1,), 'i') while 1: a, rowa, ptra, irow, jcol, ierr = \ func(s, a, rowa, ptra, irow, jcol, ierr) if (ierr == 0): break nnz = nnz + ALLOCSIZE a = resize1d(a, nnz) rowa = resize1d(rowa, nnz) self.data = a self.rowind = rowa self.indptr = ptra self.shape = (M, N) # s = dok_matrix(arg1).tocsc(nzmax) # self.shape = s.shape # self.data = s.data # self.rowind = s.rowind # self.indptr = s.indptr else: raise ValueError, "dense array does not have rank 1 or 2" elif isspmatrix(arg1): s = arg1 if isinstance(s, csc_matrix): # do nothing but copy information self.shape = s.shape if copy: self.data = s.data.copy() self.rowind = s.rowind.copy() self.indptr = s.indptr.copy() else: self.data = s.data self.rowind = s.rowind self.indptr = s.indptr elif isinstance(s, csr_matrix): self.shape = s.shape func = getattr(sparsetools, s.ftype+'transp') self.data, self.rowind, self.indptr = \ func(s.shape[1], s.data, s.colind, s.indptr) else: temp = s.tocsc() self.data = temp.data self.rowind = temp.rowind self.indptr = temp.indptr self.shape = temp.shape elif type(arg1) == tuple: try: # Assume it's a tuple of matrix dimensions (M, N) (M, N) = arg1 M = int(M) # will raise TypeError if (data, ij) N = int(N) self.data = zeros((nzmax,), dtype) self.rowind = zeros((nzmax,), int) self.indptr = zeros((N+1,), int) self.shape = (M, N) except (ValueError, TypeError): try: # Try interpreting it as (data, ij) (s, ij) = arg1 assert isinstance(ij, ArrayType) and (rank(ij) == 2) and (shape(ij) == (len(s), 2)) temp = coo_matrix( s, ij, dims=dims, nzmax=nzmax, \ dtype=dtype).tocsc() self.shape = temp.shape self.data = temp.data self.rowind = temp.rowind self.indptr = temp.indptr except: try: # Try interpreting it as (data, rowind, indptr) (s, rowind, indptr) = arg1 if copy: self.data = array(s) self.rowind = array(rowind) self.indptr = array(indptr) else: self.data = asarray(s) self.rowind = asarray(rowind) self.indptr = asarray(indptr) except: raise ValueError, "unrecognized form for csc_matrix constructor" else: raise ValueError, "unrecognized form for csc_matrix constructor"
dtype = s.dtype.char func = getattr(sparsetools, _transtabl[dtype]+'fulltocsc')
dtype = s.dtype func = getattr(sparsetools, _transtabl[dtype.char]+'fulltocsc')
def __init__(self, arg1, dims=(None,None), nzmax=100, dtype='d', copy=False): spmatrix.__init__(self) if isdense(arg1): # Convert the dense matrix arg1 to CSC format if rank(arg1) == 2: s = asarray(arg1) if s.dtype.char not in 'fdFD': # Use a double array as the source (but leave it alone) s = s*1.0 if (rank(s) == 2): M, N = s.shape dtype = s.dtype.char func = getattr(sparsetools, _transtabl[dtype]+'fulltocsc') ierr = irow = jcol = 0 nnz = sum(ravel(s != 0.0)) a = zeros((nnz,), dtype) rowa = zeros((nnz,), 'i') ptra = zeros((N+1,), 'i') while 1: a, rowa, ptra, irow, jcol, ierr = \ func(s, a, rowa, ptra, irow, jcol, ierr) if (ierr == 0): break nnz = nnz + ALLOCSIZE a = resize1d(a, nnz) rowa = resize1d(rowa, nnz) self.data = a self.rowind = rowa self.indptr = ptra self.shape = (M, N) # s = dok_matrix(arg1).tocsc(nzmax) # self.shape = s.shape # self.data = s.data # self.rowind = s.rowind # self.indptr = s.indptr else: raise ValueError, "dense array does not have rank 1 or 2" elif isspmatrix(arg1): s = arg1 if isinstance(s, csc_matrix): # do nothing but copy information self.shape = s.shape if copy: self.data = s.data.copy() self.rowind = s.rowind.copy() self.indptr = s.indptr.copy() else: self.data = s.data self.rowind = s.rowind self.indptr = s.indptr elif isinstance(s, csr_matrix): self.shape = s.shape func = getattr(sparsetools, s.ftype+'transp') self.data, self.rowind, self.indptr = \ func(s.shape[1], s.data, s.colind, s.indptr) else: temp = s.tocsc() self.data = temp.data self.rowind = temp.rowind self.indptr = temp.indptr self.shape = temp.shape elif type(arg1) == tuple: try: # Assume it's a tuple of matrix dimensions (M, N) (M, N) = arg1 M = int(M) # will raise TypeError if (data, ij) N = int(N) self.data = zeros((nzmax,), dtype) self.rowind = zeros((nzmax,), int) self.indptr = zeros((N+1,), int) self.shape = (M, N) except (ValueError, TypeError): try: # Try interpreting it as (data, ij) (s, ij) = arg1 assert isinstance(ij, ArrayType) and (rank(ij) == 2) and (shape(ij) == (len(s), 2)) temp = coo_matrix( s, ij, dims=dims, nzmax=nzmax, \ dtype=dtype).tocsc() self.shape = temp.shape self.data = temp.data self.rowind = temp.rowind self.indptr = temp.indptr except: try: # Try interpreting it as (data, rowind, indptr) (s, rowind, indptr) = arg1 if copy: self.data = array(s) self.rowind = array(rowind) self.indptr = array(indptr) else: self.data = asarray(s) self.rowind = asarray(rowind) self.indptr = asarray(indptr) except: raise ValueError, "unrecognized form for csc_matrix constructor" else: raise ValueError, "unrecognized form for csc_matrix constructor"
temp = coo_matrix( s, ij, dims=dims, nzmax=nzmax, \ dtype=dtype).tocsc() self.shape = temp.shape self.data = temp.data self.rowind = temp.rowind self.indptr = temp.indptr except:
except (AssertionError, TypeError, ValueError):
def __init__(self, arg1, dims=(None,None), nzmax=100, dtype='d', copy=False): spmatrix.__init__(self) if isdense(arg1): # Convert the dense matrix arg1 to CSC format if rank(arg1) == 2: s = asarray(arg1) if s.dtype.char not in 'fdFD': # Use a double array as the source (but leave it alone) s = s*1.0 if (rank(s) == 2): M, N = s.shape dtype = s.dtype.char func = getattr(sparsetools, _transtabl[dtype]+'fulltocsc') ierr = irow = jcol = 0 nnz = sum(ravel(s != 0.0)) a = zeros((nnz,), dtype) rowa = zeros((nnz,), 'i') ptra = zeros((N+1,), 'i') while 1: a, rowa, ptra, irow, jcol, ierr = \ func(s, a, rowa, ptra, irow, jcol, ierr) if (ierr == 0): break nnz = nnz + ALLOCSIZE a = resize1d(a, nnz) rowa = resize1d(rowa, nnz) self.data = a self.rowind = rowa self.indptr = ptra self.shape = (M, N) # s = dok_matrix(arg1).tocsc(nzmax) # self.shape = s.shape # self.data = s.data # self.rowind = s.rowind # self.indptr = s.indptr else: raise ValueError, "dense array does not have rank 1 or 2" elif isspmatrix(arg1): s = arg1 if isinstance(s, csc_matrix): # do nothing but copy information self.shape = s.shape if copy: self.data = s.data.copy() self.rowind = s.rowind.copy() self.indptr = s.indptr.copy() else: self.data = s.data self.rowind = s.rowind self.indptr = s.indptr elif isinstance(s, csr_matrix): self.shape = s.shape func = getattr(sparsetools, s.ftype+'transp') self.data, self.rowind, self.indptr = \ func(s.shape[1], s.data, s.colind, s.indptr) else: temp = s.tocsc() self.data = temp.data self.rowind = temp.rowind self.indptr = temp.indptr self.shape = temp.shape elif type(arg1) == tuple: try: # Assume it's a tuple of matrix dimensions (M, N) (M, N) = arg1 M = int(M) # will raise TypeError if (data, ij) N = int(N) self.data = zeros((nzmax,), dtype) self.rowind = zeros((nzmax,), int) self.indptr = zeros((N+1,), int) self.shape = (M, N) except (ValueError, TypeError): try: # Try interpreting it as (data, ij) (s, ij) = arg1 assert isinstance(ij, ArrayType) and (rank(ij) == 2) and (shape(ij) == (len(s), 2)) temp = coo_matrix( s, ij, dims=dims, nzmax=nzmax, \ dtype=dtype).tocsc() self.shape = temp.shape self.data = temp.data self.rowind = temp.rowind self.indptr = temp.indptr except: try: # Try interpreting it as (data, rowind, indptr) (s, rowind, indptr) = arg1 if copy: self.data = array(s) self.rowind = array(rowind) self.indptr = array(indptr) else: self.data = asarray(s) self.rowind = asarray(rowind) self.indptr = asarray(indptr) except: raise ValueError, "unrecognized form for csc_matrix constructor" else: raise ValueError, "unrecognized form for csc_matrix constructor"
other = asarray(other) return self.transpose().dot(other.transpose()).transpose()
try: tr = other.transpose() except AttributeError: tr = asarray(other).transpose() return self.transpose().dot(tr).transpose()
def __rmul__(self, other): # other * self if isscalar(other) or (isdense(other) and rank(other)==0): new = self.copy() new.data = other * new.data new.dtype = new.data.dtype new.ftype = _transtabl[new.dtype.char] return new else: other = asarray(other) return self.transpose().dot(other.transpose()).transpose()
if (rank(other) != 1) or (len(other) != self.shape[1]): raise ValueError, "dimension mismatch"
def matvec(self, other): if isdense(other): if (rank(other) != 1) or (len(other) != self.shape[1]): raise ValueError, "dimension mismatch" func = getattr(sparsetools, self.ftype+'cscmux') y = func(self.data, self.rowind, self.indptr, other, self.shape[0]) return y elif isspmatrix(other): raise NotImplementedError, "use matmat() for sparse * sparse" else: raise TypeError, "need a dense vector"
if (rank(other) != 1) or (len(other) != self.shape[0]): raise ValueError, "dimension mismatch"
def rmatvec(self, other, conjugate=True): if isdense(other): if (rank(other) != 1) or (len(other) != self.shape[0]): raise ValueError, "dimension mismatch" func = getattr(sparsetools, self.ftype+'csrmux') if conjugate: cd = conj(self.data) else: cd = self.data y = func(cd, self.rowind, self.indptr, other) return y elif isspmatrix(other): raise NotImplementedError, "use matmat() for sparse * sparse" else: raise TypeError, "need a dense vector"
raise KeyError, "index out of bounds"
raise IndexError, "index out of bounds"
def __getitem__(self, key): if isinstance(key, types.TupleType): row = key[0] col = key[1] func = getattr(sparsetools, self.ftype+'cscgetel') M, N = self.shape if not (0<=row<M) or not (0<=col<N): raise KeyError, "index out of bounds" ind, val = func(self.data, self.rowind, self.indptr, row, col) return val #elif isinstance(key, type(3)): elif type(key) == int: return self.data[key] else: raise NotImplementedError
raise KeyError, "key out of bounds"
raise IndexError, "index out of bounds"
def __setitem__(self, key, val): if isinstance(key, types.TupleType): row = key[0] col = key[1] func = getattr(sparsetools, self.ftype+'cscsetel') M, N = self.shape if (row < 0): row = M + row if (col < 0): col = N + col if (row < 0) or (col < 0): raise IndexError, "index out of bounds" if (col >= N): self.indptr = resize1d(self.indptr, col+2) self.indptr[N+1:] = self.indptr[N] N = col+1 if (row >= M): M = row+1 self.shape = (M, N) nzmax = self.nzmax if (nzmax < self.nnz+1): # need more room alloc = max(1, self.allocsize) self.data = resize1d(self.data, nzmax + alloc) self.rowind = resize1d(self.rowind, nzmax + alloc) func(self.data, self.rowind, self.indptr, row, col, val) self._check() elif isinstance(key, types.IntType): if (key < self.nnz): self.data[key] = val else: raise KeyError, "key out of bounds" else: raise NotImplementedError