Skip to content

A Multilayer Neural Network written in Python, capable of solving nonlinear problems. All of the matrix calculations are done by the NumPy library.

Notifications You must be signed in to change notification settings

aryahassibi/Multilayer-Neural-Network

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

Multilayer Neural Network

This Neural Network is written in Python (3.7.6)
All of the matrix calculations of this neural network are done by NumPy(1.9.6)

Multilayer networks solve the classification problem for non linear sets by employing hidden layers, whose neurons are not directly connected to the output.

note: The Activation function of this neural network is the sigmoid function

HOW TO WORK WITH neuralNetwork.py:

  1. Import Class

     from neuralNetwork import *
    
  2. Create an Object

     nn = NeuralNetwork(number_of_first_layer_nodes, number_of_second_layer_nodes, ..., number_of_n-th_layer_nodes)
    

    note: this is a multilayer neural network so it can have as many layers as it wants. for example:

     nn = NeuralNetwork(5, 8, 2, 6, 1)
     nn = NeuralNetwork(6, 3, 4)
    
  3. Generate the inputs and the targets that you want to train your network with
    For training the neural netwrok you should use the train() method:

     nn.train(inputs_list, targets_list)
    

    note: the length of inputs_list should be equal to first argument of the neural network
    and the lenght of targets_list should be equal to last argument of the neural network

    for example this time we are going to train the neural netwrok to solve XOR problem:

     inputs = [[0, 0], [1, 0], [1, 1], [0, 1]]
     targets = [[0], [1], [0], [1]]
    
     # Training the neural network 10000 times
     for _ in range(10000):
         index = randint(0, 3)
         nn.train(inputs[index], targets[index])
    
  4. Getting neural network prediction
    For Getting predictions you should use predict() method:

     nn.predict(inputs_list)
    

    note: the length of inputs_list should be equal to first argument of the neural network

    Again we continue with XOR problem.
    For getting the result after trianing the neural network you can do this:

     inputs = [[0, 0], [1, 0], [1, 1], [0, 1]]
    
     for i in range(4):
         output = nn.predict(inputs[i])[0]
         print("XOR", inputs[i], " ≈ ", output)
    

    output:

       XOR [0, 0]  ≈  0.040257468759495006
       XOR [1, 0]  ≈  0.9490906272946118
       XOR [1, 1]  ≈  0.05838670461374751
       XOR [0, 1]  ≈  0.944367949333263
    

About

A Multilayer Neural Network written in Python, capable of solving nonlinear problems. All of the matrix calculations are done by the NumPy library.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages