AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

How can I implement IActivationFunction?

The forum is to discuss topics from different artificial intelligence areas, like neural networks, genetic algorithms, machine learning, etc.

How can I implement IActivationFunction?

Postby edurazee » Wed Dec 14, 2016 10:56 pm

Suppose, Image

Network structure: 2 input neurons: x and 1 (bias), one hidden layer of m neurons, one output neuron.

Activation function of hidden neurons = custom function

Code: Select all
public double Function(double h)
        {
            double result = 0;

            result = (Math.Exp(h) - Math.Exp(-h)) / (Math.Exp(h) + Math.Exp(-h));

            return result;
        }


How can we achieve that?

Activation function of output neuron = linear.
Attachments
Untitled.png
Untitled.png (27.29 KiB) Viewed 141 times
edurazee
 
Posts: 9
Joined: Sat Dec 03, 2016 10:06 am

Re: How can I implement IActivationFunction?

Postby andrew.kirillov » Thu Dec 15, 2016 8:03 am

Have a look at the code of BipolarSigmoidFunction. It will give an idea how to implement IActivationFunction interface.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3153
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: How can I implement IActivationFunction?

Postby edurazee » Thu Dec 15, 2016 12:55 pm

I need to create a Perceptron with 2 input neurons: x and 1 (bias), one hidden layer of m neurons, one output neuron.

Activation function of hidden neurons = custom function

Activation function of output neurons = Linear.

I have written my custom function. But, how can I make sure that the activation function of the output neurons is Linear?



My Custom Function Code.

Code: Select all
public class CustomActivationFunction : IActivationFunction
    {
        public CustomActivationFunction()
       {

       }

        public double Derivative(double h)
        {
            return (4* Math.Exp(2*h))/Math.Pow(Math.Exp(2 * h)+1, 2);
        }

        public double Derivative2(double h)
        {
            double up = 8 * Math.Exp(2 * h) * (Math.Exp(2 * h) -1);
            double down = Math.Pow(Math.Exp(2 * h) + 1, 3);

            return up / down;
        }

        public double Function(double h)
        {
            double result = 0;

            result = (Math.Exp(h) - Math.Exp(-h)) / (Math.Exp(h) + Math.Exp(-h));

            return result;
        }
    }
edurazee
 
Posts: 9
Joined: Sat Dec 03, 2016 10:06 am

Re: How can I implement IActivationFunction?

Postby andrew.kirillov » Thu Dec 15, 2016 2:38 pm

edurazee wrote:But, how can I make sure that the activation function of the output neurons is Linear?

Create another custom function, which is linear. The set it to the neuron you need.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3153
Joined: Fri Jan 23, 2009 9:12 am
Location: UK




Return to Artificial Intelligence