相互抑制
大约 3 分钟案例案例
抑制性神经元之间的交流可以赋予回路有趣的特性。例如,如果抑制神经元A直接抑制抑制神经元B, 那么A的激活将解除对B的靶神经元的抑制。如果B也抑制A,那么它们就形成了相互(互惠)的抑制。 相互抑制被广泛应用于表现出节律性活动的电路中,例如涉及运动的回路。 甲壳类动物的口胃神经节就是一个典型的例子。在更长的时间范围内,相互抑制也可以用来调节大脑状态,如睡眠-觉醒周期。
简要拓扑图
代码示例
#
# 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):
POTENTIALS = ["potentials", "output", "firePotentials"]
plt.figure()
# Hidden1
plt.subplot(2, 1, 1)
plt.title("Hidden1 potentials")
captures = session.getCaptures(hidden1, POTENTIALS)
visualizeHelper.plotPotentials(captures, [0])
# output
plt.subplot(2, 1, 2)
plt.title("Hidden2 potentials")
captures = session.getCaptures(hidden2, POTENTIALS)
visualizeHelper.plotPotentials(captures, [0])
plt.show()
def MutualInhibition():
# Session
session = Session("session")
# Make input group
input = session.makeNeuronGroup(
"SequenceInput",
number=2,
totalTime=512,
inputBuffer=randomInput(2, 512)
)
# Make hidden1 group
hidden1 = session.makeNeuronGroup(
"General",
number=1,
thresholds=-25,
restingPotentials=-70,
decays=0.8,
potentials=-70
)
# Make hidden1 reduce
hidden1Reduce = session.makeModel(
"Reduce",
number=2
)
hidden1Reduce.output("output").connect(hidden1.input("input"))
# Make hidden2 group
hidden2 = session.makeNeuronGroup(
"General",
number=1,
thresholds=-25,
restingPotentials=-70,
decays=0.1,
potentials=-70
)
# Make hidden2 reduce
hidden2Reduce = session.makeModel(
"Reduce",
number=2
)
hidden2Reduce.output("output").connect(hidden2.input("input"))
# Make edge1
edge1 = session.makeSynapseGroup(
"SimpleSynapse",
inputNumber=2,
outputNumber=1,
weights=9
)
input.output("output").connect(edge1.input("input"))
edge1.output("output").connect(hidden1Reduce.input("input0"))
edge1.connect(0, 0)
# Make edge2
edge2 = session.makeSynapseGroup(
"SimpleSynapse",
inputNumber=2,
outputNumber=1,
weights=6
)
input.output("output").connect(edge2.input("input"))
edge2.output("output").connect(hidden2Reduce.input("input0"))
edge2.connect(1, 0)
# Make edge3
edge3 = session.makeSynapseGroup(
"SimpleSynapse",
inputNumber=1,
outputNumber=1,
weights=-18
)
hidden1.output("output").connect(edge3.input("input"))
edge3.output("output").connect(hidden2Reduce.input("input1"))
edge3.connect()
# Make edge4
edge4 = session.makeSynapseGroup(
"SimpleSynapse",
inputNumber=1,
outputNumber=1,
weights=-18
)
hidden2.output("output").connect(edge4.input("input"))
edge4.output("output").connect(hidden1Reduce.input("input1"))
edge4.connect()
# Add monitor
POTENTIALS = ["potentials", "output", "firePotentials"]
session.addMonitors(hidden1, POTENTIALS)
session.addMonitors(hidden2, 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)
if __name__ == "__main__":
MutualInhibition()
/**
* 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();
uint8_t *data = (uint8_t *) inputs.getData();
for (size_t i = 0; i < total; i++) {
data[i] = rand() % 2;
}
return inputs;
}
void MutualInhibition() {
/// Session
ocean::Session session;
/// createExecutionEngine input group
ocean::Arguments args;
args["number"] = 2u;
args["totalTime"] = 512u;
auto input = session.makeNeuronGroup("SequenceInput", args);
/// hidden1 group
args.clear();
args["number"] = 1u;
args["thresholds"] = -25.f;
args["restingPotentials"] = -75.f;
args["decays"] = 0.1f;
args["potentials"] = {-70.f, -30.f};
auto hidden1 = session.makeNeuronGroup("General", args);
/// hidden1 reduce
args.clear();
args["number"] = 2u;
auto hidden1Reduce = session.makeModel("Reduce", args);
hidden1Reduce->out("output")->connect(hidden1->in("input"));
/// hidden2 group
args.clear();
args["number"] = 1u;
args["thresholds"] = -25.f;
args["restingPotentials"] = -75.f;
args["decays"] = 0.1f;
args["potentials"] = {-70.f, -30.f};
auto hidden2 = session.makeNeuronGroup("General", args);
/// hidden1 reduce
args.clear();
args["number"] = 2u;
auto hidden2Reduce = session.makeModel("Reduce", args);
hidden2Reduce->out("output")->connect(hidden2->in("input"));
/// edge1
args.clear();
args["weights"] = 12.f;
args["inputNumber"] = 2;
args["outputNumber"] = 1;
auto edge1 = session.makeSynapseGroup("SimpleSynapse", args);
input->out("output")->connect(edge1->in("input"));
edge1->out("output")->connect(hidden1Reduce->in("input0"));
edge1->connect(0u, 0);
/// edge2
auto edge2 = session.makeSynapseGroup("SimpleSynapse", args);
input->out("output")->connect(edge2->in("input"));
edge2->out("output")->connect(hidden2Reduce->in("input0"));
edge2->connect(1u, 0);
/// edge3
args.clear();
args["weights"] = -18.f;
args["inputNumber"] = 1;
args["outputNumber"] = 1;
auto edge3 = session.makeSynapseGroup("SimpleSynapse", args);
hidden1->out("output")->connect(edge3->in("input"));
edge3->out("output")->connect(hidden2Reduce->in("input1"));
edge3->connect(0u, 0u);
/// edge4
args.clear();
args["weights"] = -18.f;
args["inputNumber"] = 1;
args["outputNumber"] = 1;
auto edge4 = session.makeSynapseGroup("SimpleSynapse", args);
hidden2->out("output")->connect(edge4->in("input"));
edge4->out("output")->connect(hidden1Reduce->in("input1"));
edge4->connect(0u, 0u);
/// compile model
if (!session.compile(ocean::CompileOption::cpu())) {
std::cout << "Compile model failed" << std::endl;
return;
}
/// add monitor
session.addMonitors(hidden1, {"potentials", "output", "firePotentials"});
session.addMonitors(hidden2, {"potentials", "output", "firePotentials"});
/// set input
input->setStatus("inputBuffer", randomInput(512, 2));
/// run model
ocean::RunOption option{false, true, 512};
session.run(option);
auto monitorVars1 = session.getCaptures(hidden1, {"potentials", "output", "firePotentials"});
auto monitorVars2 = session.getCaptures(hidden2, {"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}, hidden1->getStep());
/// output potentials
plt::subplot(2, 1, 2);
plt::title("Hidden2 potentials");
ocean::plotSingleNeuronStates(monitorVars2, {0}, hidden2->getStep());
plt::show();
}
}
int main(int argc, char *argv[]) {
MutualInhibition();
return 0;
}