Simple Implementation of a Neural Network

Python3

import numpy as np
 
# array of any amount of numbers. n = m
X = np.array([[1, 2, 3],
              [3, 4, 1],
              [2, 5, 3]])
 
# multiplication
y = np.array([[.5, .3, .2]])
 
# transpose of y
y = y.T
 
# sigma value
sigm = 2
 
# find the delta
delt = np.random.random((3, 3)) - 1
 
for j in range(100):
   
    # find matrix 1. 100 layers.
    m1 = (y - (1/(1 + np.exp(-(np.dot((1/(1 + np.exp(
        -(np.dot(X, sigm))))), delt))))))*((1/(
            1 + np.exp(-(np.dot((1/(1 + np.exp(
                -(np.dot(X, sigm))))), delt)))))*(1-(1/(
                    1 + np.exp(-(np.dot((1/(1 + np.exp(
                        -(np.dot(X, sigm))))), delt)))))))
 
    # find matrix 2
    m2 = m1.dot(delt.T) * ((1/(1 + np.exp(-(np.dot(X, sigm)))))
                           * (1-(1/(1 + np.exp(-(np.dot(X, sigm)))))))
    # find delta
    delt = delt + (1/(1 + np.exp(-(np.dot(X, sigm))))).T.dot(m1)
 
    # find sigma
    sigm = sigm + (X.T.dot(m2))
 
# print output from the matrix
print(1/(1 + np.exp(-(np.dot(X, sigm)))))

                    

Output:

[[0.99999325 0.99999375 0.99999352]
[0.99999988 0.99999989 0.99999988]
[1. 1. 1. ]]

What is a neural network?

Neural Networks are computational models that mimic the complex functions of the human brain. The neural networks consist of interconnected nodes or neurons that process and learn from data, enabling tasks such as pattern recognition and decision making in machine learning. The article explores more about neural networks, their working, architecture and more.

Table of Content

  • Evolution of Neural Networks
  • What are Neural Networks?
  • How does Neural Networks work?
  • Learning of a Neural Network
  • Types of Neural Networks
  • Simple Implementation of a Neural Network

Similar Reads

Evolution of Neural Networks

Since the 1940s, there have been a number of noteworthy advancements in the field of neural networks:...

What are Neural Networks?

Neural networks extract identifying features from data, lacking pre-programmed understanding. Network components include neurons, connections, weights, biases, propagation functions, and a learning rule. Neurons receive inputs, governed by thresholds and activation functions. Connections involve weights and biases regulating information transfer. Learning, adjusting weights and biases, occurs in three stages: input computation, output generation, and iterative refinement enhancing the network’s proficiency in diverse tasks....

How does Neural Networks work?

Let’s understand with an example of how a neural network works:...

Learning of a Neural Network

1. Learning with supervised learning...

Types of Neural Networks

There are seven types of neural networks that can be used....

Simple Implementation of a Neural Network

Python3 import numpy as np # array of any amount of numbers. n = mX = np.array([[1, 2, 3],              [3, 4, 1],              [2, 5, 3]]) # multiplicationy = np.array([[.5, .3, .2]]) # transpose of yy = y.T # sigma valuesigm = 2 # find the deltadelt = np.random.random((3, 3)) - 1 for j in range(100):       # find matrix 1. 100 layers.    m1 = (y - (1/(1 + np.exp(-(np.dot((1/(1 + np.exp(        -(np.dot(X, sigm))))), delt))))))*((1/(            1 + np.exp(-(np.dot((1/(1 + np.exp(                -(np.dot(X, sigm))))), delt)))))*(1-(1/(                    1 + np.exp(-(np.dot((1/(1 + np.exp(                        -(np.dot(X, sigm))))), delt)))))))     # find matrix 2    m2 = m1.dot(delt.T) * ((1/(1 + np.exp(-(np.dot(X, sigm)))))                           * (1-(1/(1 + np.exp(-(np.dot(X, sigm)))))))    # find delta    delt = delt + (1/(1 + np.exp(-(np.dot(X, sigm))))).T.dot(m1)     # find sigma    sigm = sigm + (X.T.dot(m2)) # print output from the matrixprint(1/(1 + np.exp(-(np.dot(X, sigm)))))...

Advantages of Neural Networks

...

Disadvantages of Neural Networks

Neural networks are widely used in many different applications because of their many benefits:...

Frequently Asked Questions (FAQs)

Neural networks, while powerful, are not without drawbacks and difficulties:...