前馈兴奋
大约 3 分钟example
信息从一个神经区域传递向另一个神经区域是通过在兴奋神经元之间的多个连接进行前馈兴奋来进行的。 神经元通常会接受多个突触前神经元搭档的输入(收敛性兴奋),并通过轴突分支输出到多个突触后神经元搭档(发散性兴奋)。 收敛性兴奋使得突触后神经元选择性地对突触前神经元的的特征作出反应。如果多个输入神经元携带相同的信号且具有不相干的噪声, 收敛性兴奋也可以很好地提高信噪比。发散性兴奋使得同一个信号号可以被不同的下游通路处理。
一个最典型的前馈兴奋的例子是灵长目动物的视觉系统,信号流从光感受器->双极细胞->视网膜神经节细胞(RGC)->外膝核(LGN)->初级视觉第4层->更高级的皮层区域。
简要拓扑图
代码示例
#
# 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, hidden1, hidden2, output):
plt.figure()
# Hidden1
plt.subplot(3, 1, 1)
plt.title("Hidden1 potentials")
captures = session.getCaptures(
hidden1, ["potentials", "output", "firePotentials"])
visualizeHelper.plotPotentials(captures, [0])
# Hidden2
plt.subplot(3, 1, 2)
plt.title("Hidden2 potentials")
captures = session.getCaptures(
hidden2, ["potentials", "output", "firePotentials"])
visualizeHelper.plotPotentials(captures, [0])
# output
plt.subplot(3, 1, 3)
plt.title("Output potentials")
captures = session.getCaptures(
output, ["potentials", "output", "firePotentials"])
visualizeHelper.plotPotentials(captures, [0, 1, 2])
plt.show()
def FeedForwardExcitation():
# Session
session = Session("session")
# Make input group
input = session.makeNeuronGroup(
"SequenceInput",
number=3,
totalTime=512,
inputBuffer=randomInput(3, 512)
)
# Make hidden1 group
hidden1 = session.makeNeuronGroup(
"General",
number=1,
thresholds=-25,
restingPotentials=-70,
decays=0.8,
potentials=-70
)
# Make hidden2 group
hidden2 = 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=(2, -70, -30, 1)
)
# Make edge1
edge1 = session.makeSynapseGroup(
"SimpleSynapse",
inputNumber=3,
outputNumber=1,
weights=6
)
input.output("output").connect(edge1.input("input"))
edge1.output("output").connect(hidden1.input("input"))
edge1.connect()
# Make edge2
edge2 = session.makeSynapseGroup(
"SimpleSynapse",
inputNumber=1,
outputNumber=1,
weights=18
)
hidden1.output("output").connect(edge2.input("input"))
edge2.output("output").connect(hidden2.input("input"))
edge2.connect()
# Make edge3
edge3 = session.makeSynapseGroup(
"SimpleSynapse",
inputNumber=1,
outputNumber=3,
weights=6
)
hidden2.output("output").connect(edge3.input("input"))
edge3.output("output").connect(output.input("input"))
edge3.connect()
# Add monitor
POTENTIALS = ["potentials", "output", "firePotentials"]
session.addMonitors(hidden1, POTENTIALS)
session.addMonitors(hidden2, 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, hidden1, hidden2, output)
if __name__ == "__main__":
FeedForwardExcitation()
/**
* 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();
for (size_t i = 0; i < total; i++) {
data[i] = rand() % 2;
}
return inputs;
}
void FeedForwardExcitation() {
/// Session
ocean::Session session;
/// 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["decays"] = 1.f;
args["restingPotentials"] = -70.f;
args["potentials"] = {-70.f, -30.f};
auto hidden = session.makeNeuronGroup("General", args);
auto hidden2 = session.makeNeuronGroup("General", args);
/// output group
args.clear();
args["number"] = 3u;
args["thresholds"] = -25.f;
args["restingPotentials"] = -70.f;
args["decays"] = 0.1f;
args["potentials"] = {-70.f, -30.f};
auto output = session.makeNeuronGroup("General", args);
/// createExecutionEngine synapses
/// edge1
args.clear();
args["inputNumber"] = 3;
args["outputNumber"] = 1;
args["weights"] = 6.f;
auto edge1 = session.makeSynapseGroup("SimpleSynapse", args);
input->out("output")->connect(edge1->in("input"));
edge1->out("output")->connect(hidden->in("input"));
edge1->connect();
/// edge2
args.clear();
args["weights"] = 18.f;
args["inputNumber"] = 1;
args["outputNumber"] = 1;
auto edge2 = session.makeSynapseGroup("SimpleSynapse", args);
hidden->out("output")->connect(edge2->in("input"));
edge2->out("output")->connect(hidden2->in("input"));
edge2->connect();
/// edge3
args.clear();
args["weights"] = 6.f;
args["inputNumber"] = 1;
args["outputNumber"] = 3;
auto edge3 = session.makeSynapseGroup("SimpleSynapse", args);
hidden2->out("output")->connect(edge3->in("input"));
edge3->out("output")->connect(output->in("input"));
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(hidden2, {"potentials", "output", "firePotentials"});
session.addMonitors(output, {"potentials", "output", "firePotentials"});
/// set input
input->setStatus("inputBuffer", randomInput(3, 512));
/// run model
ocean::RunOption option{false, true, 512};
session.run(option);
auto monitorVars1 = session.getCaptures(hidden, {"potentials", "output", "firePotentials"});
auto monitorVars2 = session.getCaptures(hidden2, {"potentials", "output", "firePotentials"});
auto monitorVars3 = session.getCaptures(output, {"potentials", "output", "firePotentials"});
if(monitorVars1.size() == 3 && monitorVars2.size() == 3){
/// hidden potentials
plt::subplot(3, 1, 1);
plt::title("Hidden1 potentials");
ocean::plotSingleNeuronStates(monitorVars1, {0}, hidden->getStep());
/// hidden2 potentials
plt::subplot(3, 1, 2);
plt::title("Hidden2 potentials");
ocean::plotSingleNeuronStates(monitorVars2, {0}, output->getStep());
/// output potentials
plt::subplot(3, 1, 3);
plt::title("Output potentials");
ocean::plotSingleNeuronStates(monitorVars3, {0, 1, 2}, output->getStep());
plt::show();
}
}
int main(int argc, char *argv[]) {
FeedForwardExcitation();
return 0;
}