Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
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
Esempio n. 4
0
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
Esempio n. 5
0
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