def gen_net() -> lb.Net:
    # Create the Network
    net = lb.Net()

    ## Create Layers

    # Create input and output layers
    net.new_layer("Input", 8, layer_spec)
    net.new_layer("EC_in", 8, EC_layer_spec)
    net.new_layer("EC_out", 8, EC_layer_spec)

    # Create cortical layers
    net.new_layer("CA1", 100, CA1_layer_spec)
    net.new_layer("CA3", 80, CA3_layer_spec)

    # Create hippocampus
    net.new_layer("DG", 400, DG_layer_spec)

    ## Create Projections

    # Input Feed
    net.new_projn("Input: Input -> EC_in",
                  "Input",
                  "EC_in",
                  spec=Input_projn_spec)
    net.new_projn("Loop: EC_out -> EC_in",
                  "EC_out",
                  "EC_in",
                  spec=EC_out_EC_in_projn_spec)

    # Create MSP
    net.new_projn("MSP: EC_in -> CA1",
                  "EC_in",
                  "CA1",
                  spec=EC_in_CA1_projn_spec)
    net.new_projn("MSP: CA1 -> EC_out",
                  "CA1",
                  "EC_out",
                  spec=EC_out_CA1_projn_spec)
    net.new_projn("MSP: EC_out -> CA1",
                  "EC_out",
                  "CA1",
                  spec=EC_out_CA1_projn_spec)

    # Create TSP
    net.new_projn("TSP: EC_in -> DG", "EC_in", "DG", spec=EC_in_projn_spec)
    net.new_projn("TSP: EC_in -> CA3", "EC_in", "CA3", spec=EC_in_projn_spec)
    net.new_projn("TSP: DG -> CA3", "DG", "CA3", spec=DG_CA3_projn_spec)
    net.new_projn("TSP: CA3 -> CA3", "CA3", "CA3", spec=CA3_CA3_projn_spec)
    net.new_projn("TSP: CA3 -> CA1", "CA3", "CA1", spec=CA3_CA1_projn_spec)

    return net
Ejemplo n.º 2
0
def test_a_simple_network_can_learn_simple_things() -> None:
    network = lb.Net()
    network.new_layer("input", size=2)
    network.new_layer("output", size=2)
    projn_spec = lb.ProjnSpec(lrate=0.2)
    network.new_projn("input_to_output",
                      pre="input",
                      post="output",
                      spec=projn_spec)

    input_patterns = [[1, 0], [0, 1]]
    output_patterns = [[0, 1], [1, 0]]
    batch(network, input_patterns, output_patterns)

    actual = [output(network, i) for i in input_patterns]

    for act, exp in zip(actual, output_patterns):
        assert act == exp
def test_you_can_log_projection_weights() -> None:
    network = lb.Net()
    network.new_layer("input", size=2)
    network.new_layer("output", size=2)
    projn_spec = lb.ProjnSpec(log_on_trial=["conn_wt"])
    network.new_projn("input_to_output",
                      pre="input",
                      post="output",
                      spec=projn_spec)

    trial(network, (1, 0), (0, 1))

    _, part_logs = network.logs(freq="trial", name="input_to_output")

    expected = pd.DataFrame({
        "pre_unit": (0, 1, 0, 1),
        "conn_wt": (0.5, 0.5, 0.5, 0.5),
        "post_unit": (0, 0, 1, 1),
        "time": (0, 0, 0, 0)
    })

    pd.util.testing.assert_frame_equal(part_logs, expected, check_like=True)
Ejemplo n.º 4
0
def test_kwta_suppresses_all_but_k_units() -> None:
    for p in np.linspace(0.0, 1.0, 10):
        n = lb.Net()
        n.new_layer(name="lr1", size=1)

        lr2_spec = lb.LayerSpec(
            inhibition_type="kwta",
            kwta_pct=p,
            unit_spec=lb.UnitSpec(adapt_dt=0, spike_gain=0))
        n.new_layer(name="lr2", size=10, spec=lr2_spec)

        pr1_spec = lb.ProjnSpec(dist=lb.Uniform(low=0.25, high=0.75))
        n.new_projn("proj1", "lr1", "lr2", pr1_spec)

        pr2_spec = lb.ProjnSpec(dist=lb.Uniform(low=0.25, high=0.75))
        n.new_projn("proj2", "lr1", "lr2", pr2_spec)

        n.clamp_layer("lr1", [1])
        for i in range(50):
            n.cycle()

        v_m_eq = n.observe("lr2", "unit_v_m_eq")["v_m_eq"]
        assert (v_m_eq > 0.5).sum() == max(1, int(round(10 * p)))
Ejemplo n.º 5
0
def test_kwta_avg_suppresses_all_but_k_units() -> None:
    for p in np.linspace(0.4, 1.0, 10):
        n = lb.Net()
        n.new_layer(name="lr1", size=1)

        lr2_spec = lb.LayerSpec(
            inhibition_type="kwta_avg",
            kwta_pct=p,
            log_on_cycle=("unit_act", ),
            unit_spec=lb.UnitSpec(adapt_dt=0, spike_gain=0))
        n.new_layer(name="lr2", size=10, spec=lr2_spec)

        pr1_spec = lb.ProjnSpec(dist=lb.Uniform(low=0.25, high=0.75))
        n.new_projn("proj1", "lr1", "lr2", pr1_spec)

        pr2_spec = lb.ProjnSpec(dist=lb.Uniform(low=0.25, high=0.75))
        n.new_projn("proj2", "lr1", "lr2", pr2_spec)

        n.clamp_layer("lr1", [1])
        for i in range(100):
            n.cycle()

        logs = n.logs("cycle", "lr2").parts
        acts = logs[logs.time == 99]["act"]
Ejemplo n.º 6
0
import matplotlib  #type: ignore
import matplotlib.pyplot as plt  #type: ignore
# %matplotlib inline
import pandas as pd  #type: ignore

import leabra7 as lb

# Begin Markdown
# # Two Neuron Network

# Begin Markdown
# ### Network Creation

# Begin Code
# Create the network
net = lb.Net()

# Set options for our layers
layer_spec = lb.LayerSpec(
    # For each layer, log the unit potential
    log_on_cycle=("unit_v_m", "unit_act", "unit_i_net", "unit_net",
                  "unit_gc_i", "unit_adapt", "unit_spike"))

# Create our layers and projections
net.new_layer("input", 1, layer_spec)
net.new_layer("output", 1, layer_spec)
net.new_projn("proj1", "input", "output")

# Begin Markdown
# ### Run Network