I wanna create neural network.
And i done with this code, and help of Sebastian Lague tutorial videos:
code
local NeuralNetwork = {}
NeuralNetwork.__index = NeuralNetwork
--[[
Actually what to do:
New : function - creates new neuralnetwrok(woow)
Forward : function - just get output from input
Backpropagate : function - just get weights from output
Activation : function - sigmoid function yep
Very very important things:
]]
local matrix = require(script.matrix)
local function zip(...)
local args, args_values = table.pack(...), { }
local i = 0
return function()
i = i + 1
for pos, t in ipairs(args) do
args_values[pos] = t[i]
if args_values[pos] == nil then
return nil
end
end
return table.unpack(args_values)
end
end
function NeuralNetwork.new(layer_sizes : {})
local t1, t2 = layer_sizes, layer_sizes table.remove(t1, 1) table.remove(t2, #t2)
local self = setmetatable({}, NeuralNetwork)
local weight_shapes={} for a,b in zip(t1, t2) do table.insert(weight_shapes, {a,b}) end
self.weights = {} for i,s in pairs(weight_shapes) do table.insert(self.weights, matrix.random(s[1], s[2])) end
self.biases={} for i,s in pairs(t1) do table.insert(self.biases,matrix.new(s, 1)) end
print(self.weights)
return self
end
function NeuralNetwork:Forward(input)
for w, b in zip(self.weights, self.biases) do
input = self:Activation(matrix.mul(w, input)) -- matrix.mul isn't correct working
end
return input
end
function NeuralNetwork:Activation(x)
return 1/(1+math.exp(-x))
end
return NeuralNetwork
My current problem is: matrix multiplication, and better understanding all of this