lately i noticed that values in my NN algorithm has been returning bigger and bigger values without environment (connection power and starting values for input layer) being changed.
Turns out the tables were the same all the time and i don’t know why.
Probably because you’re returning a reference to a table instead of a new table (you’re not actually cloning the table). If you can show more code on the neural network it would help a lot.
Calculate = function(Layers,_Sort:boolean)
local OutputResults = {}
local function Sort()
for i = 1,#OutputResults do
local SavedValue = OutputResults[i]
local SortedValue = OutputResults[i].Value
for j = 1,#OutputResults do
if i == j then
continue
end
local SavedValue2 = OutputResults[j]
local ToSwipeValue = OutputResults[j].Value
if ToSwipeValue <= SortedValue then
OutputResults[j] = SavedValue
OutputResults[i] = SavedValue2
i = j
else
break
end
end
end
end
for i = 1,#Layers do
for j = 1,#Layers[i] do
local Cell = Layers[i][j]
local Value = Cell.Value
if not (#(Cell.Connections or {}) > 0) then
continue
end
for x = 1,#Cell.Connections do
local Connection = Cell.Connections[x]
local ConnectionPower = Connection.ConnectionPower
local LayerIndex = Connection.Connection.ConnectionLayer
local CellIndex = Connection.Connection.ConnectionCellIndex
Layers[LayerIndex][CellIndex].Value += Value*ConnectionPower
end
end
if i == #Layers then
for j = 1,#Layers[i] do
table.insert(OutputResults,{Value = Layers[i][j].Value,Index = j})
end
if not _Sort then
continue
end
Sort()
end
end
return OutputResults
end,
FillFirstLayer = function(Layers,StartValue)
for i = 1,#Layers[1] do
Layers[1][i].Value = StartValue
end
return Layers
end