Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create basic neural network in Python/Pygame?

I am trying to understand how to create a basic, simple neural network in Python/Pygame. I have read this tutorial and my aim is to create a program similar to the program that is described in "AI junkie". Although this tutorial is pretty simple. I still don't fully get it, and I am not sure about the connection between the output of the neurons to the movement of the tanks. Where can I find a simple, basic code of a program like this written in pygame/python, to try improving my understanding of the implementation of the algorithm?

Thanking you in anticipation!

like image 893
user1767774 Avatar asked Sep 24 '26 18:09

user1767774


1 Answers

Check @Nathan's Python code in this post. It's pretty clean and also good to take as a start point.

If you want logistic activation:

def logistic(x):
    return 1/(1+math.exp(-x))

# derivative of logistic
def dlogistic(y):
    return y*(1-y)

The default activation function is tanh in the original code.

It's quite straightforward to construct a network and start training:

# create a network with 5 inputs, 20 hiddens, and one output nodes
n = NN(5, 20, 1)
like image 68
greeness Avatar answered Sep 26 '26 16:09

greeness



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!