Skip to main content

A Simple Neural Network to Recognize Patterns


Lets build a program that will teach the computer to recognize simple patterns using neural networks.
Artificial neural networks, like real brains, are formed from connected "neurons", all capable of carrying out a data-related task, such as answering a question about the relationship between them.
Let's take the following pattern:
1 1 1 = 1
1 0 1 = 1
0 1 1 = 0
Each input, and the output can be only a 1 or a 0. If we look closer, we will realize that the output is 1, if the first input is 1. However, we will not tell that to the computer. We will only provide the sample inputs and outputs and ask it to "guess" the output of the input 1 0 0 (which should be 1).
To make it really simple, we will just model a single neuron, with three inputs and one output.
The three examples above are called a training set.
We're going to train the neuron to work out the pattern and solve the task for input 1 0 0, by just having the training set and without knowing what operation it performs.
Training
We will give each input a weight, which can be a positive or negative number. An input with a large positive weight or a large negative weight, will have a strong effect on the neuron's output. Before we start, we set each weight to a random number. Then we begin the training process:
1. Take the inputs from the training set, adjust them by the weights, and pass them through a special formula to calculate the neuron's output.
2. Calculate the error, which is the difference between the neuron's output and the desired output in the training set example.
3. Depending on the direction of the error, adjust the weights.
4. Repeat this process 10,000 times.
Eventually the weights of the neuron will reach an optimum for the training set. This process is called back propagation.
Forthe formula, we will take the weighted sum of the inputs and normalize it between 0 and 1: 

After each iteration, we need to adjust the weight based on the error (the difference of the calculated output and the real output). We will use this formula:
adjustment = error*input*output*(1-output)
This will make the adjustment proportional to the size of the error. After each adjustment the error size should get smaller and smaller.
After the 10.000 iterations, we will have optimum weights and then we can give the program our desired inputs. The program will use the weights and calculate the output using the same weighted sum formula as above.
  
       If do you like this post and want more about neural networks than comments and feel free.

Comments

Popular posts from this blog

Web Developer's Knowledge Base

Knowing HTML very well is a must for every web developer, but more importantly, if you want to have outstanding look and feel of your web app, you have to master CSS as well. And of course, used both at backend and frontend, JavaScript is the main weapon in every web developer's inventory. In this article, we will try to cover core concepts every web developer should know about. HTTP Protocol HTTP stands for Hypertext Transfer Protocol. As a web developer, you should be familiar with at least the main HTTP methods, GET, POST, PUT, DELETE. Also, it is really preferred to know the common HTTP status codes: 200 (OK), 400 (Bad Request), 404, 500 etc. Remember: - 2xx are success codes - 3xx, redirection codes - 4xx indicate client errors, and - 5xx indicate server errors. Most APIs are currently supporting HTTPS instead of HTTP.  HTTPS stands for HTTP Secure, where the communication between the client and the server is encrypted. API API stands for Applicati...

The Entrepreneurial Journey of Ashish Mishra: A Visionary Leader in Business and Technology

In the dynamic world of business and technology, Ashish Mishra stands out as a true trailblazer, successfully navigating the realms of entrepreneurship with two thriving ventures under his belt. With an impressive background as a salesperson and a keen eye for business opportunities, Ashish has carved a niche for himself as the founder and driving force behind Pentagon Decorators and Tech HB82. Early Career: A Foundation in Sales Ashish's journey into the business world began as a salesperson, where he honed his communication skills and developed a deep understanding of customer needs. Spending nearly three years in the challenging yet rewarding field of sales laid the groundwork for his future ventures. It was during this time that he cultivated the entrepreneurial spirit that would eventually lead him to launch his own businesses. Tech HB82: Bridging the Gap in Technology In 2019, Ashish took a bold step into the tech industry with the inception of Tech HB82. Recognizing the eve...

Python: 7 Important Reasons Why You Should Use Python

According to the latest TIOBE Programming Community Index, Python is one of the top 10 popular programming languages of 2017 . Python is a general purpose and high level programming language. You can use Python for developing desktop GUI applications, websites and web applications. Also, Python, as a high level programming language, allows you to focus on core functionality of the application by taking care of common programming tasks. The simple syntax rules of the programming language further makes it easier for you to keep the code base readable and application maintainable. There are also a number of reasons why you should prefer Python to other programming languages 7.Reasons Why You Must Consider Writing Software Applications in Python 1)  Readable and Maintainable Code While writing a software application, you must focus on the quality of its source code to simplify maintenance and updates. The syntax rules of Python allow you to express concepts with...