我正在尝试教简单的单神经元感知器识别重复序列1
。
这是我用来教它的数据:
learning_signals = [
[[1, 1, 0, 0], 1],
[[1, 1, 0, 1], 1],
[[1, 1, 1, 0], 1],
[[0, 1, 1, 0], 1],
[[0, 1, 1, 1], 1],
[[0, 0, 1, 1], 1],
[[1, 0, 1, 1], 1],
[[0, 0, 0, 0], 0],
[[1, 0, 0, 0], 0],
[[0, 1, 0, 0], 0],
[[0, 0, 1, 0], 0],
[[0, 0, 0, 1], 0],
[[1, 0, 1, 0], 0],
[[1, 0, 0, 1], 0],
# [[0, 1, 0, 1], 0],
这是学习模板的数组,每个模板都是数据数组和该数据的正确结果。
正如你看到的。最后一行评论了——如果我取消评论——感知器将无法学习。如果没有它,感知器在“0101”的情况下无法正常工作。所以问题是:
- 这个任务可以用单个神经元感知器解决还是我应该使用几个分层感知器?
- 我如何确定可以用这样一个简单的感知器解决哪些任务?是否有任何规则可以应用于我的任务并说它可以用简单的感知器完成?
这是用coffeescript编写的perceprton代码:
class window.Perceptron
weights: []
calc: (signal) ->
@neuron.calc signal
adjust: ->
foo: 0.1
calc: (signal) ->
sum = 0
for s, i in signal
sum += s*@weights[i]
if sum>0.5 then return 1 else return 0
sum
learn: (templates) ->
@weights = []
for i in [1..templates[0][0].length]
@weights.push Math.random()
li = 0
max_li = 50000
console.log @weights
while true
gerror = 0
li++
for template, i in templates
res = @calc template[0]
# console.log "result: #{res}"
error = template[1] - res
gerror += Math.abs error
for weight, i in @weights
@weights[i] += @foo*error*template[0][i]
if ((gerror == 0) || li > max_li) then break
if gerror == 0
console.log "Learned in #{li} iterations"
else
console.log "Learning failed after #{max_li} iterations"
console.log @weights