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)))
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"]
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)
for i in range(200): net.cycle() # Begin Markdown # ### Graphing Logs # Begin Code wholeLog, partLog = net.logs(freq="cycle", name="output") partLog.plot(x='time', figsize=(10, 6)) # Begin Markdown # # One to Many Neuron Network # Begin Code # Define projection spec to have random weights projn_spec = lb.ProjnSpec(dist=lb.Gaussian(mean=0.5, var=0.3)) # Begin Markdown # ### Network Creation # Begin Code # Create the network net = lb.Net() # Create our layers and projections net.new_layer("input", 1, layer_spec) net.new_layer("output", 10, layer_spec) net.new_projn("proj1", "input", "output", spec=projn_spec) # Begin Markdown # ### Run Network
# CA1 Layer Spec CA1_layer_spec = lb.LayerSpec( inhibition_type="kwta_avg", kwta_pct=0.25, kwta_pt=0.7, ) # In[4]: ## Define Projections Spec # Input -> EC_in Input_projn_spec = lb.ProjnSpec( dist=lb.Uniform(low=0.25, high=0.75), lrate=0, projn_type="one_to_one", minus_phase=lb.NonePhase, plus_phase=ThetaPlus, ) # EC_in -> DG # EC_in -> CA3 EC_in_projn_spec = lb.ProjnSpec( dist=lb.Uniform(low=0.25, high=0.75), lrate=0.2, sparsity=0.25, minus_phase=lb.NonePhase, plus_phase=ThetaPlus, ) # DG -> CA3 (Mossy Fiber)