Artificial Intelligence TechC++Learn C++

AI Techs :: Structure Based Simple Artificial Neuron Model in C++

Do you want to develop your of artificial intelligence application from the scratch ? Want to learn how you can develop a simple artificial neuron model in C++? In this post we will explain with a very simple artificial neuron example. We have released A Simple Artificial Neuron Model in C++ and Very Simple Artificial Neural Network (ANN) Example in C++ and we also released Array Based Simple Artificial Neuron Model in C++ before. We highly recommend reading Introduction to AI Technologies and them if you are new to AI technology.

A Simple ANN Model

We have presented this Simple AI neuron before, let’s remember. A Minimum Artificial Neuron has an activation value (a), an activation function ( phi() ) and weighted (w) input net links. So it has one activation value, one activation function and one or more weights depends on number of it’s input nets.

This is a very simple artificial neural network in AI technology . Now let’s go with this example and improve our neuron models and lets create an artificial neuron model by using arrays.

Structure Based Artificial Neuron Model in C++

This is another simple neuron example with structures. In C & C++ programming; a Data Structure (struct) is a data block in memory and group of data elements grouped together with a name, and these data elements are variables (integers, floats, strings …) called as members, all can be defined to a new variable under a single name. They can have different types and different lengths. Data structures can be declared by using struct statement, using the following syntax;

Structs are primarily used in C programming language, you can use and store your data in C++ too. Mostly in C++ Classes are used to store data and function instead of structures. The main difference between a struct and a class is classes can obtain both data and functions while structs has data only, functions can be used externally. One of the benefit of structs are they have fixed size.

A Minimum Artificial Neuron has an activation value (a), an activation function ( phi() ) and weighted (w) input net links. So we can use structs to define a simple neuron model in C++ as below,

This is a good example if all neurons are linked each other, or there are few number of neurons. This example is also very good to calculate in IoT machines which codes can be compiled in C only, Here NN shows number of neurons and number of weights are depends on number of net links, the right way here could be using a pointer for the array, we will use this simple model here. Now we can create our n[] artificial neuron structure for the NN number neurons as here,

We can define activity of two input neurons (a0, a1) and one output neuron (a2) as below,

Note that n[2] is our output neuron here and we will calculate it’s new activation value while it’s given 0 here.

In our example above, two input neurons are connected to output neuron. Thus we have 2 links that means we have weights. We can define weights of signals comes from two input neurons to output neuron (0 to 2 and 1 to 2) as in here,

Now we need a activation function, let’s define a simple activation function phi() (transfer function or threshold) for the output neuron as below,

We can fire our artificial neuron by the activation function to calculate it’s activity . Let’s fire n[2] calculate activation of output neuron as below,

Let’s combine them in a full C++ example as in below;

Last Notes,

This is a very simple structure based artificial neuron example to give you idea how you can develop your own structure based neuron model in C++. If you have a lot of neurons and each neuron has links, links and weights should be stored outside of this structure. You can use pointers to point net link arrays for each neuron structure too. This example very good to understand a simple Artificial Neuron in C++ and it is easy to use on IoTs with C or C++. It can be recommended for the neural networks which has few neurons.

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++?

Worth reading...
AI Techs :: Structure Based Simple Artificial Neuron Model in C++