5.   Building a Simple PolyNet 4.0
5.1   Creating a Dialog
5.2   The Symmetry Dialog
5.2.1   The Symmetry Dialog
5.2.2   Display the Existing Symmetry
5.2.3   Set New Symmetry
5.3   The Line Breaker Dialog
5.4   PolyNet Commands
5.5   Test Run

5.   Building a Simple PolyNet 4.0

In this chapter, we will create a simple version of PolyNet 4.0. Most of the work was done in the last chapter. We will simply copy it as follows:

1. Copy C:\…\chap4 to produce directory, C:\…\copy of chap4 .

2. Rename C:\…\copy of chap4\ to C:\…\chap5\ .

3. Rename File:
chap4.sln to chap5.sln.
chap4.suo to chap5.suo.

4. Start the project by clicking to chap5.sln.

5. Rename the project to “chap5”.

6. Right click the Project, go to Property Window and set:
 Assembly name: chap5
 Default Name Space: chap5.

7. Go to Form1.cs and change the name space to chap5.

Now everything in chapter 4 is in chapter 5. We need to add two more buttons in this chapter: Symmetry and Line-breakers. This example is also in c:\polyapplet63\chap5\.

5.1   Creating a Dialog

To create a "Symmetry" dialog:

1. Right click the Project Name “chap5” and select  "Project/Add New Item/Windows Form".
2. Set Form2.Text = “Symmetry”.
3. Repeat the above process to create a "Line Breaker" Form, Form3. Now you will have two dialog boxes.
Now we will add two Commands to form1:

1. Add 2 buttons:

Control      Object          Description
--------------------------------------------------------
Button       Button          open Symmetry Dialog
Button       Button10       open Line Breaker Dialog
2. Go to the Property Window and set:
 Object.Property           Value
 ---------------------------------------------------------
Button9.Text               "Symmetry"
Button10.Text              "Breaker"
3. Add the following code in boldface to Form2:

public class Form2 : System.Windows.Forms.Form

 {
  Form1 a;

  private System.ComponentModel.Container components = null;

  public Form2(Form1 a1)
  {
   a = a1;
   InitializeComponent();
  }


Repeat the above for the Breaker form.

4. Open Symmetry and Break Dialog:

 Double click the Symmetry button and the Breaker button and enter the code:

private void button9_Click(object sender, System.EventArgs e)

 {
 Form2 symmetryForm = new Form2 (this );
 symmetryForm.ShowDialog ();
 }
private void button10_Click(object sender, System.EventArgs e)
 {
 Form3 breakerForm = new Form3 (this );
 breakerForm.ShowDialog ();
}
Run the program, and Figure 5.1 will appear.
 

Figure 5.1  A simple PolyNet 4.0.
 

Click the Symmetry button, Figure 5.2 will appear.
 

Figure 5.2 The Symmetry Dialog.

5.2   The Symmetry Dialog

The Symmetry Dialog will specify the symmetry of the PolyApplet. This dialog will fulfill two tasks:

The Symmetry Dialog must specify:
Where? What?  OK/Cancel
5.2.1   The Symmetry Dialog

1. Add 4 Labels to the Symmetry Dialog; go to the Property Window and set:

 Object.Property           Value
 -------------------------------------------------------
Label1.Text                   "Symmetry Starts:"
Label2.Text                   "Symmetry Ends:"
Label3.Text                   "X dimension:"
Label4.Text                   "Y dimension:"


2. Add 4 TextBoxes:

textBox1, textBox2, textBox3, textBox4
3. Add a GroupBox; go to the Property Window and set:
 Object.Property           Value
 -------------------------------------------------------
 groupBox1.Text          “Symmetry”
Add the following RadioButtons to groupBox1; go to the Property Window and set:
 Object.Property           Value
 -------------------------------------------------------
radioButton1.Text          "1D translation"
radioButton2.Text          "1D scaling"
radioButton3.Text          "2D translation"
radioButton4.Text          "2D scaling"
radioButton5.Text          "2D rotation"
radioButton6.Text          "2D scaling, rotation"
4. Add 2 buttons and go to the Property Window and set:
Object.Property              Value
 -------------------------------------------------------
button1.Text                  "OK"
button2.Text                  "Cancel"
Run the program, click the Symmetry button, and Figure 5.3 will appear.
 

Figure 5.3 The Symmetry Dialog.

5.2.2   Display the Existing Symmetry

The Symmetry Dialog is responsible for:

To display the existing Symmetry, the dialog constructor must obtain the information of the current Symmetry from form1.x. This requires form1.x to be a public object. Go to Form1 and make sure form1.x is public:
 public PolyApplet63 x;
Add the following by double clicking form2:

private void Form2_Load(object sender, System.EventArgs e)

 {
 textBox1.Text = ""+ a.x.getSymmetryStart  () ;
 textBox2.Text = ""+ a.x.getSymmetryEnd   () ;
 textBox3.Text = ""+ a.x.getSymmetryXDimension   () ;
 textBox4.Text = ""+ a.x.getSymmetryYDimension   () ;

 int sym = a.x.getSymmetry ();

 if ( sym == 0 )
  radioButton7.Checked  = true;
 else if ( sym == 1 )
  radioButton1.Checked  = true;
 else if ( sym == 2 )
  radioButton2.Checked  = true;
 else if ( sym == 3 )
  radioButton3.Checked  = true;
 else if ( sym == 4 )
  radioButton4.Checked  = true;
 else if ( sym == 5 )
  radioButton5.Checked  = true;
 else if ( sym == 6 )
  radioButton6.Checked  = true;
 else
  radioButton7.Checked  = true;
 }

This code displays the current Symmetry setting.

5.2.3   Set New Symmetry

To pass the new Symmetry setting back to the main project, double click the OK button and enter the code:

private void button1_Click(object sender, System.EventArgs e)

 {
 try
 {
a.x.setSymDimension (
 int.Parse (textBox1.Text),
 int.Parse (textBox2.Text ),
 int.Parse (textBox3.Text ),
 int.Parse (textBox4.Text )) ;
int sym = 0;
if ( radioButton1.Checked  )
   sym =1;
else if ( radioButton2.Checked  )
  sym =2;
else if ( radioButton3.Checked  )
  sym =3;
else if ( radioButton4.Checked  )
  sym =4;
else if ( radioButton5.Checked  )
  sym =5;
else if ( radioButton6.Checked  )
 sym =6;
a.x.setSymmetry (sym);
}
 catch
 {
MessageBox.Show ("Please enter valid integers", "Entry Error");
 }
 this.Close();
 }
Now the Symmetry Dialog is operational.

5.3   The Line Breaker Dialog

The Line-Breaker Dialog is similar to the Symmetry Dialog. The procedure is:

1. Add 4 Labels, 4 TextBoxes, and 2 buttons to the Line Breaker Dialog. Set:

Object.Property           Value
 -------------------------------------------------------
Label1.Text               "Line 2 starts:"
Label2.Text               "Line 3 starts:"
Label3.Text               "Line 4 starts:"
Label4.Text               "Line 5 starts:"
button1.Text               "OK"
button2.Text               "Cancel"
Run the program, click the Breaker button, and Figure 5.4 will appear.

Figure 5.4. The Line-Breaker Dialog.

2. To receive and display the current Line-Breaker setting, add the following code to the Line-Breaker Dialog:

private void Form3_Load(object sender, System.EventArgs e)

 {
 textBox1.Text = ""+ a.x.getLineBreaker1  () ;
 textBox2.Text = ""+ a.x.getLineBreaker2  () ;
 textBox3.Text = ""+ a.x.getLineBreaker3  () ;
 textBox4.Text = ""+ a.x.getLineBreaker4  () ;
 }
3. To set a new Line-Breaker setting, double click OK button in Form2 and enter the following code:

private void button1_Click(object sender, System.EventArgs e)

 {
 try
 {
 int i1 = int.Parse (textBox1.Text );
 int i2 = int.Parse (textBox2.Text );
 int i3 = int.Parse (textBox3.Text );
 int i4 = int.Parse (textBox4.Text );

 a.x.setLineBreaker (i1, i2, i3, i4);
 }
 catch
 {
 MessageBox.Show ("Please enter valid integers", "Entry Error");
 }
 this.Close();
 }

Now the Line-Breaker Dialog is operational.

5.4   PolyNet Commands

Double click the Classification button in form1 and change:

x.classification
to
 x.polyClassification
Double click the Distribution button and change:
x.Distribution ()
to
x.polyDistribution ()
Now you have built a simple PolyNet 4.0.
 

5.5   Test Run

To test:

1. Run the program.

2. Training file: the default file is “.\example1a.txt", where “.\” is chap5.exe directory (“C:\polyapplet63\chap5\bin\Debug\”). Select “shifter1a.txt” as the training file. Click the "Open" button to make sure ".\shifter1a.txt" is the training file for the shifter problem, which will look like this:

*
 shifter, Training Data File
 *
 33

006 600600000000066
 660060000000006
700 700770700007700
 007707000077007

3. Recognition file: the default recognition file is ".\example1b.txt”. Select “shifter1b.txt” as the recognition file. Click the "Open" button to make sure ".\shifter1b.txt" is the recognition file for the shifter problem, which will look like this:
*
 Shifter: Recognition Data File ( 1 neuron 1 class )
 *

xxx 070700007077070
 707000070770700
xxx 022002000020000
 022002000020000

4. Output file: the default file is ".\example1c.doc”.

5. Symmetry setting: Click the Symmetry button and set:

Symmetry starts:         3
Symmetry ends:         32
x-dimension:              30
y-dimension:               -1
1D translation              check
6. Line-Breaker setting: Click the Breaker button and set:
Line 2 starts:               3
Line 3 starts:              18
Line 4 starts:              -1
Line 5 starts:              -1
7. Run: click the "Classification" button and “Distribution” button to complete the neural computation. The results for “Distribution” button is:

xxx
                     070700007077070
                     707000070770700
-----------------------
001 41
040 10
009 70
900 26
050 20
400 144
002 40
003 11
600 64
800 114
500 35
004 60
-----------------------
400
                 070700007077070
                 707000070770700     144     1
 

xxx
                 022002000020000
                 022002000020000
-----------------------
010 106
030 500
001 34
040 88
009 39
050 144
002 160
070 58
090 23
020 640
004 44
060 102
-----------------------
020
             022002000020000
             022002000020000     640     1
 

Return