Is this an infant Neural Network, or just random code?
Posted: Sun Sep 28, 2014 3:06 am
Hi there,
I'm just wondering if anybody out there has ever tried simulating anything with neural networks? I'd like to eventually code an evolution simulation based on NN's but I don't know if my code is viable or if I'm totally on the wrong track. If anyone has any experience I'd love if you could critique my (very basic - no back propagation yet) Neuron code. Thanks in advance!
I'm just wondering if anybody out there has ever tried simulating anything with neural networks? I'd like to eventually code an evolution simulation based on NN's but I don't know if my code is viable or if I'm totally on the wrong track. If anyone has any experience I'd love if you could critique my (very basic - no back propagation yet) Neuron code. Thanks in advance!
Code: Select all
Neuron = {}
function tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
function Neuron:new(o)
o = o or {}
setmetatable(o, self)
self.__index = self
return o
end
function Neuron:init(inputs)
self.inputs = inputs
self.weights = {}
for i = 1, tablelength(self.inputs), 1 do
self.weights[i] = love.math.random() * 2.0 - 1.0
end
end
function Neuron:fire()
local weightedInput = 0
for i = 1, tablelength(self.inputs), 1 do
weightedInput = weightedInput + self.inputs[i] * self.weights[i]
end
return math.tanh(weightedInput)
end