لتحميل الشيفرة المصدرية للبرنامج
public void PerceptronAlg() {
int testPerformance;
string text;
testPerformance=NetPerformance();
good[tries]=testPerformance;
while(tries < SESSION)
{
if(testPerformance != total)
{
TeachNet();
tries++;
testPerformance=NetPerformance();
good[tries]=testPerformance;
}
else
break;
}
x = new double[tries+1];
y = new double[tries+1];
int i;
for ( i=0; i
{
x[i] = Convert.ToDouble(i);
y[i] = Convert.ToDouble( good[i] );
}
zedGraphControl1.GraphPane.AddCurve( "Sine Wave", x, y, Color.Olive, SymbolType.Circle);
zedGraphControl1.GraphPane.AxisChange();
zedGraphControl1.*******();
if(NetPerformance()!= total)
{
text="network failedn The number of correct answers is: "+ Convert.ToString(NetPerformance());
MessageBox.Show(text);
}
else
{
text="network succeedn The number of correct answers is: "+ Convert.ToString(NetPerformance());
MessageBox.Show(text);
}
}
public void TeachNet() {
Vector pattern;
int correctAnswer;
int netOutput;
for(int i=0;i
{
pattern = patterns[i];
correctAnswer = target[i];
netOutput = ThresholdRule(pattern);
if( netOutput!= correctAnswer)
{
UpdateWeight(pattern,netOutput,correctAnswer);
}
}
}
public int ThresholdRule(Vector inputPat) {
switch(s)
{
case "<":
if(WeightedSum(inputPat) < S )
return cat1;
else
return cat2;
break;
case ">":
if(WeightedSum(inputPat) > S )
return cat1;
else
return cat2;
break;
case "<=":
if(WeightedSum(inputPat) <= S )
return cat1;
else
return cat2;
break;
case ">=":
if(WeightedSum(inputPat) >= S )
return cat1;
else
return cat2;
break;
default:
return 0;
break;
}
}
publicvoid UpdateWeight(Vector inputPat, int output, int desiredOutput) {
w.x1 = w.x1 + C * (desiredOutput - output) * inputPat.x1;
w.x2 = w.x2 + C * (desiredOutput - output) * inputPat.x2;
bais = bais + C * (desiredOutput - output);
}
publicdouble WeightedSum(Vector inputs) {
return (inputs.x1 * w.x1) + (inputs.x2 * w.x2) + bais;
}
publicint NetPerformance() {
Vector pattern;
int counter=0;
for(int i=0;i
{
pattern=patterns[i];
if(ThresholdRule(pattern)==target[i])
counter++;
}
return counter;
}
publicvoid TestNet() {
int [] dis=newint [total1];
int netPass=0;
Vector pattern;
int correctAnswer;
int netOutput;
for(int i = 0;i
{
pattern = testingPattern[i];
correctAnswer = testingTarget[i];
netOutput = ThresholdRule(pattern);
dis[i]=netOutput;
if( netOutput== correctAnswer)
{
netPass++;
}
}
if(netPass == total1)
label6.Text+="Network passed the testing process successfullyn Number of correct answers: "+Convert.ToString(netPass)+"t";
else
label6.Text+="Network didn't pass the testing process successfullyn Number of correct answers: "+Convert.ToString(netPass)+"t";
}