-
Notifications
You must be signed in to change notification settings - Fork 1
Get started
To create your own neural network, you first need to understand what they consist of.
The picture clearly shows that the neural network consists of individual layers that are interconnected. Next, we say that the number of outputs is determined by the properties of the last layer. In PSNN, neural networks also consist of layers, this action occurs before the first use of the network and cannot be changed after the first use of the network. This code is used to initialize this network
from PSNN import model, layers, activation
# here we define our model == neural network
netmodel = model([
# layers.dense() is layer object
layers.dense(3, activation.sigmoid()),
layers.dense(2, activation.sigmoid()),
layers.dense(1, activation.sigmoid())
])
# here define how many inputs our network have
netmodel.create(
inputs=(2,)
)
we use learning to make our network able to do what we want it to do. Learning is done by giving the neural network inputs and outputs for these inputs. It should be noted that the more samples (input and output) the better the neural network after learning will work better.
The neural network in PSNN has two learning options, BackPropagation and Evolution. BackPropagation calculates an error for each output and then corrects the neural network using the error. Evolution works on the principle of creating N copies of a neural network and then adjusts the weights randomly on each copy and then selects the one that has the smaller error.
in code first define learning samples
inputs = np.array([
[0, 0], #0
[0, 1], #0
[1, 0], #1
[1, 1], #1
])
targets = np.array([
[0],
[0],
[1],
[1]
])
and now do learning
netmodel.fit(
rate=1, # size of jump when corecting
inputs=inputs, # your inputs
targets=targets, # your outputs for inputs
# replication=200, -> this is num of copyes when use evolution type
epochs=50, # how many times learn this samples
type="backPropagation" # or evolution
)
we use predict when we want to use a neural network on some input and we want its output
netmodel.predict([1,1,0]) # this return output of neural network in numpy array
more example code you can find in /examples dir