Artificial Intelligence TechC++Learn C++

AI Techs :: Class Based 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++ with Classes ? In this post we will explain with a very simple artificial neuron example using with Classes. 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 AI 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 depend on the number of its 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.

Class Based Artificial Neuron Model in C++

This is another simple neuron example with classes. This is a modern way to create a neuron in C++ than using structs or arrays. This example is also good for modern C++ applications. We have explained Classes very detailed in our web site. If you are new to Classes and Objects first please read Learn Classes and Objects in C++ and you will find a lot of Class related topics that teach different usage and methods in Classes.

Object Oriented Programming is a way to integrate with objects which can contain data in the form (attributes or properties of objects), and code blocks in the form of procedures (methodsfunctions of objects). Classes are defined in C++ using keyword class followed by the name of the class. Classes are the blueprint for the objects and they are user-defined data types that we can use in our program, and they work as an object constructor. Objects are an instantiation of a class, In another term. In C++ programming, most of the commands are associated with classes and objects, along with their attributes and methods. 

If you have a complex network, this call based artificial neuron model is more safe and functional to calculate activation of neurons. Structs and arrays are easy to allocate memory and easy to use on static neural networks but Classes are the best if you are strongly know their all features.

Let’s create our simple Tneuron class (T means it is a Type),

In this Tneuron class, we can create a constructor with its same name Tneuron() as below,

In this Tneuron class, we can also define a linear activation function as below,

If we sum up all, our simple neuron in a class form can be as below,

Now we have a neuron class and each neuron has activity value, weights if it has inputs its own Tneuron() constructor and activation_functin(). We can create many ne[] neuron objects by using this class as below;

An activation function can be written as here,

This image has an empty alt attribute; its file name is activation_function3.png

We need a function to fire a nn’th neuron as below,

This is a very simple class example for an artificial neuron. Classes has many features that you can use professionally. We can create our more functional and complex neuron models. To do this you need to know well about Classes, please read our previous posts about classes.

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.

About author

33+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux and some other operating systems. Dr. Yilmaz Yoru was born in 1974, Eskisehir-Turkey. He graduated from the department of Mechanical Engineering of Eskisehir Osmangazi University in 1997. One year later he started to work in the same university as an assistant. He received his MSc and PhD degrees from the same department of the same university. He has married and he is a father of a son. Some of his interests are Programming, Thermodynamics, Fluid Mechanics and Artificial Intelligence. He also likes the graphical 2D & 3D design and high-end innovations.
Related posts
C++C++11C++14C++17Introduction to C++Learn C++

Learn about Declaration of a Copy Constructor

C++Game DevelopmentLearn C++

Learn to Develop a Text Based Simple Adventure Game in C++ on Windows

C++C++11C++14C++17Learn C++

Learn what is Trivial Default Constructor in C++

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

Learn to use Deleted Implicitly-Declared Default Constructor