侧向抑制
大约 3 分钟案例案例
侧抑制是一种广泛存在的回路。它通过放大平行通路之间的活性差异来选择要传播到下游电路的信息。 例如,脊椎动物视网膜中的光感受器神经元激活水平细胞,水平细胞对附近的许多光感受器神经元提供反馈抑制。 这一行为是下游神经节细胞中经典的中央环绕感受野的主要贡献者,赋予这些神经元提取空间或颜色对比信息的能力。 横向抑制也被用于其他感觉系统,其一般目的是使下游电路处理的行为学相关信息的表征更加清晰。
简要拓扑图
代码示例
#
# Copyright (c) 2022 Neurocean Group
# All rights reserved.
# Created by damone
#
import numpy as np
import ocean
from ocean import Session, CompileOption
from matplotlib import pyplot as plt
from ocean.utils.VisualizeHelper import visualizeHelper
def randomInput(number, timezone):
return np.random.randint(2, size=(timezone, number), dtype=np.int8)
def visualizeResults(session, hidden, output):
plt.figure()
# Hidden1
plt.subplot(2, 1, 1)
plt.title("Hidden1 potentials")
captures = session.getCaptures(
hidden, ["potentials", "output", "firePotentials"])
visualizeHelper.plotPotentials(captures, [0])
# output
plt.subplot(2, 1, 2)
plt.title("Output potentials")
captures = session.getCaptures(
output, ["potentials", "output", "firePotentials"])
visualizeHelper.plotPotentials(captures, [0, 1, 2])
plt.show()
def LateralInhibition():
# Session
session = Session("session")
# Make input group
input = session.makeNeuronGroup(
"SequenceInput",
number=3,
totalTime=512,
inputBuffer=randomInput(3, 512)
)
# Make hidden group
hidden = session.makeNeuronGroup(
"General",
number=1,
thresholds=-25,
restingPotentials=-70,
decays=0.8,
potentials=-70
)
# Make output group
output = session.makeNeuronGroup(
"General",
number=3,
thresholds=-25,
restingPotentials=-70,
decays=0.1,
potentials=-70
)
# Make output reduce
outputReduce = session.makeModel(
"Reduce",
number=2
)
outputReduce.output("output").connect(output.input("input"))
# Make edge1
edge1 = session.makeSynapseGroup(
"SimpleSynapse",
inputNumber=3,
outputNumber=1,
weights=9
)
input.output("output").connect(edge1.input("input"))
edge1.output("output").connect(hidden.input("input"))
edge1.connect()
# Make edge2
edge2 = session.makeSynapseGroup(
"SimpleSynapse",
inputNumber=3,
outputNumber=3,
weights=9
)
input.output("output").connect(edge2.input("input"))
edge2.output("output").connect(outputReduce.input("input0"))
edge2.connect(0, 0)
edge2.connect(1, 1)
edge2.connect(2, 2)
# Make edge3
edge3 = session.makeSynapseGroup(
"SimpleSynapse",
inputNumber=1,
outputNumber=3,
weights=-18
)
hidden.output("output").connect(edge3.input("input"))
edge3.output("output").connect(outputReduce.input("input1"))
edge3.connect()
# Add monitor
POTENTIALS = ["potentials", "output", "firePotentials"]
session.addMonitors(hidden, POTENTIALS)
session.addMonitors(output, POTENTIALS)
# Run model
option = ocean.RunOption(False, False, 512)
if not (session.run(CompileOption.cpu(), option)):
print("Run Model failed")
return
# Get captures, visualize it
visualizeResults(session, hidden, output)
if __name__ == "__main__":
LateralInhibition()
/**
* Copyright (c) 2022 Neurocean Group
* All rights reserved.
* Created by damone
*/
#include <frontend/Option.hpp>
#include <frontend/Session.hpp>
#include <frontend/Filler.hpp>
#include "VisualizeHelper.hpp"
ocean::Tensor randomInput(int time, int inputSize) {
ocean::Tensor inputs(inputSize, time, ocean::INT8);
size_t total = inputs.total();
int8_t *data = (int8_t *) inputs.getData();
srand(rand());
for (size_t i = 0; i < total; i++) {
data[i] = rand() % 2;
}
return inputs;
}
void LateralInhibition() {
/// Sion
ocean::Session session;
/// createExecutionEngine input group
ocean::Arguments args;
args["number"] = 3u;
args["totalTime"] = 512u;
auto input = session.makeNeuronGroup("SequenceInput", args);
/// hidden group
args.clear();
args["number"] = 1u;
args["thresholds"] = -25.f;
args["restingPotentials"] = -75.f;
args["decays"] = 0.8f;
args["potentials"] = {-70.f, -30.f, 1};
auto hidden = session.makeNeuronGroup("General", args);
/// output group
args.clear();
args["number"] = 3u;
args["thresholds"] = -25.f;
args["restingPotentials"] = -75.f;
args["decays"] = 0.1f;
args["potentials"] = {-70.f, -25.f};
auto output = session.makeNeuronGroup("General", args);
/// output reduce
args.clear();
args["number"] = 2u;
auto outputReduce = session.makeModel("Reduce", args);
outputReduce->out("output")->connect(output->in("input"));
/// createExecutionEngine synapses
/// edge1
args.clear();
args["weights"] = 9;
args["inputNumber"] = 3;
args["outputNumber"] = 1;
auto edge1 = session.makeSynapseGroup("SimpleSynapse", args);
input->out("output")->connect(edge1->in("input"));
edge1->out("output")->connect(hidden->in("input"));
edge1->connect();
args.clear();
args["weights"] = {9.f, 16.f};
args["inputNumber"] = 3;
args["outputNumber"] = 3;
auto edge2 = session.makeSynapseGroup("SimpleSynapse", args);
input->out("output")->connect(edge2->in("input"));
edge2->out("output")->connect(outputReduce->in("input0"));
edge2->connect(0u, 0u);
edge2->connect(1u, 1u);
edge2->connect(2u, 2u);
/// edge2
args.clear();
args["weights"] = {-6.f, -9.f};
args["inputNumber"] = 1;
args["outputNumber"] = 3;
auto edge3 = session.makeSynapseGroup("SimpleSynapse", args);
hidden->out("output")->connect(edge3->in("input"));
edge3->out("output")->connect(outputReduce->in("input1"));
edge3->connect();
/// compile model
if (!session.compile(ocean::CompileOption::cpu())) {
std::cout << "Compile model failed" << std::endl;
return;
}
/// add monitor
session.addMonitors(hidden, {"potentials", "output", "firePotentials"});
session.addMonitors(output, {"potentials", "output", "firePotentials"});
/// set input
input->setStatus("inputBuffer", randomInput(512, 3));
/// run model
ocean::RunOption option{false, true, 512};
session.run(option);
auto monitorVars1 = session.getCaptures(hidden, {"potentials", "output", "firePotentials"});
auto monitorVars2 = session.getCaptures(output, {"potentials", "output", "firePotentials"});
if(monitorVars1.size() == 3 && monitorVars2.size() == 3){
/// hidden potentials
plt::subplot(2, 1, 1);
plt::title("Hidden1 potentials");
ocean::plotSingleNeuronStates(monitorVars1, {0}, hidden->getStep());
/// output potentials
plt::subplot(2, 1, 2);
plt::title("Output potentials");
ocean::plotSingleNeuronStates(monitorVars2, {0, 1, 2}, output->getStep());
plt::show();
}
}
int main(int argc, char *argv[]) {
LateralInhibition();
return 0;
}