C++Builder How To Make AI Binary/Heaviside Step Functions In C++

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,199
Credits
4,009
How To Make AI Binary/Heaviside Step Functions In C++
By Yilmaz Yoru November 23, 2021

What is a Binary Step Function? Should we use Binary Step Function or Heaviside Step Function? Are Binary Step functions and Heaviside Step functions the same thing? What is a Unit Step Function? Briefly, all these terms are same, let’s explain these terms.

What is an activation function in C++ AI?​

An Activation Function ( phi() ) also called as transfer function, or threshold function that determines the activation value ( a = phi(sum) ) from a given value (sum) from the Net Input Function. A Net Input Function, here, is the sum is a sum of signals in their weights, and activation function is a new value of this sum with a given function or conditions. In other words, the activation function is a way to transfer the sum of all weighted signals to a new activation value of that signal. There are different activation functions, mostly Linear (Identity), bipolar and logistic (sigmoid) functions are used. The activation function and its types are explained well Для просмотра ссылки Войди или Зарегистрируйся.

Is it possible to create an AI activation function in C++?​

In C++ (in general in most Programming Languages) you can create your activation function. Note that sum is the result of Net Input Function which calculates the sum of all weighted signals. We will use some as a result of the input function. Here activation value of an artificial neuron (output value) can be written by the activation function as below,
1637652620632.png
By using this sum Net Input Function Value and phi() activation functions, let’s see some of activation functions in C++; Now Let’s see how we can use Binary Step Function as in this example formula,

What is a Binary Step or Heaviside Step Function?​

A Для просмотра ссылки Войди или Зарегистрируйся, or Heaviside step function, or the unit step function, is a Для просмотра ссылки Войди или Зарегистрируйся, named after Для просмотра ссылки Войди или Зарегистрируйся (1850–1925), the value of which is zeroДля просмотра ссылки Войди или Зарегистрируйсяfor negative arguments and one for positive arguments. That means it results 0 or 1 as a Boolean. Indicator function is described as below,

1637652714674.png
This function is an example to the general class of step functions, all of which can be represented as Для просмотра ссылки Войди или Зарегистрируйся of translations of this one.

Thus, Binary Step Function is a Boolean function that returns bool (1 or 0), it should be as below,
C++:
bool phi(float sum)
{
  return(sum>0) ;   // Binary Step Function , Heaviside Step Function, Unit Step Function,
}
This activation function returns 1 (true) if sum>0 otherwise returns 0 (false)

Is there a C++ example of an AI Binary Step or Heaviside function?​

Here is a example how to use a step function.
C++:
#include <iostream>
 
#define    NN 2   // number of neurons
 
class Tneuron    // neuron class
{
  public:
   bool a;       // activity of each neurons
   float w[NN+1]; // weight of links between each neurons
 
   Tneuron()
   {
 a=0;
 for(int i=0; i<=NN; i++) w[i]=-1;  // if weight is negative there is no link
   }
 
   // let's define an activation function (or threshold) for the output neuron
    bool phi(float sum)
    {
       return(sum>0) ;   // Binary Step Function , Heaviside Step Function, Unit Step Function,
    }
};
 
Tneuron ne[NN+1];   // neuron objects
 
void fire(int nn)
{
   float sum = 0;
 
   for ( int j=0; j<=NN; j++ )
   {
    if( ne[j].w[nn]>=0 ) sum += ne[j].a*ne[j].w[nn];
   }
 
   ne[nn].a = ne[nn].activation_function(sum);
}
 
int main()
{
 //let's define activity of two input neurons (a0, a1) and one output neuron (a2)
 
 ne[0].a = 0;
 ne[1].a = 1;
 ne[2].a = 0;
 
 //let's define weights of signals comes from two input neurons to output neuron (0 to 2 and 1 to 2)
 
 ne[0].w[2] = 0.3;
 ne[1].w[2] = 0.2;
 
 
 // Let's fire our artificial neuron activity, output will be
 fire(2);
 
 printf("%d\n", ne[2].a);
 getchar();
 return 0;
}
In addition to this Для просмотра ссылки Войди или Зарегистрируйся, other Heaviside step function types are; a Для просмотра ссылки Войди или Зарегистрируйся, Для просмотра ссылки Войди или Зарегистрируйся, Для просмотра ссылки Войди или Зарегистрируйся, and Для просмотра ссылки Войди или Зарегистрируйся of the Dirac delta function. More details can be found on Для просмотра ссылки Войди или Зарегистрируйся.