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

Top 5 programming language for artificial intelligence research

Here are the top 5 programming languages for artificial intelligence research: 1. LISP LISP (List Processing) is that high level language which impresses AI developers quite well and has been used in many classic AI Projects as well. The factor that places it at the last position is that, in comparison to others it is not fast. 2. C++ The very reason C++ is used in AI solutions is its speed; it is probably the fastest language out of all. Therefore, whenever speed is the prime concern of any AI developer, C++ is opted. 3. JAVA Java is in the top five because of its familiarity and easy to use features. This OOP language allows easy coding of algorithms which covers the major part of AI. 4. Prolog The reason Prolog is preferred for AI solutions is that it pretty much revolves around a dedicated set of mechanisms which consists of a small, flexible yet well-built programming framework. 5. Python One of the leading languages used for developin...

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...

Computing in Python I: Fundamentals and Procedural Programming

Learn the fundamentals of computer programming in Python, from the basics of how a computer runs lines of code, to the write-run-debug cycle of program development, to working with variables, mathematical operators, and logical operators.      Techhb82    About this course This course starts from the beginning, covering the basics of how a computer interprets lines of code; how to write programs, evaluate their output, and revise the code itself; how to work with variables and their changing values; and how to use mathematical, boolean, and relational operators. By the end of this course, you'll be able to write small programs in Python that use variables, mathematical operators, and logical operators. For example, you could write programs that carry out complex mathematical operations, like calculating the interest rate necessary to reach a savings goal, recommending apparel options based on weather patterns, or calculating a grade based ...