Discuss Scratch

roman_nichols02
New to Scratch
2 posts

Neural net??

I am currently trying to make an AI with scratch.
im using the game from “chrome there is no internet connection” game

the idea is the AI will be able to choose randomly whether it jump or not. over generations the dinosaur will learn when to jump and how to play the game based on a fitness variable. the further the dinosaur gets the higher the fitness variable goes. after a certain number of randomly generated jumps the one that gets the farthest becomes the input and it makes more random scenarios based on it. eventually the AI knows how to play the game.

I like this idea but i need help with how to make it happen . can anyone help me. im pretty new to neural nets. im a new sophmore and am currently in geometry 1. any help would be much appreciated
clarence112
Scratcher
500+ posts

Neural net??

I just recently learned this stuff myself, so it might be a little wrong, but I'll try to explain anyway.

Neural networks really just boil down to four elements:
  • Inputs
  • Outputs
  • Neurons
  • Axons

Inputs:
Inputs give off a decimal value between -1 and 1.
They can generate that signal from pretty much anything.
In your case, I'd say you need two inputs: one to see how far to the next obstacle, and one to see how far off the ground it is.

Outputs:
Outputs are how the neural network interacts with other things.
They add all the values they are receiving, and if the result is above a threshold the output activates.
I In your case, I'd say you need two outputs: one to make the dino jump, and one to make the dino duck.

Neurons
Neurons add all the values they are receiving, add them together, run the result through a sigmoid function, and output that result.
Look below for an implementation of a sigmoid function in scratch.

Axons
Axons connect two neurons together.
They have an input side, an output side, and a bias.
They take their input value, multiply it by their bias, and output the result.

Here's a scratch implementation of a sigmoid function:
define sigmoid (base) with curve (curve)
(curve) ^ ((-1) * (base))
set [sigmoid result v] to (((2) * ((1) / ((1) + (exponent result)))) - (1))

define (base) ^ (power)
set [exponent result v] to ([10 ^ v] of ((power) * ([log v] of ([abs v] of (base))))
if <(power) = (0)> then
set [exponent result v] to (1)
end
if <(base) < (0)> then
set [exponent result v] to ((exponent result) * (-1))
end
The base input can be any value, and is what the neurons input value is.
The curve input changes how the function behaves. Any value between 0 and 1 will have a negative correlation between the input and the result, and any value greater than 1 will have a positive correlation.

The connections, bias/curve values, and output thresholds of all inputs/outputs/axons/neurons should be evolved.

I hope this stuff helps.

I'M the evil kumquat!
Want to help out with world building? Click here!
OH, DID U GET THE BROOM CLOSET ENDING? THEB ROOM CLOSET ENDING WAS MY FAVRITE!1 XD
Check out Byte, my W.I.P. scratch-inspired pygame IDE
620 posts as of Nov 7, 2019, 11:56 AM EST




.
roman_nichols02
New to Scratch
2 posts

Neural net??

im gonna study this for next few days and try to apply it thank you
DrSpoculus
New to Scratch
2 posts

Neural net??

Any chance of a breakdown, for idiots like myself?

I can't read the mathematical equation. and I can't find anywhere or anyone who just simply breaks it down, step by step, of how to implement or code one.

I tried to copy the one above, but i'm just not getting what it's doing. Like, the top part, it has a purple block, Curve ^ -1… Is that needed is that doing anything? Am i supposed to make a block using the example below since they are named similar?

I need a "Click this block first, it's going to….. then next we use this block, it's going to…

So frustrating to find help. It seems like nobody actually understand what a sigmoid function is doing or how it works, they just repeat the wiki or quick rundown they heard from a tutorial.

Not saying that's the case here. I do appreciate the help and the visual reference for help.

DrSpoculus
New to Scratch
2 posts

Neural net??

Using that Sigmoid function diagram I'm getting 2 and -2 only. Should be 1 and -1, i thought? I'm not smart enough to figure out what's wrong. Anyone got an idea?
MasterScratchC
Scratcher
49 posts

Neural net??

this is my version of a sigmoid function

you need an exponential function first:

define (base)^(power)
set [exponential result v] to ([10^ v] of ((power) * ([log v] of ([abs v] of (base)))))
if <(power) = [0]> then
set [exponential result v] to [0]


else
if <<<([mod v] of (power)) = [0]> and <(power) < [0]>>> then
set [exponential result v] to ((power) * (-1))
end
end

and here is the sigmoid function

define sigmoid (number)
(2.71828)^((power) * (-1))
set [sigmoid v] to ((1) / ((1) + (exponential result)))

define me
ask [do you like bananas?] and wait
if <(answer) = [yes]> then
say (join [me too! ] (conversation about bananas)
else
if <(answer) = [no]> then
show list [why bananas are good v]
start discussion on (why bananas are good) ::sound
end
end
MasterScratchC
Scratcher
49 posts

Neural net??

in the mod of power it should be power mod 2

define me
ask [do you like bananas?] and wait
if <(answer) = [yes]> then
say (join [me too! ] (conversation about bananas)
else
if <(answer) = [no]> then
show list [why bananas are good v]
start discussion on (why bananas are good) ::sound
end
end
CoolCrafter1231
Scratcher
100+ posts

Neural net??

how would you do this in reverse like to backpropagate

Back to help on the forums

Profiles
postpercent | Scratch | ocular
scott170
Scratcher
84 posts

Neural net??

don't forget about calculus

Powered by DjangoBB