Discuss Scratch

Gustavo6046
Scratcher
100+ posts

Simple Neural Networks

I have a cool suggestion for simpler embedding of AI in Scratch games: neural networks.

What is a neural network?
A neural network (aka NN) is a mathematical approach to a biological neural network, where a number (called fitness) is used to determine how good the AI performed in the last time it was activated (or how bad if it's called “loss”). This “activation” is when a set of numbers (like for example X, Y, velocity, rotation rate and current rotation) are taken and the neural network, through some mathematical nodes called “neurons”, returns a small set of numbers (like how much it should accelerate/brake and what direction to turn). It takes decision that gave the biggest fitness, while using decisions not yet taken to learn new moves.

How would you implement this?

The neural network is defined like this:

create a neural network ID () with () inputs, () outputs

set neural network number () input to the list ()

(output of the neural network number () )

tell neural network number () it performed as good as ()

  • The first block creates a neural network with the ID of the first argument (index). This network takes as input the first n numbers from the input list, being n the second argument. Same scheme for the output list, except being n the last argument (if you understand me).
  • The second block sets the neural network of the first argument's ID's input list to the list given in the second argument.
  • The third block (round one) is the current output of the neural network of ID n.
  • The last block sets the fitness of the neural network, so it can take decisions. Basically it registers the last activations (i.e. the last time the round block was called) and sets them to this fitness; if the fitness is positive, then it gains. Otherwise it lost. If the fitness is zero, then it's state about decisions doesn't changes… If the neural network gained, then register these last decisions as the one they should take if the condition is equal or similiar to the one set at the time. If it lost, then refrain from doing them.

While this may seem hard, it is actually easy to learn: simply give the network the current stats, take it's output and use it to control, and tell it how good it performed in the last block.

I can try and develop a neural network using my cloning knowledge.

As for the storage of these decisions, let's brainstorm a bit.

That's just a nice suggestion of mine

Thank you!,
Gustavo

Last edited by Gustavo6046 (Nov. 8, 2016 20:31:35)

Gustavo6046
Scratcher
100+ posts

Simple Neural Networks

Ihaveexpectations wrote:

those blocks are too long for the editor.
Shorten them and you have my support.
Done

Ok. Maybe not enough. I'm not good at shortening phrases, sentences or explanations. Could you propose something?

Last edited by Gustavo6046 (Nov. 8, 2016 20:43:32)

alexphan
Scratcher
1000+ posts

Simple Neural Networks

This looks extremely specific for just AI games. Remember, Scratch is about all kinds of projects, not just ones with AI. Plus, this may contradict this part of the Scratch Design Goals:
* Low floor: It should be easy to climb in and get started with Scratch - even for Scratchers who have no experience programming.

Last edited by alexphan (Nov. 8, 2016 20:51:43)

jokebookservice1
Scratcher
1000+ posts

Simple Neural Networks

alexphan wrote:

This looks extremely specific for just AI games. Remember, Scratch is about all kinds of projects, not just ones with AI. Plus, this may contradict this part of the Scratch Design Goals:
* Low floor: It should be easy to climb in and get started with Scratch - even for Scratchers who have no experience programming.
Of course, but I think that this works for lots of AI games where you can use a neural network – they are powerful things…

That said, implementing your own neural network is more fun and educational, so I'd say that this suggestion shouldn't be implemented.
Gustavo6046
Scratcher
100+ posts

Simple Neural Networks

alexphan wrote:

This looks extremely specific for just AI games. Remember, Scratch is about all kinds of projects, not just ones with AI. Plus, this may contradict this part of the Scratch Design Goals:
* Low floor: It should be easy to climb in and get started with Scratch - even for Scratchers who have no experience programming.

1. Yeah, but the AI can calculate all sorts of stuff. And even predict player position, etc etc etc.
2. It is easy; experimentation with NN requires just knowing how good it is, and giving it some values to retrieve output.

P.S.: for more info on Neural Networks read http://neuralnetworksanddeeplearning.com/chap1.html .

jokebookservice1 wrote:

That said, implementing your own neural network is more fun and educational, so I'd say that this suggestion shouldn't be implemented.

IS it fun to insert sigmoids, sums and a lot of workarounds to Scratch limitations in a neural network?
Er, it might be. I'm doing one right now

Last edited by Gustavo6046 (Nov. 8, 2016 21:03:31)

alexphan
Scratcher
1000+ posts

Simple Neural Networks

Gustavo6046 wrote:

alexphan wrote:

This looks extremely specific for just AI games. Remember, Scratch is about all kinds of projects, not just ones with AI. Plus, this may contradict this part of the Scratch Design Goals:
* Low floor: It should be easy to climb in and get started with Scratch - even for Scratchers who have no experience programming.

1. Yeah, but the AI can calculate all sorts of stuff. And even predict player position, etc etc etc.

alexphan wrote:

Remember, Scratch is about all kinds of projects, not just ones with AI.

Jonathan50
Scratcher
1000+ posts

Simple Neural Networks

I like it but don't think it should be primitive. It's something a library is well suited for.
Jonathan50
Scratcher
1000+ posts

Simple Neural Networks

For consistency I think there should be a “Make a Neural Network” button instead of the first block and dropdowns instead of “IDs”.
jokebookservice1
Scratcher
1000+ posts

Simple Neural Networks

alexphan wrote:

Gustavo6046 wrote:

alexphan wrote:

This looks extremely specific for just AI games. Remember, Scratch is about all kinds of projects, not just ones with AI. Plus, this may contradict this part of the Scratch Design Goals:
* Low floor: It should be easy to climb in and get started with Scratch - even for Scratchers who have no experience programming.

1. Yeah, but the AI can calculate all sorts of stuff. And even predict player position, etc etc etc.

alexphan wrote:

Remember, Scratch is about all kinds of projects, not just ones with AI.

So let's remove motion blocks, because some people make animations
alexphan
Scratcher
1000+ posts

Simple Neural Networks

jokebookservice1 wrote:

alexphan wrote:

Gustavo6046 wrote:

alexphan wrote:

This looks extremely specific for just AI games. Remember, Scratch is about all kinds of projects, not just ones with AI. Plus, this may contradict this part of the Scratch Design Goals:
* Low floor: It should be easy to climb in and get started with Scratch - even for Scratchers who have no experience programming.

1. Yeah, but the AI can calculate all sorts of stuff. And even predict player position, etc etc etc.

alexphan wrote:

Remember, Scratch is about all kinds of projects, not just ones with AI.

So let's remove motion blocks, because some people make animations
You could create animation with motion blocks…

I do agree that AI blocks would open up many possibilities, however it's way too specific. There are not many projects with AI in them. I think it would be awesome if someone created something like a neural network Scratch modification.

Another point is that while AI would be cool, it contradicts with the “low floor” statement of the Scratch Design Goals. People with no experience in programming should be able to use Scratch easily.
jokebookservice1
Scratcher
1000+ posts

Simple Neural Networks

Maybe the lack of AI projects is caused by lack of AI blocks And they can use Scratch easily, they just need to learn about those blocks by right clicking them and clicking help, same with lists, same with variables.

Though I do agree with you
-stache-
Scratcher
500+ posts

Simple Neural Networks

alexphan wrote:

This looks extremely specific for just AI games. Remember, Scratch is about all kinds of projects, not just ones with AI. Plus, this may contradict this part of the Scratch Design Goals:
* Low floor: It should be easy to climb in and get started with Scratch - even for Scratchers who have no experience programming.
How would this raise the floor…
You don't have to use them…

Last edited by -stache- (Nov. 8, 2016 22:34:29)

-stache-
Scratcher
500+ posts

Simple Neural Networks

Gustavo6046 wrote:

(neural network [NN v] with [list v] as input ::#6f3)

set correctness of last output of [NN v] to (42) ::#6f3
What about a “new NN” button in the data pane?
CoderOwl
Scratcher
30 posts

Simple Neural Networks

I think this would be too confusing and complicated, and its benefits are limited. No support.
Alberknyis
Scratcher
1000+ posts

Simple Neural Networks

These are extremely specific blocks, though. They're useful when making an AI, but they do nothing otherwise.

First of all, we can't just add blocks to the editor and say “just because they're there doesn't mean you have to use them”. Scratch is designed to be simple. Part of that being simpleness is having a smaller set of functions than other programming languages so that new Scratchers can understand the whole thing faster. With these AI blocks they would be both confusing (try saying “those blocks are for AI” to a person that doesn't know AI) and be an extra set of blocks for them to learn.

My rule for whether a suggested block should even be considered is that it would be true to at least one of these:
A - It would be widely used by Scratchers/It's convenient
B - It does something no other block on Scratch can do

I believe a neural network isn't exactly what Scratch was designed to promote, and that there are other/better/faster* ways to make simple AIs.

*self learning AI's take a while to learn enough to become useful. You'd probably have to leave the project running for a few hours/days.
braxbroscratcher
Scratcher
1000+ posts

Simple Neural Networks

-stache- wrote:

Gustavo6046 wrote:

(neural network [NN v] with [list v] as input ::#6f3)

set correctness of last output of [NN v] to (42) ::#6f3
What about a “new NN” button in the data pane?
No support. Also, that is eyebleed, my good sir.
deletedscratch0
Scratcher
82 posts

Simple Neural Networks

You need a list to keep useful information and a script that controls it and reads the list if there was a mistake.

Last edited by deletedscratch0 (March 16, 2018 22:43:41)

chexbox
Scratcher
100+ posts

Simple Neural Networks

Support, if it is added as a 3.0 extension.
Gustavo6046
Scratcher
100+ posts

Simple Neural Networks

Sorry for the long time away, and the consequential bump.

You are right. A neural network button doesn't go anywhere. But is there any good way of doing one without messing with lots of list logic? Because lists are frustrating…
xenon1345
Scratcher
10 posts

Simple Neural Networks

Maybe add an AI extension?

Powered by DjangoBB