Neural Network Library (Obsolete)

Yes but it would recognize only that 1 zero, and have a lot of trouble with any other kind of zero. Basically, you just need to draw a bunch of samples for each digit and then start a training session with those.

1 Like

Hmm… Is there any better way, you think I could train it?

1 Like

That’s the only method there is. To train it, you have to have data to train from. Since you don’t have any data to work with already, you have to make it yourself. Like 10 samples of each digit should be fine.

1 Like

I’ll make like 100 if I need to. But when training it, would I have to train it on every sample, like a million times or something? Or could I take it easy, and train it on like random amount of samples per digit, for like 100,000 times?

1 Like

Yes, just train the network a however much you like for each sample randomly, with no given order. 100,000 times would be a fair bet.

1 Like

After hundreds of generations, it still only scores around 1000.

Is this a result of a poor environment (aka the game itself can’t be played better than that) or a poor reward function? I would have expected to see improvement over time, but gen 20 and gen 800 were pretty much the same.

3 Likes

Generally what is used in practice is we setup computer simulations that creates the data for us. We apply constraints to our simulation model so that our computer simulation is close to actual practice. Then we use a uniform psuedo RNG to shove numbers in and retrieve results. Usually this takes a lot of time and a powerful machine though.

My suggestion is that you will have to essentially outsource your data. Basically create another program, perhaps in another language using another development environment. You can set it up with some algorithms to produce a file with the results you would want or need to pre-train your AI. You would have to run these algorithms/simulations hundreds of thousands of times though for proper results. Then you would have to take those results and copy it over, probably into a ModuleScript. Then you would need to read the data into the NN to process and make decisions.You will need to help it undersand how to process the information though.

2 Likes

Most likely its a mix of both. The AI is really as good as its going to get and the scoring may not be accurate enough for the AI to improve any further.
Ignoring how you managed to simulate the generations at a speed where you can thousands of networks going through a thousand pipes, you may want to instead try another activation function.
Changing that might make a huge difference. You can also try making the network recurrent, which usually gives an added advantage towards live networks.

1 Like

Make sure to calibrate the values for your screen size. To do this change either “jumppower” or “a”. I havent really set it up to specify the canvas of the screen. It should easily score around 10k on the 5th generation. Ill make an updated version. It is jumping correctly but it seems to be jumping too high making it always hit the top pipe.

2 Likes

Fixed flappy.rbxl (41.5 KB)
Check if this works for you.

3 Likes

Yup! That was it. Works properly now, I think. Environment definitely scaled to be possible at least.

This was the case then, as the game itself really couldn’t be played with those settings.


image

Why does it sometimes do freaky well (Gen 4 and more so Gen 15) and then get worse and worse?

1 Like

Because the levels are random. If the levels were the same, the best score would never go down. But when chance is at play, the score can go up and down at random intervals.
For the crazy good scores, that’s probably because the bot got lucky and it didn’t find any difficult pipes on the way by chance (opening on the top followed by an opening on the bottom of the pipe).

2 Likes

Okay im not sure what i am doing wrong, the network seems to work but it does not seem to be learning anything. What am i doing wrong?

-- creating the neural network --
local inputs = 6
local hiddenL = 10 -- hidden layers 
local hiddenN = 10 -- hidden nodes
local outputs = 2 
local activator = "Sigmoid" --"Identity", "Binary", "Sigmoid", "Tanh", "ArcTan", "Sin", "Sinc", "ArSinh", "SoftPlus", "BentIdentity", "ReLU", "SoftReLU", "LeakyReLU", "Swish", "ElliotSign", "Gaussian", "SQ-RBF"
local recurrent = true 
local Bias = 0.5 -- default bias
local network = module.createNet(inputs,hiddenL,hiddenN,outputs,activator,recurrent,Bias) 
--------------------------------

local b = tick()
local scores = {}
local gen = 1
local died = "fr"

local cam = workspace.CurrentCamera
--[[local vis = module.getVisual(network)
vis.Parent = game.StarterGui]]

onDied:Connect(function()
	died = true
end)

while wait() do
	if not died then
		local closest = getClosest()
		local Input1,Input2,Input3
		if closest then
			Input1 = cam.CFrame.Position.X - closest.Position.X--Distance to the part
			Input2 = closest.Index.X
			Input3 = closest.Index.Y	
		else
			Input1 = 10000
			Input2 = 0
			Input3 = 0
		end
		Input4 = cam.CFrame.LookVector.X
		Input5 = cam.CFrame.LookVector.Y
		Input6 = cam.CFrame.LookVector.Z
		inputs = {Input1,Input2,Input3,Input4,Input5,Input6}
		local out = module.forwardNet(network,inputs)
		print(out[1],out[2])
		module.backwardNet(network, 0.01, inputs, out)
		fakeMouseMove((out[1]-0.5)*25,(out[2]-0.5)*25)
	else
		local score = tonumber(mainObj.Score.Text)
		table.insert(scores,score)
		warn("Generation: "..gen.." Score: "..score)
		gen=gen+1
		if died ~= "fr" then
			--best = module.runGenNet(network,scores)
		end
		--module.updateVisualState(network,vis)
		wait(1)
		restartGame()
		died = false
	end
end

Are you perhaps trying to create a neural network to detect aimbots? You are trying to combine backwardnet with forwardnet. That might work or might not (not sure), but when you use backwardNet with the value from forwardNet as the “truth” value it wont do good. You assume that forwardNet always gives correct results that you put into the backwardNet function. This is not the case as in forwardNet just runs and at first spits out random numbers.

I suggest you to figure out your “truth” value based on your inputs. Then you would train it based on those if you use backwardNet (backward propagation).


It might be a bit ambitious but I am attempting to make a sword fighting AI. Im just wondering if anyone had thoughts on what inputs and fitness functions and outputs would be good too use.

What I currently have:

  • Inputs (5 rays) measuring distances to an object

outputs

-Slash
-Lunge
– if one of the value >0.5 then do actions for that value–

If value >0.5 then move left | value <= 0.5 move right
-Right

if value > 0.5 then move forward | value <= 0.5 move back
-Front

Fitness function: Score based on kills. Timeout on 10 sec to kill all of them

Result:
It spins around and just hits randomly with the sword.

I don’t think you would be using NN for deciding which direction to move. When there is nothing in the vicinity, it isn’t necessary to know where to move. For this type of AI, the circumstances are constantly changing so it makes it difficult to deduce. It would require a lot more testing, and even then I am not sure if you can deduce a proper set of actions and behaviors. Now, you can use NN for deducing between multiple targets within the vicinity. Then deciding how the AI should deal with this through a NN would work. Unless you want to create habits and handicaps for the AI, you should only account for within a certain range of the AI. Your inputs are adequate, although you don’t need 5 inputs in certain directions. You can get away with 3 primary inputs, <x,y,z>. The rest is just collision detection that you would have to figure out.

2 Likes

When using loadNet(netWork) I get an error that says: Can't parse JSON.

network is a stringvalue with the string inside (the string contains the information about the network). What I usually do is let it run and copy the network folder. You will see stringvalues inside. Alternatively create a stringvalue and paste the string from you datastore into it and then call

local StringValue = script.StringValue – path to it. Remember to assign the network string
loadNet(StringValue)

TL:DR: Did you make sure the argument inside loadNet function is an object called StringValue

Hi. I was playing around with your module and came with this question. How would I feed the information of vector, such as look vectors and Position vector. Would I convert it into a single integer or should I separately feed in the x, y, and z into different nodes?

2 Likes

Out of those 2 methods, splitting it into the 3 XYZ components and then scaling it 0-1 is the best option.

1 Like