BindsNET Breakout源码分析

2021-03-03 02:29

阅读:518

标签:code   imu   bin   计算   function   col   shape   tpi   std   

BindsNET:https://github.com/BindsNET/bindsnet

相关代码:bindsnet/examples/breakout/

1. breakout.py

技术图片技术图片
from bindsnet.network import Network
from bindsnet.pipeline import EnvironmentPipeline
from bindsnet.encoding import bernoulli
from bindsnet.network.topology import Connection
from bindsnet.environment import GymEnvironment
from bindsnet.network.nodes import Input, IzhikevichNodes
from bindsnet.pipeline.action import select_softmax

# Build network.
network = Network(dt=1.0)

# Layers of neurons.
inpt = Input(n=80 * 80, shape=[1, 1, 1, 80, 80], traces=True)
middle = IzhikevichNodes(n=100, traces=True)
out = IzhikevichNodes(n=4, refrac=0, traces=True)

# Connections between layers.
inpt_middle = Connection(source=inpt, target=middle, wmin=0, wmax=1)
middle_out = Connection(source=middle, target=out, wmin=0, wmax=1)

# Add all layers and connections to the network.
network.add_layer(inpt, name="Input Layer")
network.add_layer(middle, name="Hidden Layer")
network.add_layer(out, name="Output Layer")
network.add_connection(inpt_middle, source="Input Layer", target="Hidden Layer")
network.add_connection(middle_out, source="Hidden Layer", target="Output Layer")

# Load the Breakout environment.
environment = GymEnvironment("BreakoutDeterministic-v4")
environment.reset()

# Build pipeline from specified components.
pipeline = EnvironmentPipeline(
    network,
    environment,
    encoding=bernoulli,
    action_function=select_softmax,
    output="Output Layer",
    time=100,
    history_length=1,
    delta=1,
    plot_interval=1,
    render_interval=1,
)

# Run environment simulation for 100 episodes.
for i in range(100):
    total_reward = 0
    pipeline.reset_state_variables()
    is_done = False
    while not is_done:
        result = pipeline.env_step()
        pipeline.step(result)

        reward = result[1]
        total_reward += reward

        is_done = result[2]
    print(f"Episode {i} total reward:{total_reward}")
View Code
# Build network.
network = Network(dt=1.0) # param dt: Simulation timestep.

bindsnet.network.Network对象是BindsNET的主要工作。它负责协调其所有组成部分的仿真:神经元,突触,学习规则等。其中dt参数指定仿真时间步长,该步长决定要解决仿真的时间粒度(以毫秒为单位)。为了简化计算,所有仿真均使用Euler方法进行。如果在仿真中遇到不稳定性,请使用较小的dt来解决数值不稳定性。

# Layers of neurons.
inpt = Input(n=80 * 80, shape=[1, 1, 1, 80, 80], traces=True)
middle = IzhikevichNodes(n=100, traces=True)
out = IzhikevichNodes(n=4, refrac=0, traces=True)

 

 

2. breakout_stdp.py

3. play_breakout_from_ANN.py

4. random_baseline.py

5. random_network_baseline.py

6. trained_shallow_ANN.pt

BindsNET Breakout源码分析

标签:code   imu   bin   计算   function   col   shape   tpi   std   

原文地址:https://www.cnblogs.com/lucifer1997/p/14293310.html


评论


亲,登录后才可以留言!