a basic single layer learning perceptron
As the title says I'm trying to program the forementioned. The Perceptron runs flawlessly, its the learning part that I'm having trouble with
Here is the code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include <iostream>
#include <math.h>
using namespace std;
struct perceptron
{
public:
int Input[16]; // Up to 16 inputs
int Bias; //bias
double Weight[16];
double Threshold;
bool fireing;
private:
int Input1_pr[16];
int Bias_pr;
double Weight_pr;
int Threshold_pr;
bool fireing_pr;
};
int main(int argc, char *argv[])
{
double total;
double subOutput;
perceptron prpMain;
prpMain.Bias = 3;
prpMain.Threshold = 0.6;
prpMain.Weight[1] = 0.2;
prpMain.Weight[2] = 0.3;
for (int i = 1; i <=2; i++)
{
cout << "What is the value of input ";
cout << i;
cout << ": ";
cin >> prpMain.Input[i];
cout << "\n";
total = total + (prpMain.Input[i] * prpMain.Weight[i]);
}
do
{
subOutput = 1/(1+exp(-(total * prpMain.Threshold)));
if (subOutput >= prpMain.Threshold)
{
prpMain.fireing = true;
cout << "It fired ";
cout << "\n ";
cout << subOutput;
} else {
prpMain.fireing = false;
cout << "It didnt fire";
for ( int j = 1; j <=2; j++)
{
prpMain.Weight[j] = prpMain.Input[j]*(prpMain.Threshold - subOutput);
}
total = 0.0;
for (int k = 1; k <= 2; k++)
{
total = total + (prpMain.Input[k] * prpMain.Weight[k]);
}
}
}while(prpMain.fireing = false);
system("PAUSE");
return EXIT_SUCCESS;
}
|
once the bool returns false it quits, even though I have a do while, with the expression being the bool = false.
Anyone know why this isnt working? or how I can check to see if it is indeed learning?
It's probably just a simple mistake.
Last edited on
Should be while(prpMain.fireing == false)
wow....I dont think I've ever failed so hard XD *facepalms*
Thanks Mythios :P
Topic archived. No new replies allowed.