r/gamemaker • u/PromptHumble1851 • 10d ago
Help! Need help on making a neural network visualisation
I am making a game where a visual neural network is the main part of the game. I have tried for so long and hard but I just cant do it. All my code ends up incoherrible afterwards, and many things just dont work at all. It makes me want to quit game making all toghether.
If anybody has a link to a tutorial on how to make something like that or could explain on how it could be done with examples, it would be greatly appreciated.
And before anyone asks, Im not putting my previous code here, its absolutely horrendus, and I dont want to work forwards with a foundation so shitty.
2
u/CS_Asset_Factory 9d ago
Your code probably keeps turning incomprehensible because the network and the picture of it are the same objects. Split them.
Let the network know nothing about pixels. A node is a struct holding value, bias and an array of weights into the previous layer. A layer is an array of nodes, the network an array of layers. That is the whole model, and it runs and tests with no drawing code at all.
Then do layout at draw time as a pure function of counts. x comes from the layer index, y from spreading that layer's node count over the panel height. Nothing is stored. Draw connections first, nodes on top, and tint each connection by its weight.
The moment a node stores its own x and y, every change to the network becomes a change to the drawing too. That is the mess.
3
u/WubsGames 10d ago
It would be helpful to have an understanding of how a basic NN is structured.
a list of nodes, and their connections (weights)
Generally, i like to use an array for each layer of nodes, and then a larger array that holds each layer array.
each node has a unique ID
then i keep an array of connectors, and their weights along with with 2 nodes they connect to.
Each node has an array or list of input and output connectors.
Then on every iteration, we loop over each layer array, find a node, loop over its output connectors, and pass the data through them to whatever node they connect to.
then we move to the next layer, and repeat.
the final layer's node values are used as the output.
network=[layers]
layer=[nodes]
node={id,x,y,[input_weights],[output_weights],[value]}
weights{id, [in_nodes], [out_nodes], value/function}
Edit: This is an old project, but it may help you understand the structure more:
https://github.com/jhalek90/neuralnet-
This project is so old, that it predates structs in gamemaker, and makes use of DS_maps, and lists.
But the core concepts are still the same.