Lec 2 Overall Introduction of BrainCog

Hello everyone, this time we will bring you the overall introduction of BrainCog. In addition to providing different basic components to facilitate the development of brain-inspired artificial intelligence and brain simulation, BrainCog also provides many basic examples for everyone to learn and use.

Basic Components of BrainCog

Neuron Models

We provide different neuron types in the “node” under the BrainCog “base” directory, such as common IF neurons, LIF neurons, Izhikevich neurons, H-H neurons, etc. Users only need to inherit BaseNode and define their own membrane potential accumulation “integral” and spikes firing “calc_spike” method to define their desired neurons.

def integral(self, inputs):
    self.mem = self.mem + inputs
def calc_spike(self):
    self.spike = self.act_fun(self.mem - self.get_thres())
    self.mem = self.mem * (1 - self.spike.detach())

Encoding Method

We define different encoding methods in the “encoder” under the BrainCog “base” directory, such as temporal coding, rate coding, phase coding, direct coding, etc. Users can choose different coding methods according to their own needs. They can call in the following way to get the rate coding sequence of T=10.

encoder = Encoder(step=10, encode_type = 'rate')
inputs = encoder(inputs)

Connection

The “connection” in the “base” directory provides different neural network connection modes, such as lateral inhibition, local connection, feedforward connection, feedback connection, etc. The connection modeling methods are defined in “CustomLinear.py”, so you can design your own neural network architecture by entering the weight matrix and connection matrix mask.

class CustomLinear(nn.Module):
    def __init__(self, weight,mask=None):
        super().__init__()
        self.weight = nn.Parameter(weight, requires_grad=True)
        self.mask=mask

Learning Rule

The “learningrule” under the “base” directory integrates a rich set of brain-inspired learning plasticity rules: Hebb’s rule, STDP, STP, LTP, BCM, etc.

class STDP(nn.Module):
     def forward(self, x):
        x = x.clone().detach()
        i = self.connection(x)
        with torch.no_grad():
            s = self.node(i)
            i.data += s - i.data
            trace = self.cal_trace(x)
            x.data += trace - x.data
        dw = torch.autograd.grad(outputs=i, inputs=self.connection.weight, grad_outputs=i)

Brain Area

Based on these basic components, different functional brain regions can be constructed (see the “brainarea” directory). In the case of the basal ganglia, for example, it is possible to build excitatory and inhibitory connections between different nuclei in the basal ganglia by invoking neurons, learning rules, and connection classes, and assigning plasticity mechanisms to the connections.

from BrainCog.base.node.node import IFNode,SimHHNode
from BrainCog.base.learningrule.STDP import STDP,MutliInputSTDP
from BrainCog.base.connection.CustomLinear import CustomLinear

Brain-inspired AI models

Based on the easy-to-use basic components of BrainCog, we have also released 18 spiking neural network based brain-inspired AI models (see the “examples” directory), which initially implement five cognitive functions: perception and learning, decision making, motor control, knowledge representation and reasoning, and social cognition. The technical details will be described in a subsequent public issue.

Perception and Learning

BrainCog supports a variety of supervised and unsupervised training algorithms, such as STDP, backpropagation, and ANN to SNN conversion algorithms. It achieves outstanding adaptability in small samples and noisy environments. BrainCog also provides a multisensory integration framework that mimics human concept learning.

Decision Making

BrainCog provides multi-brain areas coordinated decision-making spiking neural network and a spiking deep Q-network. The biologically inspired decision-making model implemented by BrainCog achieves human-like learning ability on the Flappy Bird game and supports UAVs’ online decision-making tasks. In addition, BrainCog combines SNNs with deep reinforcement learning and provides the brain-inspired spiking deep Q network.

Motor Control

BrainCog has initially implemented multi-brain areas coordinated spiking neural network model for robotic motor control and applied it to a humanoid robot playing piano.

Knowledge Representation and Reasoning

BrainCog incorporates multiple neuroplasticity and population coding mechanisms for knowledge representation and reasoning. The brain-inspired music memory and stylistic composition model implements the knowledge representation and memory of note sequences and can generate music according to different styles. Sequence Production Spiking Neural Network (SPSNN) achieves the memory of the symbol sequence and can reconstruct the symbol sequence in the light of different rules. Commonsense Knowledge Representation Graph SNN (CKR-GSNN) realizes the representation of commonsense knowledge through incorporating multi-scale neural plasticity and population coding mechanism into a graph SNN model. Causal Reasoning Spiking Neural Network (CRSNN) encodes the causal graph into a spiking neural network and realizes deductive reasoning tasks accordingly.

Social Cognition

BrainCog provides a brain-inspired social cognition model with biological plausibility. This model gives the agent a preliminary ability to perceive and understand itself and others and can enable the robots pass the Multi-Robots Mirror Self-Recognition Test and the AI Safety Risks Experiment.

Brain Simulation

BrainCog can support the simulation of brain structure and cognitive function at different scales in the brain simulation part, so as to provide strong support for the verification of scientific conjecture and interpretation at local and whole brain scales.

BrainCog has initially realized the simulation of linear and nonlinear decision-making and PFC working memory function. In terms of brain structure simulation, BrainCog can simulate biological brain structures of different scales. The following mouse brain simulation model will be taken as an example to give us a brief introduction:

Open the Examples folder on the BrainCog main menu, followed by the Multiscale_Brain_Structure_Simulation subfolder.

img.png

We can see these folders: Corticothalamic column, human_PFC_model, Mouse_brain simulation, Macaque _Brain ,Human_brain. Open the Mouse_brain folder.

img_1.png

According to README, download the weight matrix of 213 mouse brain region connections published by the Allen Brain Institute from the web link and place it in the file for the local running.

img_2.png

Download the Python file from Mouse_model to the same folder.

img_3.png

The ratio of different types of neurons, the parameters of neurons, and the time of simulation can be set according to the requirements.

img_4.png

Taking the 200ms simulated mouse brain model as an example, A.MAT data file will be generated after local running, and the drawing software of the program will automatically present the scatter diagram of the whole spiking brain.

img_5.png