def _generate_projections(net_id, gather_subprojections): txt = "" proj_tpl = """ %(pre)s & %(post)s & %(target)s & %(synapse)s & %(description)s \\\\ \\hline """ if gather_subprojections: projections = [] for proj in Global._network[net_id]['projections']: for existing_proj in projections: if proj.pre.name == existing_proj.pre.name and proj.post.name == existing_proj.post.name and proj.target == existing_proj.target : # TODO break else: projections.append(proj) else: projections = Global._network[net_id]['projections'] for proj in projections: # Find a name for the synapse if proj.synapse_type.name in Synapse._default_names.values(): # name not set synapse_name = "Synapse " + str(proj.synapse_type._rk_synapses_type) else: synapse_name = proj.synapse_type.name txt += proj_tpl % { 'pre': LatexParser.pop_name(proj.pre.name), 'post': LatexParser.pop_name(proj.post.name), 'target': LatexParser._format_list(proj.target, ' / '), 'synapse': synapse_name, 'description': proj.connector_description} return connectivity_template % {'projections_description': txt}
def _generate_population_parameters(net_id): txt = "" pop_tpl = """ %(name)s & $%(param)s$ & %(value)s \\\\ \\hline """ for rk, pop in enumerate(Global._network[net_id]['populations']): parameters = "" for idx, param in enumerate(pop.parameters): val = pop.init[param] if isinstance(val, (list, np.ndarray)): val = "$[" + str(np.array(val).min()) + ", " + str( np.array(val).max()) + "]$" parameters += pop_tpl % { 'name': LatexParser.pop_name(pop.name) if idx == 0 else "", 'param': LatexParser._latexify_name(param, []), 'value': val } txt += popparameters_template % { 'parameters': parameters, 'firstpopulation': "\hdr{3}{H}{Population parameters}\\\\ \\hline" if rk == 0 else "" } return txt
def _generate_projections(net_id, gather_subprojections): txt = "" proj_tpl = """ %(pre)s & %(post)s & %(target)s & %(synapse)s & %(description)s \\\\ \\hline """ if gather_subprojections: projections = [] for proj in Global._network[net_id]['projections']: for existing_proj in projections: if proj.pre.name == existing_proj.pre.name and proj.post.name == existing_proj.post.name and proj.target == existing_proj.target : # TODO break else: projections.append(proj) else: projections = Global._network[net_id]['projections'] for proj in projections: # Find a name for the synapse if proj.synapse_type.name in Synapse._default_names.values(): # name not set synapse_name = "Synapse " + str(proj.synapse_type._rk_synapses_type) else: synapse_name = proj.synapse_type.name txt += proj_tpl % { 'pre': LatexParser.pop_name(proj.pre.name), 'post': LatexParser.pop_name(proj.post.name), 'target': LatexParser._format_list(proj.target, ' / '), 'synapse': synapse_name, 'description': proj.connector_description} return connectivity_template % {'projections_description': txt}
def _generate_projection_parameters(net_id, gather_subprojections): txt = "" proj_tpl = """ %(name)s & $%(param)s$ & %(value)s \\\\ \\hline """ if gather_subprojections: projections = [] for proj in Global._network[net_id]['projections']: for existing_proj in projections: if proj.pre.name == existing_proj.pre.name and proj.post.name == existing_proj.post.name and proj.target == existing_proj.target: # TODO break else: projections.append(proj) else: projections = Global._network[net_id]['projections'] first = True for rk, proj in enumerate(projections): parameters = "" for idx, param in enumerate(proj.parameters): if param == 'w': continue if idx == 0: proj_name = "%(pre)s $\\rightarrow$ %(post)s with target %(target)s" % { 'pre': LatexParser.pop_name(proj.pre.name), 'post': LatexParser.pop_name(proj.post.name), 'target': LatexParser._format_list(proj.target, ' / ') } else: proj_name = "" val = proj.init[param] if isinstance(val, (list, np.ndarray)): val = "$[" + str(np.min(val)) + ", " + str(np.max(val)) + "]$" parameters += proj_tpl % { 'name': proj_name, 'param': LatexParser._latexify_name(param, []), 'value': val } if parameters != "": txt += projparameters_template % { 'parameters': parameters, 'firstprojection': "\hdr{3}{H}{Projection parameters}\\\\ \\hline" if first else "" } first = False return txt
def _process_variables(variables, neuron=True): eqs = "" for var in variables: # Min value if 'min' in var['bounds'].keys(): min_val = ", minimum: " + str(var['bounds']['min']) else: min_val ="" # Max value if 'max' in var['bounds'].keys(): max_val = ", maximum: " + str(var['bounds']['max']) else: max_val ="" # Method if var['ode']: method = ", " + find_method(var) + " numerical method" else: method = "" eqs += """ * Variable %(name)s : %(locality)s, initial value: %(init)s%(min)s%(max)s%(method)s $$ %(code)s $$ """ % { 'name': "$" + LatexParser._latexify_name(var['name'], []) + "$", 'code': var['latex'], 'locality': _adapt_locality_neuron(var['locality']) if neuron else _adapt_locality_synapse(var['locality']), 'init': var['init'], 'min': min_val, 'max': max_val, 'method': method} return eqs
def _process_variables(variables, neuron=True): eqs = "" for var in variables: # Min value if 'min' in var['bounds'].keys(): min_val = ", minimum: " + str(var['bounds']['min']) else: min_val ="" # Max value if 'max' in var['bounds'].keys(): max_val = ", maximum: " + str(var['bounds']['max']) else: max_val ="" # Method if var['ode']: method = ", " + find_method(var) + " numerical method" else: method = "" eqs += """ * Variable %(name)s : %(locality)s, initial value: %(init)s%(min)s%(max)s%(method)s $$ %(code)s $$ """ % { 'name': "$" + LatexParser._latexify_name(var['name'], []) + "$", 'code': var['latex'], 'locality': _adapt_locality_neuron(var['locality']) if neuron else _adapt_locality_synapse(var['locality']), 'init': var['init'], 'min': min_val, 'max': max_val, 'method': method} return eqs
def _generate_populations(net_id): def format_size(pop): size = str(pop.size) if pop.dimension >1: size += ' (' for d in range(pop.dimension): size += str(pop.geometry[d]) + '*' size = size.rsplit('*', 1)[0] + ')' return size txt = "" pop_tpl = """ %(pop_name)s & %(neuron_type)s & $N_{\\text{%(pop_name)s}}$ = %(size)s \\\\ \\hline """ for pop in Global._network[net_id]['populations']: # Find a name for the neuron if pop.neuron_type.name in Neuron._default_names.values(): # name not set neuron_name = "Neuron " + str(pop.neuron_type._rk_neurons_type) else: neuron_name = pop.neuron_type.name txt += pop_tpl % { 'pop_name': LatexParser.pop_name(pop.name), 'neuron_type': neuron_name, 'size': format_size(pop)} return populations_template % {'populations_description': txt}
def _generate_populations(net_id): def format_size(pop): size = str(pop.size) if pop.dimension >1: size += ' (' for d in range(pop.dimension): size += str(pop.geometry[d]) + '*' size = size.rsplit('*', 1)[0] + ')' return size txt = "" pop_tpl = """ %(pop_name)s & %(neuron_type)s & $N_{\\text{%(pop_name)s}}$ = %(size)s \\\\ \\hline """ for pop in Global._network[net_id]['populations']: # Find a name for the neuron if pop.neuron_type.name in Neuron._default_names.values(): # name not set neuron_name = "Neuron " + str(pop.neuron_type._rk_neurons_type) else: neuron_name = pop.neuron_type.name txt += pop_tpl % { 'pop_name': LatexParser.pop_name(pop.name), 'neuron_type': neuron_name, 'size': format_size(pop)} return populations_template % {'populations_description': txt}
def _generate_functions(net_id): functions = "" if len(Global._objects['functions']) == 0: return functions for name, func in Global._objects['functions']: functions += LatexParser._process_functions(func) + "\n" return functions_template % {'parameters': functions, 'firstfunction': "\hdr{1}{G}{Functions}\\\\ \\hline"}
def _generate_functions(net_id): functions = "" if len(Global._objects['functions']) == 0: return functions for name, func in Global._objects['functions']: functions += LatexParser._process_functions(func) + "\n" return functions_template % {'parameters': functions, 'firstfunction': "\hdr{1}{G}{Functions}\\\\ \\hline"}
def _generate_summary(net_id): "part A" population_names = str(len(Global._network[net_id]['populations'])) + ': ' connectivity = "" neuron_models = "" synapse_models = "" # List the names of all populations for pop in Global._network[net_id]['populations']: # population name population_names += LatexParser.pop_name(pop.name) + ", " population_names = population_names[:-2] # suppress the last , # List all BOLD recordings measurements = "" # List all neuron types neuron_model_names = [] for neur in Global._objects['neurons']: # bold models sorted in measurements if isinstance(neur, BoldModel): if neur._model_instantiated: measurements += neur.name + ', ' # neuron model else: neuron_model_names.append(neur.name) for neur in list(set(neuron_model_names)): neuron_models += neur + ', ' # suppress the last , measurements = measurements[:-2] neuron_models = neuron_models[:-2] list_connectivity = [] list_synapse_models = [] for proj in Global._network[net_id]['projections']: list_connectivity.append(proj.connector_name) if not proj.synapse_type.name in list(Synapse._default_names.values()) + ['-']: list_synapse_models.append(proj.synapse_type.name) for con in list(set(list_connectivity)): connectivity += con + ', ' for syn in list(set(list_synapse_models)): synapse_models += syn + ', ' connectivity = connectivity[:-2] synapse_models = synapse_models[:-2] # suppress the last , # Write the summary txt = summary_template % { 'population_names' : population_names, 'connectivity' : connectivity, 'neuron_models' : neuron_models, 'synapse_models' : synapse_models, 'measurements': measurements } return txt
def _generate_projection_parameters(net_id, gather_subprojections): txt = "" proj_tpl = """ %(name)s & $%(param)s$ & %(value)s \\\\ \\hline """ if gather_subprojections: projections = [] for proj in Global._network[net_id]['projections']: for existing_proj in projections: if proj.pre.name == existing_proj.pre.name and proj.post.name == existing_proj.post.name and proj.target == existing_proj.target : # TODO break else: projections.append(proj) else: projections = Global._network[net_id]['projections'] first = True for rk, proj in enumerate(projections): parameters = "" for idx, param in enumerate(proj.parameters): if param == 'w': continue if idx == 0: proj_name = "%(pre)s $\\rightarrow$ %(post)s with target %(target)s" % { 'pre': LatexParser.pop_name(proj.pre.name), 'post': LatexParser.pop_name(proj.post.name), 'target': LatexParser._format_list(proj.target, ' / ')} else: proj_name = "" val = proj.init[param] if isinstance(val, (list, np.ndarray)): val = "$[" + str(np.min(val)) + ", " + str(np.max(val)) + "]$" parameters += proj_tpl % {'name': proj_name, 'param': LatexParser._latexify_name(param, []), 'value': val} if parameters != "": txt += projparameters_template % {'parameters': parameters, 'firstprojection': "\hdr{3}{H}{Projection parameters}\\\\ \\hline" if first else ""} first = False return txt
def _generate_constants(net_id): cst_tpl = """ & $%(param)s$ & %(value)s \\\\ \\hline """ parameters = "" if len(Global._objects['constants']) == 0: return "" for constant in Global._objects['constants']: parameters += cst_tpl % {'param': LatexParser._latexify_name(constant.name, []), 'value': constant.value} txt = constants_template % {'parameters': parameters} return txt
def _generate_constants(net_id): cst_tpl = """ & $%(param)s$ & %(value)s \\\\ \\hline """ parameters = "" if len(Global._objects['constants']) == 0: return "" for constant in Global._objects['constants']: parameters += cst_tpl % {'param': LatexParser._latexify_name(constant.name, []), 'value': constant.value} txt = constants_template % {'parameters': parameters} return txt
def _generate_population_parameters(net_id): txt = "" pop_tpl = """ %(name)s & $%(param)s$ & %(value)s \\\\ \\hline """ for rk, pop in enumerate(Global._network[net_id]['populations']): parameters = "" for idx, param in enumerate(pop.parameters): val = pop.init[param] if isinstance(val, (list, np.ndarray)): val = "$[" + str(np.array(val).min()) + ", " + str(np.array(val).max()) + "]$" parameters += pop_tpl % {'name': LatexParser.pop_name(pop.name) if idx==0 else "", 'param': LatexParser._latexify_name(param, []), 'value': val} txt += popparameters_template % {'parameters': parameters, 'firstpopulation': "\hdr{3}{H}{Population parameters}\\\\ \\hline" if rk==0 else ""} return txt
def _generate_summary(net_id): "part A" population_names = str(len(Global._network[net_id]['populations'])) + ': ' connectivity = "" neuron_models = "" synapse_models = "" # List the names of all populations for pop in Global._network[net_id]['populations']: # population name population_names += LatexParser.pop_name(pop.name) + ", " population_names = population_names[:-2] # suppress the last , # List all neuron types neuron_model_names = [] for neur in Global._objects['neurons']: neuron_model_names.append(neur.name) for neur in list(set(neuron_model_names)): neuron_models += neur + ', ' neuron_models = neuron_models[:-2] # suppress the last , list_connectivity = [] list_synapse_models = [] for proj in Global._network[net_id]['projections']: list_connectivity.append(proj.connector_name) if not proj.synapse_type.name in list(Synapse._default_names.values()) + ['-']: list_synapse_models.append(proj.synapse_type.name) for con in list(set(list_connectivity)): connectivity += con + ', ' for syn in list(set(list_synapse_models)): synapse_models += syn + ', ' connectivity = connectivity[:-2] synapse_models = synapse_models[:-2] # suppress the last , # Write the summary txt = summary_template % { 'population_names' : population_names, 'connectivity' : connectivity, 'neuron_models' : neuron_models, 'synapse_models' : synapse_models } return txt
def _generate_parameters(net_id, gather_subprojections): txt = """ # Parameters """ # Constants if len(Global._objects['constants']) > 0: txt += """ ## Constants """ constants_list = [ ["$" + LatexParser._latexify_name(constant.name, []) + "$", constant.value] for constant in Global._objects['constants']] constants_headers = ["Name", "Value"] txt += _make_table(constants_headers, constants_list) # Population parameters txt += """ ## Population parameters """ parameters_list = [] for rk, pop in enumerate(Global._network[net_id]['populations']): neuron_name = "Neuron " + str(pop.neuron_type._rk_neurons_type) if pop.neuron_type.name in Neuron._default_names.values() \ else pop.neuron_type.name for idx, param in enumerate(pop.parameters): val = pop.init[param] if isinstance(val, (list, np.ndarray)): val = "$[" + str(np.array(val).min()) + ", " + str(np.array(val).max()) + "]$" parameters_list.append( [ LatexParser.pop_name(pop.name) if idx==0 else "", neuron_name if idx==0 else "", "$" + LatexParser._latexify_name(param, []) + "$", val ] ) population_headers = ["Population", "Neuron type", "Name", "Value"] txt += _make_table(population_headers, parameters_list) # Projection parameters txt += """ ## Projection parameters """ if gather_subprojections: projections = [] for proj in Global._network[net_id]['projections']: for existing_proj in projections: if proj.pre.name == existing_proj.pre.name and proj.post.name == existing_proj.post.name \ and proj.target == existing_proj.target : # TODO break else: projections.append(proj) else: projections = Global._network[net_id]['projections'] parameters_list = [] for rk, proj in enumerate(projections): for idx, param in enumerate(proj.parameters): if param == 'w': continue if idx == 0: proj_name = "%(pre)s $\\rightarrow$ %(post)s with target %(target)s" % { 'pre': LatexParser.pop_name(proj.pre.name), 'post': LatexParser.pop_name(proj.post.name), 'target': LatexParser._format_list(proj.target, ' / ')} else: proj_name = "" synapse_name = "Synapse " + str(proj.synapse_type._rk_synapses_type) if proj.synapse_type.name in Synapse._default_names.values() \ else proj.synapse_type.name val = proj.init[param] if isinstance(val, (list, np.ndarray)): val = "$[" + str(np.array(val).min()) + ", " + str(np.array(val).max()) + "]$" parameters_list.append( [ proj_name, synapse_name if idx == 0 else "", "$" + LatexParser._latexify_name(param, []) + "$", val ] ) projection_headers = ["Projection", "Synapse type", "Name", "Value"] txt += _make_table(projection_headers, parameters_list) return txt
def _generate_summary(net_id): txt = """ # Structure of the network """ # General information backend = 'default' if Global.config['paradigm'] == 'cuda': backend = "CUDA" elif Global.config['paradigm'] == "openmp" and Global.config['num_threads'] > 1: backend = "OpenMP" txt +=""" * ANNarchy %(version)s using the %(backend)s backend. * Numerical step size: %(dt)s ms. """ % {'version': ANNarchy.__release__, 'backend': backend, 'dt': Global.config['dt']} # Populations if len(Global._network[net_id]['populations']) > 0: headers = ["Population", "Size", "Neuron type"] populations = [] for pop in Global._network[net_id]['populations']: # Find a name for the neuron neuron_name = "Neuron " + str(pop.neuron_type._rk_neurons_type) if pop.neuron_type.name in Neuron._default_names.values() \ else pop.neuron_type.name populations.append([ pop.name, pop.geometry if len(pop.geometry)>1 else pop.size, neuron_name]) txt += """ ## Populations """ txt += _make_table(headers, populations) # Projections if len(Global._network[net_id]['projections']) > 0 : headers = ["Source", "Destination", "Target", "Synapse type", "Pattern"] projections = [] for proj in Global._network[net_id]['projections']: # Find a name for the synapse synapse_name = "Synapse " + str(proj.synapse_type._rk_synapses_type) if proj.synapse_type.name in Synapse._default_names.values() \ else proj.synapse_type.name projections.append([ proj.pre.name, proj.post.name, LatexParser._format_list(proj.target, ' / '), synapse_name, proj.connector_description ]) txt += """ ## Projections """ txt += _make_table(headers, projections) # Monitors if len(Global._network[net_id]['monitors']) > 0: headers = ["Object", "Variables", "Period"] monitors = [] for monitor in Global._network[net_id]['monitors']: monitors.append([ monitor.object.name + (" (subset)" if isinstance(monitor.object, PopulationView) else ""), LatexParser._format_list(monitor.variables, ', '), monitor.period ]) txt += """ ## Monitors """ txt += _make_table(headers, monitors) # Functions if len(Global._objects['functions']) > 0 : txt += """## Functions """ for name, func in Global._objects['functions']: txt += LatexParser._process_functions(func, begin="$$", end="$$\n\n") return txt
def _generate_synapse_models(net_id): txt = """ # Synapse models """ for idx, synapse in enumerate(Global._objects['synapses']): # Do not document default synapses if synapse.name == "-": continue # Find a name for the synapse synapse_name = "Synapse " + str(synapse._rk_synapses_type) if synapse.name in Synapse._default_names.values() else synapse.name # Description description = synapse.short_description if description == None: description = "Spiking synapse." if synapse.type == 'spike' else 'Rate-coded synapse' # Parameters parameters = extract_parameters(synapse.parameters, synapse.extra_values) parameters_list = [ ["$" + LatexParser._latexify_name(param['name'], []) + "$", param['init'], _adapt_locality_synapse(param['locality']), param['ctype']] for param in parameters] parameters_headers = ["Name", "Default value", "Locality", "Type"] parameters_table = _make_table(parameters_headers, parameters_list) if len(parameters) == 0: parameters_table = "$$\\varnothing$$" # Generate the code for the equations psp, variables, pre_desc, post_desc = LatexParser._process_synapse_equations(synapse) eqs = _process_variables(variables, neuron = False) # PSP if synapse.type == "rate": psp = """ **Weighted sum:** $$%(transmission)s$$ """ % {'transmission': psp} elif synapse.type == "spike" and psp != "": psp = """ **Continuous transmission:** $$%(transmission)s$$ """ % {'transmission': psp} else: psp = "" # Pre- and post-events if synapse.type == "spike": if len(pre_desc) > 0: eqs += """ **Pre-synaptic event at $t_\\text{pre} + d$:** """ for pre in pre_desc: eqs += "$$"+pre+"$$\n" if len(post_desc) > 0: eqs += """ **Post-synaptic event at $t_\\text{post}$:** """ for post in post_desc: eqs += "$$"+post+"$$\n" # Finalize the template txt += synapse_tpl % { 'name': synapse_name, 'description': description, 'psp': psp, 'parameters': parameters_table, 'eqs': eqs} return txt
def _generate_synapse_models(net_id): firstsynapse = "" synapses = "" firstsynapse = "\\hdr{2}{E}{Synapse Models}\\\\ \\hline" synapse_tpl = """ \\noindent \\begin{tabularx}{\\linewidth}{|p{0.15\\linewidth}|X|}\\hline %(firstsynapse)s \\textbf{Name} & %(name)s \\\\ \\hline \\textbf{Type} & %(description)s\\\\ \\hline %(psp)s %(variables)s %(preevent)s %(postevent)s %(functions)s \\end{tabularx} \\vspace{2ex} """ for idx, synapse in enumerate(Global._objects['synapses']): # Do not document default synapses if synapse.name == "-": continue # Find a name for the synapse if synapse.name in Synapse._default_names.values(): # name not set synapse_name = "Synapse " + str(synapse._rk_synapses_type) else: synapse_name = synapse.name # Generate the code for the equations psp, variables, pre_desc, post_desc = LatexParser._process_synapse_equations(synapse) eqs = "" for var in variables: eqs += """ \\begin{dmath*} %(eq)s \\end{dmath*} """ % {'eq': var['latex']} variables_eqs = """ %(eqs)s \\\\ \\hline """ % {'eqs': eqs} # Synaptic variables variables = """ \\textbf{Equations} & %(variables)s \\\\ \\hline""" % {'variables':eqs} if eqs != "" else "" # PSP if psp != "": psp_code = """ \\textbf{PSP} & \\begin{dmath*} %(psp)s \\end{dmath*} \\\\ \\hline""" % {'psp': psp} else: psp_code = "" # Spiking neurons have extra fields for the event-driven if synapse.type == 'spike': if len(pre_desc) > 0: txt_pre = "" for l in pre_desc: txt_pre += """ \\begin{dmath*} %(eq)s \\end{dmath*} """ % {'eq': l} preevent = """ \\textbf{Pre-synaptic event} & %(preevent)s \\\\ \\hline """ % {'preevent': txt_pre} else: preevent = "" if len(post_desc) > 0: txt_post = "" for l in post_desc: txt_post += """ \\begin{dmath*} %(eq)s \\end{dmath*} """ % {'eq': l} postevent = """ \\textbf{Post-synaptic event} & %(postevent)s \\\\ \\hline """ % {'postevent': txt_post} else: postevent = "" else: preevent = "" postevent = "" # Possible functions functions = "" if not synapse.functions == None: functions = """ \\textbf{Functions} & %(functions)s \\\\ \\hline """ % {'functions': LatexParser._process_functions(synapse.functions)} # Build the dictionary desc = { 'name': synapse_name, 'description': synapse.short_description, 'firstsynapse': firstsynapse if idx == 0 else "", 'variables': variables, 'psp': psp_code, 'preevent': preevent, 'postevent': postevent, 'functions': functions } # Generate the code synapses += synapse_tpl % desc return synapses
def _generate_synapse_models(net_id): txt = """ # Synapse models """ for idx, synapse in enumerate(Global._objects['synapses']): # Do not document default synapses if synapse.name == "-": continue # Find a name for the synapse synapse_name = "Synapse " + str(synapse._rk_synapses_type) if synapse.name in Synapse._default_names.values() else synapse.name # Description description = synapse.short_description if description == None: description = "Spiking synapse." if synapse.type == 'spike' else 'Rate-coded synapse' # Parameters parameters = extract_parameters(synapse.parameters, synapse.extra_values) parameters_list = [ ["$" + LatexParser._latexify_name(param['name'], []) + "$", param['init'], _adapt_locality_synapse(param['locality']), param['ctype']] for param in parameters] parameters_headers = ["Name", "Default value", "Locality", "Type"] parameters_table = _make_table(parameters_headers, parameters_list) if len(parameters) == 0: parameters_table = "$$\\varnothing$$" # Generate the code for the equations psp, variables, pre_desc, post_desc = LatexParser._process_synapse_equations(synapse) eqs = _process_variables(variables, neuron = False) # PSP if synapse.type == "rate": psp = """ **Weighted sum:** $$%(transmission)s$$ """ % {'transmission': psp} elif synapse.type == "spike" and psp != "": psp = """ **Continuous transmission:** $$%(transmission)s$$ """ % {'transmission': psp} else: psp = "" # Pre- and post-events if synapse.type == "spike": if len(pre_desc) > 0: eqs += """ **Pre-synaptic event at $t_\\text{pre} + d$:** """ for pre in pre_desc: eqs += "$$"+pre+"$$\n" if len(post_desc) > 0: eqs += """ **Post-synaptic event at $t_\\text{post}$:** """ for post in post_desc: eqs += "$$"+post+"$$\n" # Finalize the template txt += synapse_tpl % { 'name': synapse_name, 'description': description, 'psp': psp, 'parameters': parameters_table, 'eqs': eqs} return txt
def _generate_neuron_models(net_id): neurons = "" firstneuron = "\\hdr{2}{D}{Neuron Models}\\\\ \\hline" neuron_tpl = """ \\noindent \\begin{tabularx}{\\linewidth}{|p{0.15\\linewidth}|X|}\\hline %(firstneuron)s \\textbf{Name} & %(name)s \\\\ \\hline \\textbf{Type} & %(description)s\\\\ \\hline \\textbf{%(equation_type)s} & %(variables)s %(spike)s %(functions)s \\end{tabularx} \\vspace{2ex} """ for idx, neuron in enumerate(Global._objects['neurons']): # Name if neuron.name in Neuron._default_names.values(): # name not set neuron_name = "Neuron " + str(neuron._rk_neurons_type) else: neuron_name = neuron.name # Generate the code for the equations variables, spike_condition, spike_reset = LatexParser._process_neuron_equations(neuron) eqs = "" for var in variables: eqs += """ \\begin{dmath*} %(eq)s \\end{dmath*} """ % {'eq': var['latex']} variables_eqs = """ %(eqs)s \\\\ \\hline """ % {'eqs': eqs} # Spiking neurons have an extra field for the spike condition spike_extra = "" if neuron.type == 'spike': spike_code = "If $" + spike_condition + "$ or $t \leq t^* + t_{\\text{refractory}}$:" # Reset spike_code += """ \\begin{enumerate} \\item Emit a spike at time $t^*$""" for var in spike_reset: spike_code += """ \\item $""" + var + "$" spike_code += """ \\end{enumerate}""" spike_extra = """ \\textbf{Spiking} & %(spike)s \\\\ \\hline """ % {'spike': spike_code} # Possible function functions = "" if not neuron.functions == None: functions = """ \\textbf{Functions} & %(functions)s \\\\ \\hline """ % {'functions': LatexParser._process_functions(neuron.functions)} # Build the dictionary desc = { 'name': neuron_name, 'description': neuron.short_description, 'firstneuron': firstneuron if idx ==0 else "", 'variables': variables_eqs, 'spike': spike_extra, 'functions': functions, 'equation_type': "Subthreshold dynamics" if neuron.type == 'spike' else 'Equations' } # Generate the code depending on the neuron position neurons += neuron_tpl % desc return neurons
def _generate_neuron_models(net_id): txt = """ # Neuron models """ for idx, neuron in enumerate(Global._objects['neurons']): # Name if neuron.name in Neuron._default_names.values(): # name not set neuron_name = "Neuron " + str(neuron._rk_neurons_type) else: neuron_name = neuron.name # Description description = neuron.short_description if description == None: description = "Spiking neuron." if neuron.type == 'spike' else 'Rate-coded neuron' # Parameters parameters = extract_parameters(neuron.parameters, neuron.extra_values) parameters_list = [ ["$" + LatexParser._latexify_name(param['name'], []) + "$", param['init'], _adapt_locality_neuron(param['locality']), param['ctype']] for param in parameters] parameters_headers = ["Name", "Default value", "Locality", "Type"] parameters_table = _make_table(parameters_headers, parameters_list) if len(parameters) == 0: parameters_table = "$$\\varnothing$$" # Generate the code for the equations variables, spike_condition, spike_reset = LatexParser._process_neuron_equations(neuron) eqs = _process_variables(variables, neuron=True) # Spiking neurons if neuron.type == 'spike': reset_txt = "* Emit a spike a time $t$.\n" for r in spike_reset: reset_txt += "* $" + r + "$\n" eqs += """ **Spike emission:** if $%(condition)s$ : %(reset)s """ % {'condition': spike_condition, 'reset': reset_txt} # Possible function if not neuron.functions == None: eqs += """ **Functions** %(functions)s """ % {'functions': LatexParser._process_functions(neuron.functions, begin="$$", end="$$\n\n")} # Finalize the template txt += neuron_tpl % { 'name': neuron_name, 'description': description, 'parameters': parameters_table, 'eqs': eqs} return txt
def _generate_neuron_models(net_id): txt = """ # Neuron models """ for idx, neuron in enumerate(Global._objects['neurons']): # Name if neuron.name in Neuron._default_names.values(): # name not set neuron_name = "Neuron " + str(neuron._rk_neurons_type) else: neuron_name = neuron.name # Description description = neuron.short_description if description == None: description = "Spiking neuron." if neuron.type == 'spike' else 'Rate-coded neuron' # Parameters parameters = extract_parameters(neuron.parameters, neuron.extra_values) parameters_list = [ ["$" + LatexParser._latexify_name(param['name'], []) + "$", param['init'], _adapt_locality_neuron(param['locality']), param['ctype']] for param in parameters] parameters_headers = ["Name", "Default value", "Locality", "Type"] parameters_table = _make_table(parameters_headers, parameters_list) if len(parameters) == 0: parameters_table = "$$\\varnothing$$" # Generate the code for the equations variables, spike_condition, spike_reset = LatexParser._process_neuron_equations(neuron) eqs = _process_variables(variables, neuron=True) # Spiking neurons if neuron.type == 'spike': reset_txt = "* Emit a spike a time $t$.\n" for r in spike_reset: reset_txt += "* $" + r + "$\n" eqs += """ **Spike emission:** if $%(condition)s$ : %(reset)s """ % {'condition': spike_condition, 'reset': reset_txt} # Possible function if not neuron.functions == None: eqs += """ **Functions** %(functions)s """ % {'functions': LatexParser._process_functions(neuron.functions, begin="$$", end="$$\n\n")} # Finalize the template txt += neuron_tpl % { 'name': neuron_name, 'description': description, 'parameters': parameters_table, 'eqs': eqs} return txt
def _generate_neuron_models(net_id): neurons = "" firstneuron = "\\hdr{2}{D}{Neuron Models}\\\\ \\hline" neuron_tpl = """ \\noindent \\begin{tabularx}{\\linewidth}{|p{0.15\\linewidth}|X|}\\hline %(firstneuron)s \\textbf{Name} & %(name)s \\\\ \\hline \\textbf{Type} & %(description)s\\\\ \\hline \\textbf{%(equation_type)s} & %(variables)s %(spike)s %(functions)s \\end{tabularx} \\vspace{2ex} """ first_neuron = True for neuron in Global._objects['neurons']: # skip bold models if isinstance(neuron, BoldModel): continue # Name if neuron.name in Neuron._default_names.values(): # name not set neuron_name = "Neuron " + str(neuron._rk_neurons_type) else: neuron_name = neuron.name # Generate the code for the equations variables, spike_condition, spike_reset = LatexParser._process_neuron_equations(neuron) eqs = "" for var in variables: eqs += """ \\begin{dmath*} %(eq)s \\end{dmath*} """ % {'eq': var['latex']} variables_eqs = """ %(eqs)s \\\\ \\hline """ % {'eqs': eqs} # Spiking neurons have an extra field for the spike condition spike_extra = "" if neuron.type == 'spike': spike_code = "If $" + spike_condition + "$ or $t \leq t^* + t_{\\text{refractory}}$:" # Reset spike_code += """ \\begin{enumerate} \\item Emit a spike at time $t^*$""" for var in spike_reset: spike_code += """ \\item $""" + var + "$" spike_code += """ \\end{enumerate}""" spike_extra = """ \\textbf{Spiking} & %(spike)s \\\\ \\hline """ % {'spike': spike_code} # Possible function functions = "" if not neuron.functions == None: functions = """ \\textbf{Functions} & %(functions)s \\\\ \\hline """ % {'functions': LatexParser._process_functions(neuron.functions)} # Build the dictionary desc = { 'name': neuron_name, 'description': neuron.short_description, 'firstneuron': firstneuron if first_neuron else "", 'variables': variables_eqs, 'spike': spike_extra, 'functions': functions, 'equation_type': "Subthreshold dynamics" if neuron.type == 'spike' else 'Equations' } # Generate the code depending on the neuron position neurons += neuron_tpl % desc # first_neuron = False, to prevent multiple header first_neuron = False return neurons
def _generate_parameters(net_id, gather_subprojections): txt = """ # Parameters """ # Constants if len(Global._objects['constants']) > 0: txt += """ ## Constants """ constants_list = [ ["$" + LatexParser._latexify_name(constant.name, []) + "$", constant.value] for constant in Global._objects['constants']] constants_headers = ["Name", "Value"] txt += _make_table(constants_headers, constants_list) # Population parameters txt += """ ## Population parameters """ parameters_list = [] for rk, pop in enumerate(Global._network[net_id]['populations']): neuron_name = "Neuron " + str(pop.neuron_type._rk_neurons_type) if pop.neuron_type.name in Neuron._default_names.values() \ else pop.neuron_type.name for idx, param in enumerate(pop.parameters): val = pop.init[param] if isinstance(val, (list, np.ndarray)): val = "$[" + str(np.array(val).min()) + ", " + str(np.array(val).max()) + "]$" parameters_list.append( [ LatexParser.pop_name(pop.name) if idx==0 else "", neuron_name if idx==0 else "", "$" + LatexParser._latexify_name(param, []) + "$", val ] ) population_headers = ["Population", "Neuron type", "Name", "Value"] txt += _make_table(population_headers, parameters_list) # Projection parameters txt += """ ## Projection parameters """ if gather_subprojections: projections = [] for proj in Global._network[net_id]['projections']: for existing_proj in projections: if proj.pre.name == existing_proj.pre.name and proj.post.name == existing_proj.post.name \ and proj.target == existing_proj.target : # TODO break else: projections.append(proj) else: projections = Global._network[net_id]['projections'] parameters_list = [] for rk, proj in enumerate(projections): for idx, param in enumerate(proj.parameters): if param == 'w': continue if idx == 0: proj_name = "%(pre)s $\\rightarrow$ %(post)s with target %(target)s" % { 'pre': LatexParser.pop_name(proj.pre.name), 'post': LatexParser.pop_name(proj.post.name), 'target': LatexParser._format_list(proj.target, ' / ')} else: proj_name = "" synapse_name = "Synapse " + str(proj.synapse_type._rk_synapses_type) if proj.synapse_type.name in Synapse._default_names.values() \ else proj.synapse_type.name val = proj.init[param] if isinstance(val, (list, np.ndarray)): val = "$[" + str(np.array(val).min()) + ", " + str(np.array(val).max()) + "]$" parameters_list.append( [ proj_name, synapse_name if idx == 0 else "", "$" + LatexParser._latexify_name(param, []) + "$", val ] ) projection_headers = ["Projection", "Synapse type", "Name", "Value"] txt += _make_table(projection_headers, parameters_list) return txt
def _generate_synapse_models(net_id): firstsynapse = "" synapses = "" firstsynapse = "\\hdr{2}{E}{Synapse Models}\\\\ \\hline" synapse_tpl = """ \\noindent \\begin{tabularx}{\\linewidth}{|p{0.15\\linewidth}|X|}\\hline %(firstsynapse)s \\textbf{Name} & %(name)s \\\\ \\hline \\textbf{Type} & %(description)s\\\\ \\hline %(psp)s %(variables)s %(preevent)s %(postevent)s %(functions)s \\end{tabularx} \\vspace{2ex} """ for idx, synapse in enumerate(Global._objects['synapses']): # Do not document default synapses if synapse.name == "-": continue # Find a name for the synapse if synapse.name in Synapse._default_names.values(): # name not set synapse_name = "Synapse " + str(synapse._rk_synapses_type) else: synapse_name = synapse.name # Generate the code for the equations psp, variables, pre_desc, post_desc = LatexParser._process_synapse_equations(synapse) eqs = "" for var in variables: eqs += """ \\begin{dmath*} %(eq)s \\end{dmath*} """ % {'eq': var['latex']} variables_eqs = """ %(eqs)s \\\\ \\hline """ % {'eqs': eqs} # Synaptic variables variables = """ \\textbf{Equations} & %(variables)s \\\\ \\hline""" % {'variables':eqs} if eqs != "" else "" # PSP if psp != "": psp_code = """ \\textbf{PSP} & \\begin{dmath*} %(psp)s \\end{dmath*} \\\\ \\hline""" % {'psp': psp} else: psp_code = "" # Spiking neurons have extra fields for the event-driven if synapse.type == 'spike': if len(pre_desc) > 0: txt_pre = "" for l in pre_desc: txt_pre += """ \\begin{dmath*} %(eq)s \\end{dmath*} """ % {'eq': l} preevent = """ \\textbf{Pre-synaptic event} & %(preevent)s \\\\ \\hline """ % {'preevent': txt_pre} else: preevent = "" if len(post_desc) > 0: txt_post = "" for l in post_desc: txt_post += """ \\begin{dmath*} %(eq)s \\end{dmath*} """ % {'eq': l} postevent = """ \\textbf{Post-synaptic event} & %(postevent)s \\\\ \\hline """ % {'postevent': txt_post} else: postevent = "" else: preevent = "" postevent = "" # Possible functions functions = "" if not synapse.functions == None: functions = """ \\textbf{Functions} & %(functions)s \\\\ \\hline """ % {'functions': LatexParser._process_functions(synapse.functions)} # Build the dictionary desc = { 'name': synapse_name, 'description': synapse.short_description, 'firstsynapse': firstsynapse if idx == 0 else "", 'variables': variables, 'psp': psp_code, 'preevent': preevent, 'postevent': postevent, 'functions': functions } # Generate the code synapses += synapse_tpl % desc return synapses
def _generate_summary(net_id): txt = """ # Structure of the network """ # General information backend = 'default' if Global.config['paradigm'] == 'cuda': backend = "CUDA" elif Global.config['paradigm'] == "openmp" and Global.config['num_threads'] > 1: backend = "OpenMP" txt +=""" * ANNarchy %(version)s using the %(backend)s backend. * Numerical step size: %(dt)s ms. """ % {'version': ANNarchy.__release__, 'backend': backend, 'dt': Global.config['dt']} # Populations if len(Global._network[net_id]['populations']) > 0: headers = ["Population", "Size", "Neuron type"] populations = [] for pop in Global._network[net_id]['populations']: # Find a name for the neuron neuron_name = "Neuron " + str(pop.neuron_type._rk_neurons_type) if pop.neuron_type.name in Neuron._default_names.values() \ else pop.neuron_type.name populations.append([ pop.name, pop.geometry if len(pop.geometry)>1 else pop.size, neuron_name]) txt += """ ## Populations """ txt += _make_table(headers, populations) # Projections if len(Global._network[net_id]['projections']) > 0 : headers = ["Source", "Destination", "Target", "Synapse type", "Pattern"] projections = [] for proj in Global._network[net_id]['projections']: # Find a name for the synapse synapse_name = "Synapse " + str(proj.synapse_type._rk_synapses_type) if proj.synapse_type.name in Synapse._default_names.values() \ else proj.synapse_type.name projections.append([ proj.pre.name, proj.post.name, LatexParser._format_list(proj.target, ' / '), synapse_name, proj.connector_description ]) txt += """ ## Projections """ txt += _make_table(headers, projections) # Monitors if len(Global._network[net_id]['monitors']) > 0: headers = ["Object", "Variables", "Period"] monitors = [] for monitor in Global._network[net_id]['monitors']: monitors.append([ monitor.object.name + (" (subset)" if isinstance(monitor.object, PopulationView) else ""), LatexParser._format_list(monitor.variables, ', '), monitor.period ]) txt += """ ## Monitors """ txt += _make_table(headers, monitors) # Functions if len(Global._objects['functions']) > 0 : txt += """## Functions """ for name, func in Global._objects['functions']: txt += LatexParser._process_functions(func, begin="$$", end="$$\n\n") return txt
def _generate_measurements(net_id): measurements = "" header = "\\hdr{2}{D}{Bold Measurement Models}\\\\ \\hline" measurements_template = """ \\noindent \\begin{tabularx}{\\linewidth}{|p{0.15\\linewidth}|X|}\\hline %(header)s \\textbf{Name} & %(name)s \\\\ \\hline \\textbf{Type} & %(description)s\\\\ \\hline \\textbf{%(equation_type)s} & %(variables)s \\end{tabularx} \\vspace{2ex} """ first_define = True for neuron in Global._objects['neurons']: # skip non-bold models if not isinstance(neuron, BoldModel): continue # the model is not used if not neuron._model_instantiated: continue # Name if neuron.name in Neuron._default_names.values(): # name not set neuron_name = "Neuron " + str(neuron._rk_neurons_type) else: neuron_name = neuron.name # Generate the code for the equations variables, _, _ = LatexParser._process_neuron_equations(neuron) eqs = "" for var in variables: eqs += """ \\begin{dmath*} %(eq)s \\end{dmath*} """ % {'eq': var['latex']} variables_eqs = """ %(eqs)s \\\\ \\hline """ % {'eqs': eqs} # Build the dictionary desc = { 'name': neuron_name, 'description': neuron.short_description, 'header': header if first_define else "", 'variables': variables_eqs, 'equation_type': "Equations" } # Generate the code depending on the neuron position measurements += measurements_template % desc # first_define disable to prevent multiple table header first_define = False # no models were processed if len(measurements) == 0: measurements = """ \\noindent \\begin{tabularx}{\\linewidth}{|l|X|}\\hline \\hdr{2}{H}{Measurement}\\\\ \\hline \\textbf{Type} & \\textbf{Description} \\\\ \\hline --- \\\\ \\hline \\end{tabularx} """ return measurements