def _fmin(self): ''' xtol - difference between x for last and second last iteration ftol - same but for error function The nedler-mead simplex algorithm keeps track of the three best solutions. xtol and ftol is calculated base on the three last best solutions. Best minus the value of the second and third. Max of this. ''' with Stopwatch('\nOptimizing...'): out = opt.fmin(self.fmin_error_fun, self.get_x0(), args=(), **self.kwargs_fmin) [xopt, fopt, iterations, funcalls, warnflag, allvecs] = out #print xopt, fopt, allvecs self.data['xopt'].append(xopt) # append last self.data['fopt'].append(fopt) self.data['iterations'] = iterations self.data['funcalls'] = funcalls self.data['warnflag'] = warnflag self.data['allvecs'] = allvecs self.print_last(t=0)
def _Simulate(sim_time, chunksize=None): if chunksize: # print chunksize while sim_time > 0: if sim_time < chunksize: chunksize = sim_time # print 'inside', chunksize # with Barrier(): # if Rank()==0: # print 'Time left:{}'.format(sim_time) k = {'only_rank_0_mpi': True, 'relative_to': chunksize / 1000.} with Stopwatch('Time left {}'.format(sim_time), **k): nest.Simulate(chunksize) sim_time -= chunksize else: nest.Simulate(sim_time)
def _Connect_speed(pre, post, *args, **kwargs): def fun(pre, post, args, kwargs, sl): # args=[a[sl] for a in args] # print sl _Connect_speed_internal(pre[sl], post[sl], *[a[sl] for a in args], **kwargs) step = 10000 #n/chunks n = len(pre) chunks = int(numpy.ceil(n / float(step))) slice_list = [] for i in range(chunks): if i < chunks - 1: slice_list.append(slice(i * step, (i + 1) * step)) else: slice_list.append(slice(i * step, n)) from core.misc import Stopwatch # print 'hej' with Stopwatch('Connecting'): map(fun, [pre] * chunks, [post] * chunks, [args] * chunks, [kwargs] * chunks, slice_list)
''' Created on Sep 29, 2014 @author: mikael ''' import os import sys currdir = os.getcwd() basedir = '/'.join(currdir.split('/')[:-1]) from core import data_to_disk from core.misc import Stopwatch from core.parallel_excecution import Mockup_class from scripts_inhibition import base_Go_NoGo_compete import pprint pp = pprint.pprint # pp(sys.modules) fileName = sys.argv[1] print fileName obj, script = data_to_disk.pickle_load(fileName) # print 'Running '+str(obj)+' as ' + script with Stopwatch('Running ' + str(obj) + ' as ' + script): obj.do()
def _Connect_DC(pre, post, weights, delays, model, only_local=False): from itertools import izip tp, receptor = nest.GetDefaults(model, ['type', 'receptor_type']) if not only_local: # with Stopwatch('Connecting DC', **{'only_rank_0_mpi':True}): # post_ids=list(numpy.unique(post)) # status=GetStatus(list(numpy.unique(post)), 'local') # lock_up=dict(zip(post_ids,status)) # # dic={} # for d, s, t, w in izip(delays, pre, post, weights_input_rates): # if not lock_up[t]: # continue # # pp(lock_up) # if s not in dic.keys(): # dic[s]={'target':[t*1.0], # 'weight':[w], # 'delay':[d]} # else: # dic[s]['target'].append(t*1.0) # dic[s]['weight'].append(w) # dic[s]['delay'].append(d) # pp(dic) # key=dic.keys() # DataConnect(key, [dic[k] for k in key], model) with Stopwatch('Connecting DC', **{'only_rank_0_mpi': True}): post_ids = list(numpy.unique(post)) status = GetStatus(list(numpy.unique(post)), 'local') lock_up = dict(zip(post_ids, status)) step = 100000 #n/chunks n = len(pre) chunks = int(numpy.ceil(n / float(step))) slice_list = [] for i in range(chunks): if i < chunks - 1: slice_list.append(slice(i * step, (i + 1) * step)) else: slice_list.append(slice(i * step, n)) for s in slice_list: params = [{ 'delay': d, 'receptor': receptor, 'source': s, 'synapse_model': model, 'target': t, 'type': tp, 'weight': w } for s, t, d, w, in izip(pre[s], post[s], delays[s], weights[s]) if lock_up[t]] DataConnect(params) del params import gc gc.collect() elif only_local: # with Stopwatch('Connecting DC', **{'only_rank_0_mpi':True}): # # dic={} # for d, s, t, w in izip(delays, pre, post, weights_input_rates): # if s not in dic.keys(): # dic[s]={'target':[t], # 'weight':[w], # 'delay':[d]} # else: # dic[s]['target'].append(t) # dic[s]['weight'].append(w) # dic[s]['delay'].append(d) # # key, val=dic.items() # DataConnect(key, val, model) with Stopwatch('Connecting DC', **{'only_rank_0_mpi': True}): # step=20000 #n/chunks # n=len(pre) # chunks=int(numpy.ceil(n/float(step))) # slice_list=[] # for i in range(chunks): # if i<chunks-1: # slice_list.append(slice(i*step,(i+1)*step)) # else: # slice_list.append(slice(i*step, n)) # # # for s in slice_list: # params=[{'delay': d, # 'receptor': receptor, # 'source': s, # 'synapse_model': model, # 'target': t, # 'type': tp, # 'weight': w} for s, t, d, w, in izip(pre[s], # post[s], # delays[s], # weights_input_rates[s] # )] # DataConnect(params) # del params # import gc # gc.collect() # for s in slice_list: # lnt=nest.GetKernelStatus('local_num_threads') # nest.SetKernelStatus({'local_num_threads':1}) m = len(delays) params = map(_Connect_DC_fun, delays, [receptor] * m, pre, [model] * m, post, [tp] * m, weights) DataConnect(params) nest.SetKernelStatus({'local_num_threads': 1}) del params import gc gc.collect() print 'hej'
d = {} d[0] = nest.Create('aeif_cond_exp', 20000) nest.CopyModel('static_synapse', 'static') connect(d, chunks, type_conn) # my_nest.Connect(args[0], args[1], model='static', chunks=chunks) # args=get_pre_post(500,d[0], d[1] ) # nest.Connect(*args, model='tsodyks') # nest.Simulate(10000) # time.sleep(30) if __name__ == '__main__': # time.sleep(60) with Stopwatch('Connect 1'): gen_network(1, 'Connect') # nest.Simulate(1000) nest.ResetKernel() gc.collect() time.sleep(60) with Stopwatch('Connect 10'): gen_network(10, 'Connect') # nest.Simulate(1000) nest.ResetKernel() gc.collect() time.sleep(60) with Stopwatch('Connect 100'): gen_network(100, 'Connect')