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_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_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_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_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): 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): 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_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