Example #1
0
 def to_nineml(self):
     connection_rule = self._method.to_nineml(self.label)
     connection_type = nineml.ConnectionType(
                                 name="connection type for projection %s" % self.label,
                                 definition=nineml.Definition("%s/connectiontypes/static_synapse.xml" % catalog_url),
                                 parameters=build_parameter_set(
                                              {"weight": self._method.weights,
                                               "delay": self._method.delays}))
     synaptic_responses = self.post.get_synaptic_response_components(self.target)
     synaptic_response, = synaptic_responses
     projection = nineml.Projection(
                             name=self.label,
                             source=self.pre.to_nineml(), # or just pass ref, and then resolve later?
                             target=self.post.to_nineml(),
                             rule=connection_rule,
                             synaptic_response=synaptic_response,
                             connection_type=connection_type)
     return projection
Example #2
0
    def test_xml_roundtrip(self):

        delay = 1.5  # (ms) global delay for all neurons in the group
        J = 0.1  # (mV) EPSP size
        Jeff = 24.0 * J  # (nA) synaptic weight
        g = 5.0  # relative strength of inhibitory synapses
        #         eta = 2.0            # nu_ext / nu_thresh
        Je = Jeff  # excitatory weights
        Ji = -g * Je  # inhibitory weights
        theta = 20.0  # firing thresholds
        tau = 20.0  # membrane time constant
        tau_syn = 0.5  # synapse time constant
        input_rate = 50.0  # mean input spiking rate

        neuron_parameters = nineml.PropertySet(tau=(tau, ms),
                                               theta=(theta, mV),
                                               tau_rp=(2.0, ms),
                                               Vreset=(10.0, mV),
                                               R=(1.5, Mohm))
        psr_parameters = nineml.PropertySet(tau_syn=(tau_syn, ms))
        neuron_initial_values = {
            "V": (0.0, mV),  # todo: use random distr.
            "t_rpend": (0.0, ms)
        }
        synapse_initial_values = {"A": (0.0, nA), "B": (0.0, nA)}

        celltype = nineml.SpikingNodeType("nrn",
                                          path.join(self.xml_dir,
                                                    'BrunelIaF.xml'),
                                          neuron_parameters,
                                          initial_values=neuron_initial_values)
        ext_stim = nineml.SpikingNodeType("stim",
                                          path.join(self.xml_dir,
                                                    "Poisson.xml"),
                                          nineml.PropertySet(rate=(input_rate,
                                                                   Hz)),
                                          initial_values={"t_next": (0.5, ms)})
        psr = nineml.SynapseType("syn",
                                 path.join(self.xml_dir, "AlphaPSR.xml"),
                                 psr_parameters,
                                 initial_values=synapse_initial_values)

        p1 = nineml.Population("Exc", 1, celltype, positions=None)
        p2 = nineml.Population("Inh", 1, celltype, positions=None)
        inpt = nineml.Population("Ext", 1, ext_stim, positions=None)

        all_to_all = nineml.ConnectionRule(
            "AllToAll", path.join(self.xml_dir, "AllToAll.xml"))

        static_exc = nineml.ConnectionType("ExcitatoryPlasticity",
                                           path.join(self.xml_dir,
                                                     "StaticConnection.xml"),
                                           initial_values={"weight": (Je, nA)})
        static_inh = nineml.ConnectionType("InhibitoryPlasticity",
                                           path.join(self.xml_dir,
                                                     "StaticConnection.xml"),
                                           initial_values={"weight": (Ji, nA)})

        exc_prj = nineml.Projection(
            "Excitation",
            inpt,
            p1,
            connectivity=all_to_all,
            response=psr,
            plasticity=static_exc,
            port_connections=[
                nineml.PortConnection("plasticity", "response", "weight", "q"),
                nineml.PortConnection("response", "destination", "Isyn",
                                      "Isyn")
            ],
            delay=(delay, ms))

        inh_prj = nineml.Projection(
            "Inhibition",
            inpt,
            p2,
            connectivity=all_to_all,
            response=psr,
            plasticity=static_inh,
            port_connections=[
                nineml.PortConnection("plasticity", "response", "weight", "q"),
                nineml.PortConnection("response", "destination", "Isyn",
                                      "Isyn")
            ],
            delay=(delay, ms))

        model = nineml.Network("Three-neuron network with alpha synapses")
        model.add(inpt, p1, p2)
        model.add(exc_prj, inh_prj)
        model.write(self.tmp_xml_file)
        loaded_model = nineml.Network.read(self.tmp_xml_file)
        self.assertEqual(loaded_model, model)
        os.remove(self.tmp_xml_file)
Example #3
0
inh_psr = nineml.SynapseType(
    "Inhibitory post-synaptic response",
    catalog + "postsynapticresponses/exp_g.xml",
    dict(tau=(5.0, "ms"), vrev=(-70.0, "mV"), q=(1.0, "dimensionless")))

exc_connection_type = nineml.ConnectionType(
    "Static excitatory connections",
    catalog + "connectiontypes/static_connection.xml")  ##,
##{'weight': (0.1, "nS"), 'delay': (0.3, "ms")})
inh_connection_type = nineml.ConnectionType(
    "Static inhibitory connections",
    catalog + "connectiontypes/static_connection.xml")  ##,
##{'weight': (0.2, "nS"), 'delay': (0.3, "ms")})

exc2exc = nineml.Projection("Excitatory cells-Excitatory cells", exc_cells,
                            exc_cells, connection_rule, exc_psr,
                            exc_connection_type)
inh2all = nineml.Projection("Inhibitory connections", inh_cells, all_cells,
                            connection_rule, inh_psr, inh_connection_type)

network = nineml.Group("Network")
network.add(exc_cells)
network.add(inh_cells)
network.add(all_cells)
network.add(exc2exc)
network.add(inh2all)

model = nineml.Model("Simple 9ML example model")
model.add_group(network)

if __name__ == "__main__":
def build_model(g, eta):
    """
    Build a NineML representation of the Brunel (2000) network model.

    Arguments:
        g: relative strength of inhibitory synapses
        eta: nu_ext / nu_thresh

    Returns:
        a nineml user layer Model object
    """
    order = 1000  # scales the size of the network
    Ne = 4 * order  # number of excitatory neurons
    Ni = 1 * order  # number of inhibitory neurons
    epsilon = 0.1  # connection probability
    Ce = int(epsilon * Ne)  # number of excitatory synapses per neuron
    Ci = int(epsilon * Ni)  # number of inhibitory synapses per neuron
    Cext = Ce  # effective number of external synapses per neuron
    delay = 1.5  # (ms) global delay for all neurons in the group
    J = 0.1  # (mV) EPSP size
    Jeff = 24.0 * J  # (nA) synaptic weight
    Je = Jeff  # excitatory weights
    Ji = -g * Je  # inhibitory weights
    Jext = Je  # external weights
    theta = 20.0  # firing thresholds
    tau = 20.0  # membrane time constant
    tau_syn = 0.1  # synapse time constant
    #nu_thresh = theta / (Je * Ce * tau * exp(1.0) * tau_syn)  # threshold rate
    nu_thresh = theta / (J * Ce * tau)
    nu_ext = eta * nu_thresh  # external rate per synapse
    input_rate = 1000.0 * nu_ext * Cext  # mean input spiking rate

    neuron_parameters = nineml.PropertySet(tau=(tau, ms),
                                           theta=(theta, mV),
                                           tau_rp=(2.0, ms),
                                           Vreset=(10.0, mV),
                                           R=(1.5, Mohm))  # units??
    psr_parameters = nineml.PropertySet(tau_syn=(tau_syn, ms))
    #v_init = nineml.RandomDistribution("uniform(rest,threshold)",
    #                                   "catalog/randomdistributions/uniform_distribution.xml",  # hack - this file doesn't exist
    #                                   {'lowerBound': (0.0, "dimensionless"),
    #                                    'upperBound': (theta, "dimensionless")})
    v_init = 0.0
    neuron_initial_values = {"V": (v_init, mV), "t_rpend": (0.0, ms)}
    synapse_initial_values = {"A": (0.0, nA), "B": (0.0, nA)}

    celltype = nineml.SpikingNodeType("nrn",
                                      "BrunelIaF.xml",
                                      neuron_parameters,
                                      initial_values=neuron_initial_values)

    #tpoisson_init = nineml.RandomDistribution("exponential(beta)",
    #                                          "catalog/randomdistributions/exponential_distribution.xml",
    #                                          {"beta": (1000.0/input_rate, "dimensionless")})
    tpoisson_init = 5.0
    ext_stim = nineml.SpikingNodeType(
        "stim",
        "Poisson.xml",
        nineml.PropertySet(rate=(input_rate, Hz)),
        initial_values={"t_next": (tpoisson_init, ms)})
    psr = nineml.SynapseType("syn",
                             "AlphaPSR.xml",
                             psr_parameters,
                             initial_values=synapse_initial_values)

    exc_cells = nineml.Population("Exc", Ne, celltype, positions=None)
    inh_cells = nineml.Population("Inh", Ni, celltype, positions=None)
    external = nineml.Population("Ext", Ne + Ni, ext_stim, positions=None)

    all_cells = nineml.Selection("All neurons",
                                 nineml.Concatenate(exc_cells, inh_cells))

    one_to_one = nineml.ConnectionRule("OneToOne", "OneToOne.xml")
    random_exc = nineml.ConnectionRule("RandomExc", "RandomFanIn.xml",
                                       {"number": (Ce, unitless)})
    random_inh = nineml.ConnectionRule("RandomInh", "RandomFanIn.xml",
                                       {"number": (Ci, unitless)})

    static_ext = nineml.ConnectionType("ExternalPlasticity",
                                       "StaticConnection.xml",
                                       initial_values={"weight": (Jext, nA)})
    static_exc = nineml.ConnectionType("ExcitatoryPlasticity",
                                       "StaticConnection.xml",
                                       initial_values={"weight": (Je, nA)})
    static_inh = nineml.ConnectionType("InhibitoryPlasticity",
                                       "StaticConnection.xml",
                                       initial_values={"weight": (Ji, nA)})

    input_prj = nineml.Projection(
        "External",
        external,
        all_cells,
        connectivity=one_to_one,
        response=psr,
        plasticity=static_ext,
        port_connections=[
            nineml.PortConnection("plasticity", "response", "weight", "q"),
            nineml.PortConnection("response", "destination", "Isyn", "Isyn")
        ],
        delay=(delay, ms))
    exc_prj = nineml.Projection(
        "Excitation",
        exc_cells,
        all_cells,
        connectivity=random_exc,
        response=psr,
        plasticity=static_exc,
        port_connections=[
            nineml.PortConnection("plasticity", "response", "weight", "q"),
            nineml.PortConnection("response", "destination", "Isyn", "Isyn")
        ],
        delay=(delay, ms))
    inh_prj = nineml.Projection(
        "Inhibition",
        inh_cells,
        all_cells,
        connectivity=random_inh,
        response=psr,
        plasticity=static_inh,
        port_connections=[
            nineml.PortConnection("plasticity", "response", "weight", "q"),
            nineml.PortConnection("response", "destination", "Isyn", "Isyn")
        ],
        delay=(delay, ms))

    network = nineml.Network("BrunelCaseC")
    network.add(exc_cells, inh_cells, external, all_cells)
    network.add(input_prj, exc_prj, inh_prj)

    #model = nineml.Model("Brunel (2000) network with alpha synapses")
    #model.add_group(network)

    #return model
    return network
Example #5
0
        'delay': (0.3, "ms")
    })

inh_connection_type = nineml.ConnectionType(
    name="Static inhibitory connections",
    reference=exc_connection_type.name,
    parameters={'weight': (0.2, "nS")})

intra_column_connector = nineml.ConnectionRule(
    name="local random connections",
    definition=catalog + "connectionrules/fixed_probability.xml",
    parameters={'p_connect': (0.1, "dimensionless")})

inner_exc2all = nineml.Projection(name="Intra-column excitatory connections",
                                  source=exc_cells,
                                  target=column,
                                  rule=intra_column_connector,
                                  synaptic_response=exc_psr,
                                  connection_type=exc_connection_type)

inner_inh2all = nineml.Projection(name="Intra-column inhibitory connections",
                                  source=inh_cells,
                                  target=column,
                                  rule=intra_column_connector,
                                  synaptic_response=inh_psr,
                                  connection_type=inh_connection_type)

column.add(inner_exc2all, inner_inh2all)

inter_column_connector = nineml.ConnectionRule(
    name="lateral random connections",
    reference=intra_column_connector.name,
Example #6
0
all_to_all = nineml.ConnectionRule("AllToAll", "AllToAll.xml")

static_exc = nineml.ConnectionType("ExcitatoryPlasticity",
                                   "StaticConnection.xml",
                                   initial_values={"weight": (Je, nA)})
static_inh = nineml.ConnectionType("InhibitoryPlasticity",
                                   "StaticConnection.xml",
                                   initial_values={"weight": (Ji, nA)})

exc_prj = nineml.Projection("Excitation",
                            input,
                            p1,
                            connectivity=all_to_all,
                            response=psr,
                            plasticity=static_exc,
                            port_connections=[
                                nineml.PortConnection("plasticity", "response",
                                                      "weight", "q"),
                                nineml.PortConnection("response",
                                                      "destination", "Isyn",
                                                      "Isyn")
                            ],
                            delay=(delay, ms))

inh_prj = nineml.Projection("Inhibition",
                            input,
                            p2,
                            connectivity=all_to_all,
                            response=psr,
                            plasticity=static_inh,
                            port_connections=[
                                nineml.PortConnection("plasticity", "response",