Artificial Intelligence TechC++Learn C++

AI Techs :: Very Simple Artificial Neural Network Example in C++

In this post, we will try to explain how to simulate a very simple artificial neural network in C++ and this is a good introduction to Artificial Intelligence Technologies. Artificial Intelligence is being widely explained well in Computer Science and many other disciplines, when we search simple examples in C++ it is really hard to find simple examples. The main aim of this post is to give an AI example in C++ as simple as possible and this post is also a good example of an introduction to Neural Network (ANN).

Very Simple Artificial Neural Network Example in C++

Here below we prepared a a very simple Artificial Neural Network example with an Activation Function given,

In this ANN example we have 2 input neurons and one output neuron. Neuron 0 and Neuron 1 are connected with Neuron 2. Each neuron will have their activation value (a) and each of the links between neurons will have weights. So output neuron will be the result of activation of the sum of 2 input neuron activations multiplied in their weights.

Output of the neuron may have a value in this current state. We should calculate it’s new activation value by the activation function phi(). Let’s define a simple linear activation function

Here we assume that our network was trained before, that means weights of net links are known. Let’s define and initialize our all neural activation and weight values,

Note that, the number of neural net links are not same with number of neurons. That means, links and weights can be handled in another array. We defined a2 before and we set it to 0 which is not correct in this network, our ANN should be stable, correct ! So we need to calculate the activation value of the output with these inputs. We should use our activation function with the sum of incoming signals in their weights.

As you see, this simple equation shows that activation value of an artificial neuron depends on activation values of input neurons and weights of input links.

We think that, this example above was the simplest artificial neuron and ANN example in C++ on the internet. It is good to understand how a simple neuron simulation works. Let’s sum all in this full example below,

Get started building powerful apps with C++Builder!

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Introduction to C++Learn C++

Learn Copy Constructors in C++ Classes

C++C++11C++14C++17Introduction to C++Learn C++Syntax

Learn How To Use Types Of Destructors In C++?

C++C++11C++14Learn C++Syntax

How To Convert u32string To A wstring In C++

C++C++11C++14C++17C++20Introduction to C++Learn C++

How To Learn The Move Constructors In Modern C++?