I’m starting to learn NNs which I’ll need for an AI in my game, so I started with a simple one.
The NN will see if the number is negative or positive, it should return 1 if it’s positive.
After a lot of testing, the best result I could get was 64% - I know this can be so much better.
Here’s the current code:
local module = require(game:GetService("ReplicatedStorage").Modules.KNNLibrary)
local runservice = game:GetService("RunService")
local network = module.createNet(1,3,2,1,"LeakyReLU")
local timesToTrain = 1000000
local timesToTry = 10000
local learningRate = 0.01
local tock = tick()
local testNumber = 1
while true do
for i = 1, timesToTrain do
local randomNumber = math.random(-500, 500)
local correctAnswer = 1
if randomNumber < 0 then
correctAnswer = 0
end
module.backwardNet(network, learningRate, {randomNumber}, {correctAnswer})
if (tick() - tock) >= 0.1 then
tock = tick()
runservice.Heartbeat:Wait()
print((i/timesToTrain)*100 .. "% trained")
end
end
local wins = 0
local count = 0
for i = 1, timesToTry do
local number = math.random(-500, 500)/1000
local answer = module.forwardNet(network, {number})[1]
local shouldBeCorrect = 1
if number < 0 then
shouldBeCorrect = 0
end
if math.abs(shouldBeCorrect - answer) <= 0.4 then
wins = wins + 1
print("Got", answer, "- classed as correct")
end
print("Testing, " .. (count/timesToTry)*100 .. "%")
count = count + 1
runservice.Heartbeat:Wait()
end
print("Test number:", testNumber .. "\n" .. (wins/timesToTry)*100 .. "% successful")
testNumber = testNumber + 1
wait(2)
end
(yes it’s messy, but it’s just a test right now)
The library I’m using is the KNNLibrary, I recommend you check it out if you haven’t already.
Any help is appriciated.