Simple Perceptron with binary classifier using C#
The following code is a simple three input perceptron neural network with a binary classifier using c#.This neural net was the most primitive invented by Rosenblatt in 1959.
// A simple three input Perceptron Model using C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class perceptrontest1
{
static void elements()
{
//intialization of inputs and weights for nueral net//
decimal x1, x2, x3, w1, w2, w3;
decimal isum,thresh;
// bias input to neural net//
int bias=1;
// Provide userdefined inputs and weights//
Console.WriteLine("enter the inputs to be feeded in perceptron");
x1 = Convert.ToDecimal(Console.ReadLine());
x2 = Convert.ToDecimal(Console.ReadLine());
x3 = Convert.ToDecimal(Console.ReadLine());
Console.WriteLine("enter the value of the weights");
w1 = Convert.ToDecimal(Console.ReadLine());
w2 = Convert.ToDecimal(Console.ReadLine());
w3 = Convert.ToDecimal(Console.ReadLine());
// calculation of sum//
Console.WriteLine("calculating");
isum = (x1 * w1 + x2 * w2 + x3 * w3)+bias;
Console.WriteLine("The summed output is:{0} ",isum);
Console.WriteLine("enter the desired threshold value");
thresh = Convert.ToDecimal(Console.ReadLine());
// Binary classifier//
if (isum > thresh)
{
int y = 0;
Console.WriteLine("your classification is:{0}",y);
}
else if (isum < thresh)
{
int y = 1;
Console.WriteLine("your classification is:{0}",y);
}
}
static void Main(string[] args)
{
elements();
}
}
}