Hello developers, im into learning part of the neural network system. I was creating a code myself, like converting the deep learning code “from pyhton” to lua. I did all things correctly but there’s an error says that 42. line has error. Anybody can help?
function getRandom(min, max)
return min + math.random() * (max - min)
end
local bldeger= {{3, 1.5, 1},
{2, 1, 0},
{4, 1.5, 1},
{3, 1, 0},
{3.5, .5, 1},
{2, .5, 0},
{5.5, 1, 1},
{1, 1, 0}}
function sigmoid(x)
return 1/(1+math.exp(-x))
end
function train()
local denemeler = 10000
local ogrenmedegeri = 0.1
local w1,w2,b = getRandom(-1,1),getRandom(-1,1),getRandom(-1,1)
for i=0,denemeler,1 do
local randomtable = bldeger[math.random(1,#bldeger)]
local nntoplam = randomtable[1]*w1+randomtable[2]*w2+b
local tahmin = sigmoid(nntoplam)
local hedef = randomtable[3]
local maliyet = (tahmin-hedef)*(tahmin-hedef)
if i % 100 == 0 then
local c=0
for ina=0, #bldeger, 1 do
p = bldeger[ina+1]
--line that gives the error
ptahmin = sigmoid(w1*p[1]+w2*p[2]+b)
c += (ptahmin - p[3])*(ptahmin - p[3])
end
end
local degerslopesi = 2*(tahmin-hedef)
local dpred = sigmoid(nntoplam) * (1-sigmoid(nntoplam))
dzdw1 = randomtable[1]
dzdw2 = randomtable[2]
dzdb = 1
dcost = degerslopesi * dpred
dzdw1 = dcost * dzdw1
dzdw2 = dcost * dzdw2
dzdb = dcost * dzdb
w1 = w1 - ogrenmedegeri * dzdw1
w2 = w2 - ogrenmedegeri * dzdw2
b = b - ogrenmedegeri * dzdb
end
return w1, w2, b
end
local w1,w2,b = train()
print(sigmoid(w1*4.5+w2*1+b))