Ejemplo n.º 1
0
 def to_nineml(self):
     model = ul.Model(name=self.label)
     for cs in self.current_sources:
         model.add_component(cs.to_nineml())
         # needToDefineWhichCellsTheCurrentIsInjectedInto
         # doWeJustReuseThePopulationProjectionIdiom="?"
     main_group = ul.Network(name="Network")
     _populations = self.populations[:]
     _projections = self.projections[:]
     for a in self.assemblies:
         group = a.to_nineml()
         for p in a.populations:
             _populations.remove(p)
             group.add(p.to_nineml())
         for prj in self.projections:
             if (prj.pre is a or prj.pre in a.populations) and \
                (prj.post is a or prj.post in a.populations):
                 _projections.remove(prj)
                 group.add(prj.to_nineml())
         model.add_group(group)
     for p in _populations:
         main_group.add(p.to_nineml())
     for prj in _projections:
         main_group.add(prj.to_nineml())
     model.add_group(main_group)
     model.check()
     return model
def build_model(order=1000,
                epsilon=0.1,
                delay=1.5,
                J=0.1,
                theta=20.0,
                tau=20.0,
                tau_syn=0.1,
                tau_refrac=2.0,
                v_reset=10.0,
                R=1.5,
                g=5,
                eta=2):
    """
    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
    """
    Ne = 4 * order  # number of excitatory neurons
    Ni = 1 * order  # number of inhibitory neurons
    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
    scale_factor = psp_height(tau, R, tau_syn)
    Jeff = J / scale_factor  # (nA) synaptic weight
    Je = Jeff  # excitatory weights
    Ji = -g * Je  # inhibitory weights
    Jext = Je  # external weights
    nu_thresh = theta / (Je * Ce * R * tau_syn)  # threshold rate
    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),
                                           v_threshold=(theta, mV),
                                           refractory_period=(tau_refrac, ms),
                                           v_reset=(v_reset, mV),
                                           R=(R, Mohm))
    psr_parameters = nineml.PropertySet(tau=(tau_syn, ms))
    v_init = nineml.RandomDistributionComponent(
        "uniform_rest_to_threshold",
        CATALOG_URL + "randomdistribution/Uniform.xml#UniformDistribution",
        {
            'minimum': (0.0, unitless),
            'maximum': (theta, unitless)
        },
    )
    neuron_initial_values = {"v": (v_init, mV), "refractory_end": (0.0, ms)}
    synapse_initial_values = {"a": (0.0, nA), "b": (0.0, nA)}

    celltype = nineml.SpikingNodeType("nrn",
                                      CATALOG_URL +
                                      "neuron/LeakyIntegrateAndFire.xml",
                                      neuron_parameters,
                                      initial_values=neuron_initial_values)
    tpoisson_init = nineml.RandomDistributionComponent(
        "exponential_first_spike_time", CATALOG_URL +
        "randomdistribution/Exponential.xml#ExponentialDistribution",
        {"rate": (input_rate, unitless)})

    ext_stim = nineml.SpikingNodeType(
        "stim",
        CATALOG_URL + "input/Poisson.xml",
        nineml.PropertySet(rate=(input_rate, Hz)),
        initial_values={"t_next": (tpoisson_init, ms)})
    psr = nineml.SynapseType("syn",
                             CATALOG_URL + "postsynapticresponse/Alpha.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",
                                 nineml.Concatenate(exc_cells, inh_cells))

    one_to_one = nineml.ConnectionRuleComponent(
        "OneToOne", CATALOG_URL + "connectionrule/OneToOne.xml")
    random_exc = nineml.ConnectionRuleComponent(
        "RandomExc", CATALOG_URL + "connectionrule/RandomFanIn.xml",
        {"number": (Ce, unitless)})
    random_inh = nineml.ConnectionRuleComponent(
        "RandomInh", CATALOG_URL + "connectionrule/RandomFanIn.xml",
        {"number": (Ci, unitless)})

    static_ext = nineml.ConnectionType("ExternalPlasticity",
                                       CATALOG_URL + "plasticity/Static.xml",
                                       nineml.PropertySet(weight=(Jext, nA)))
    #initial_values={"weight": (Jext, nA)})
    static_exc = nineml.ConnectionType("ExcitatoryPlasticity",
                                       CATALOG_URL + "plasticity/Static.xml",
                                       nineml.PropertySet(weight=(Je, nA)))
    #initial_values={"weight": (Je, nA)})
    static_inh = nineml.ConnectionType("InhibitoryPlasticity",
                                       CATALOG_URL + "plasticity/Static.xml",
                                       nineml.PropertySet(weight=(Ji, nA)))
    #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", "fixed_weight",
                                  "weight"),
            nineml.PortConnection("response", "destination", "i_synaptic",
                                  "i_synaptic")
        ],
        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", "fixed_weight",
                                  "weight"),
            nineml.PortConnection("response", "destination", "i_synaptic",
                                  "i_synaptic")
        ],
        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", "fixed_weight",
                                  "weight"),
            nineml.PortConnection("response", "destination", "i_synaptic",
                                  "i_synaptic")
        ],
        delay=(delay, ms))

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

    return network
def build_model(N=100,
                delay=1.5,
                weight=0.1,
                theta=20.0,
                tau=20.0,
                tau_syn=0.1,
                tau_refrac=2.0,
                v_reset=10.0,
                R=1.5,
                interval=5.0):
    """
    docstring missing
    """

    neuron_parameters = nineml.PropertySet(tau=(tau, ms),
                                           v_threshold=(theta, mV),
                                           refractory_period=(tau_refrac, ms),
                                           v_reset=(v_reset, mV),
                                           R=(R, Mohm))
    psr_parameters = nineml.PropertySet(tau=(tau_syn, ms))
    v_init = v_reset
    neuron_initial_values = {"v": (v_init, mV), "refractory_end": (0.0, ms)}
    synapse_initial_values = {"a": (0.0, nA), "b": (0.0, nA)}

    celltype = nineml.SpikingNodeType("nrn",
                                      CATALOG_URL +
                                      "neuron/LeakyIntegrateAndFire.xml",
                                      neuron_parameters,
                                      initial_values=neuron_initial_values)
    ext_stim = nineml.SpikingNodeType("stim",
                                      join(dirname(__file__), "Tonic.xml"),
                                      nineml.PropertySet(interval=(interval,
                                                                   ms)),
                                      initial_values={"t_next": (10.0, ms)})
    psr = nineml.SynapseType("syn",
                             CATALOG_URL + "postsynapticresponse/Alpha.xml",
                             psr_parameters,
                             initial_values=synapse_initial_values)

    exc_cells = nineml.Population("Exc", N, celltype, positions=None)
    external = nineml.Population("Ext", N, ext_stim, positions=None)

    one_to_one = nineml.ConnectionRuleComponent(
        "AllToAll", CATALOG_URL + "connectionrule/AllToAll.xml")

    static_ext = nineml.ConnectionType("ExternalPlasticity",
                                       CATALOG_URL + "plasticity/Static.xml",
                                       nineml.PropertySet(weight=(weight, nA)))

    input_prj = nineml.Projection(
        "External",
        external,
        exc_cells,
        connectivity=one_to_one,
        response=psr,
        plasticity=static_ext,
        port_connections=[
            nineml.PortConnection("plasticity", "response", "fixed_weight",
                                  "weight"),
            nineml.PortConnection("response", "destination", "i_synaptic",
                                  "i_synaptic")
        ],
        delay=(delay, ms))

    network = nineml.Network("SimpleNetwork")
    network.add(exc_cells, external)
    network.add(input_prj)

    return network