Deep Learning Tools/Nengo
Nengo synapse에 PES learning 적용 예제
바나나인간
2018. 11. 26. 16:48
Nengo에서는 PES learning (https://banana-media-lab.tistory.com/26) 을 synapse에 넣어 학습을 적용할 수 있다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | import numpy as np import matplotlib.pyplot as plt %matplotlib inline import nengo from nengo.processes import WhiteSignal model = nengo.Network() with model: inp = nengo.Node(WhiteSignal(50, high=5), size_out=1) pre = nengo.Ensemble(50, dimensions=1) nengo.Connection(inp, pre) post = nengo.Ensemble(50, dimensions=1) conn = nengo.Connection(pre, post, function=lambda x: np.random.random(1)) inp_p = nengo.Probe(inp) pre_p = nengo.Probe(pre, synapse=0.01) post_p = nengo.Probe(post, synapse=0.01) | cs |
일단 input은 white noise를 input으로 만들고,
해당 input을 받는 presynaptic neuron와 postsynaptic neuron을 만들었다.
input -> pre -> post 식으로 연결되었다.
여기서 synapse에는 random함수로 initialize해주었다.
1 2 | with nengo.Simulator(model) as sim: sim.run(10.0) | cs |
시뮬레이션을 돌리고 plot을 확인해보면
1 2 3 4 | plt.figure(figsize=(12, 4)) plt.plot(sim.trange(), sim.data[inp_p].T[0], c='k', label='Input') plt.plot(sim.trange(), sim.data[pre_p].T[0], c='b', label='Pre') plt.plot(sim.trange(), sim.data[post_p].T[0], c='r', label='Post') | cs |
여기서 검은색 line이 input, 파란색 line이 presynaptic neuron의 활성을 decoding한 것, 빨간색 line은 postsynaptic neuron의 활성을 decoding한 것이다.
1 2 3 4 5 6 7 | plt.figure(figsize=(12, 16)) plt.subplot(2, 1, 1) rasterplot(sim.trange(), sim.data[pre_spike_p]) plt.xlabel('time [s]'); plt.subplot(2, 1, 2) rasterplot(sim.trange(), sim.data[post_spike_p]) plt.xlabel('time [s]'); | cs |
Presynaptic neuron의 활성이 postsynaptic neuron으로 잘 전달되지 않은 것이 보인다
이제 PES synapse를 추가해보자!
1 2 3 4 5 6 7 | with model: error = nengo.Ensemble(50, dimensions=1) error_p = nengo.Probe(error, synapse=0.03) nengo.Connection(post, error) nengo.Connection(pre, error, transform=-1) conn.learning_rule_type = nengo.PES() nengo.Connection(error, conn.learning_rule) | cs |
Error를 표현하는 neuron group를 하나 만들고, post와 pre를 각각 연결해주었다.
여기서 error는 다음의 식으로 계산된다.
Error = actual - target = post - pre
다시 10초의 simulation을 돌리고 활성을 관찰해보자!
띠요오오오옹
시간이 지날수록 postsynaptic neuron이 presynaptic neuron의 활성을 따라 발화한다.
끗!