3.1 Class Library Name
3.2 Interface
3.3 Class Library Overview
3.4 Link To Class Library
3.5 Training and Recognition File Format3.5.1 Data File Formats3.6 Setting Up PolyApplet Output Files
3.5.2 Limits3.6.1 Position of a Digit in a String3.7 Setup Symmetry
3.6.2 Output File Format3.7.1 Setup Symmetry Parameters3.8 Neural Commands3.8.1 Binary and Polytomous Recognition Commands3.9 Test Input File Format
3.8.2 Classification and Distribution
3.8.3 1-Neuron-1-Class Classifications/Distributions
3.8.4 Training, Retraining and Recognition
3.8.5 Array Commands
3.8.6 Search Commands
3.10 Messages
3.11 Example Class
3.12 Common Errors
This chapter introduces the interface for the neural layer component of the Attrasoft PolyApplet. The class library in PolyApplet is PolyApplet63.
The neural layer class library is:
The class in this library will be:
PolyApplet63 implements the following interface:
//2. Parameter Section
void setRotationType(int x);
int getRotationType();
void setTranslationType(int x);
int getTranslationType();
void setScalingType(int x);
int getScalingType();
void setSensitivity(int x);
int getSensitivity();
void setBlurring(int x);
int getBlurring();
void setInternalThreshold(int x);
int getInternalThreshold();
void setSegmentSize(int x);
int getSegmentSize();
void setImageType(int x);
int getImageType();
//3. Files:
void setTrainFile( string aFile);
string getTrainFile( );
void setRecognitionFile( string aFile);
string getRecognitionFile( );
void setOutputFile( string aFile);
string getOutputFile( );
void setHelpFile( string aFile);
string getHelpFile( );
bool testInput(); //Test Input Files
bool openTrainFile ();
bool openRecognitionFile ();
bool openOutputFile ();
//4. Symmetry and Breaker
// Symmetry
bool setSymDimension (int symStart, int symEnd, int xDimension,
int yDimension);
void deleteSymDimension () ;
bool setSymmetry (int aSym);
void deleteSymmetry ();
int getSymmetry();
//final int SymxTranslation1D = 1;
//final int SymxScaling1D = 2;
//final int SymxyTranslation2D = 3;
//final int SymxyScaling2D = 4;
//final int SymzRotate2D = 5;
//final int SymzRotatexyScaling2D = 6;
int getSymmetryStart();
int getSymmetryEnd();
int getSymmetryXDimension();
int getSymmetryYDimension() ;
bool setLineBreaker(int line2, int line3, int line4, int line5 );
void deleteLineBreaker();
int getLineBreaker1();
int getLineBreaker2();
int getLineBreaker3();
int getLineBreaker4();
//5. Search
bool train ( char [] trainArray );
bool train () ;
bool retrain ( char [] reTrainArray );
bool retrain () ;
long match( char [] matchArray);
//6. classification
//6A. Binary Neural Commands
bool classification() ;
bool distribution () ;
bool classification1N1C() ;
bool distribution1N1C () ;
bool Recognition_classification() ;
bool Recognition_classification1N1C() ;
long Recognition_classification1N1C(char[] b) ;
bool Recognition_distribution () ;
bool Recognition_distribution1N1C () ;
long Recognition_distribution1N1C (char[] b) ;
bool Recognition_localMinima (int repeat) ;
//6B. Polytomous Neural Commands
bool polyClassification() ;
bool polyDistribution () ;
bool polyClassification1N1C() ;
bool polyDistribution1N1C () ;
bool polyRecognition_classification() ;
bool polyRecognition_classification1N1C() ;
long polyRecognition_classification1N1C(char[] b) ;
bool polyRecognition_distribution () ;
bool polyRecognition_distribution1N1C () ;
long polyRecognition_distribution1N1C (char[] b) ;
Setting up a neural net means to select a neural network size. For example,
select a neural network of 100 neurons. The first group of commands deals
with how to set up a neural net:
The neural net layer class library has several parameters. The next
group of commands deals with how to set up the parameter:
void setTranslationType(int x);
int getTranslationType();
…
The neural net will use several files. Please refer to Attrasoft
ABM
for
Windows for the files used. The next group of commands deals with how to
assign or open the neural files:
void setRecognitionFile( string aFile);
string getRecognitionFile( );
…
The next group of commands deals with Symmetries and Breakers; again,
please refer to the software ABM 2.7 for details.
The Attrasoft ImageFinder uses the following Array commands:
The binary neural net commands are:
bool Recognition_classification() ;
bool Recognition_classification1N1C() ;
long Recognition_classification1N1C(char[] b) ;
bool Recognition_distribution () ;
bool Recognition_distribution1N1C () ;
long Recognition_distribution1N1C (char[] b) ;
bool Recognition_localMinima (int repeat) ;
The multi-valued neural network commands are:
bool polyRecognition_classification() ;
bool polyRecognition_classification1N1C() ;
long polyRecognition_classification1N1C(char[] b) ;
bool polyRecognition_distribution () ;
bool polyRecognition_distribution1N1C () ;
long polyRecognition_distribution1N1C (char[] b) ;
To include the class library in the project:
To use the class library, add:
To declare an object, add:
Now PolyApplet63 object, x, is ready to use.
3.5 Training and Recognition File Format
The file commands are:
void setRecognitionFile( string aFile);
string getRecognitionFile( );
void setOutputFile( string aFile);
string getOutputFile( );
void setHelpFile( string aFile);
string getHelpFile( );
bool testInput(); //Test Input Files
You can train your neural net in two ways:
After training, you can recognize a pattern in two ways:
If you choose to train your neural net with a training file, or
recognize patterns in a recognition file, the above commands will let you
specify these files. Similarly, you can set the output file, which contains
the results after neural computation, and the help file, which will be
the help file in your neural software.
The training and the recognition files must follow the Attrasoft formats. An example of a training file is:
46
10000000000
01000
10100
10100
01000
00000
00000
00000
10000000000
01000
10100
10100
10100
01000
00000
00000
The 10 neurons, 10000000000, are called classification-neurons.
These classification neurons together represent a classification. The 35
neurons,
are called pattern-neurons. These pattern neurons together represent
a pattern.
An example of a recognition file is:
xxxxxxxxxxx
00100
01010
01010
01010
01010
00100
00000
To make a long story short, in the training file, you will:
In the recognition file, you will:
The two files must be prepared in the text file format. The
training file has three sections:
The recognition file has two sections:
Part 1 of the Training File: Comment Section
Example:
Note: the PolyApplet will ignore this section. This section
is for your remarks only.
Part 2 of the Training File: Number of Neurons
Part 3 of the Training File: Data Section
Part 1 of the Recognition File: Comment Section
Part 2 of the Recognition File: Data Section
(1) The unknown digits in a recognition file must be marked as 'x';
(2) The unknown digits in a recognition file must stay together;
(3) The unknown digits in a recognition file must all be in the same
positions.
The following test pattern is wrong because the x's are separated:
The following test pattern is wrong because y's are illegal characters:
The following test pattern is wrong because the x's are not in the
same positions:
If you want the PolyApplet to recognize:
you have to run it twice; the first time with the recognition
pattern:
and the second time with the pattern:
3.6
Setting Up PolyApplet Output Files
3.6.1 Position of a Digit in a String
Let a string be 101, then the position of the first digit is 0; the
position of the second digit is 1; and the position of the third digit
is 2, ...
The line-breaker commands are:
If no output format is given, the default will print one pattern
per line.
If your recognition pattern is long, or they are 2-dimensional, you
might want to change this default format. Inserting line breakers will
do just that. PolyApplet allows you to insert up to 4 line breakers.
To insert the line breakers, you must specify the positions of the line
breakers. Suppose you want the output to look like this:
then call setLineBreaker ( 3, 7, 12, 18 ). The position of the first
digit is 0; the position of the second digit is 1; and the position of
the third digit is 2. Note that after "111", the next position is 3, and
3 is the first parameter in setLineBreaker ( 3, 7, 12, 18 ), meaning a
new line starts after "111". The default values are all -1, meaning
no line breakers.
PolyApplet allows the output neurons to be printed on five lines.
However, if line 2 and line 3, (or line 3 and line 4) have an equal length,
all the rest of the lines will also have the same length. For example,
to change the output-vector to:
call setLineBreaker ( 4, 7, 10, 13 ).
The Symmetry commands are:
int getSymmetryStart();
int getSymmetryEnd();
int getSymmetryXDimension();
int getSymmetryYDimension() ;
Symmetry means that after you transform the pattern, both the original
pattern and the transformed pattern belong to the same class. The transformation
includes:
For example, a picture of a person in the middle of a page and the
same person near the edge of the paper represents the same person. Almost
all images have some sort of symmetry. Please study Symmetry in ABM
2.7.
PolyApplet supports one-dimensional and two-dimensional patterns.
One-dimensional patterns may have the following symmetries:
Two-dimensional patterns may have the following symmetries:
3.7.1
Setup Symmetry Parameters
Symmetries only apply to the pattern-neurons. In general, the classification-neurons do not have any symmetry.
To specify the symmetry, you have to specify:
Where:
Position: where does it start, and where does it end:
Dimension: 1-dimension or 2-dimension.
The function, public boolean setSymDimension (int symStart, int symEnd, int xDimension, int yDimension), specifies:
where symmetry starts
where symmetry ends
the x-dimension of the symmetry
the y-dimension of the symmetry
If you do not specify the symmetry, the default values are -1, meaning no symmetry. Please refer to the last section for the position of a pattern.
What:
will specify the symmetry as follows:
The Rotation symmetry automatically implies the Translation symmetry,
so does the Scaling symmetry.
Example The 4-Digit Shifter Problem (See ABM 2.7)
has 1-dimensional x-translation symmetry. The class-neurons take digits
from 0 to 2, and the pattern-neurons take digits from 3 to 10. The x-dimension
is 8 and there is no y-dimension. The position is shown as follows:
Call setSymDimension (3, 10, 8, -1), meaning
Symmetry starts at 3
Symmetry ends at 10
x-dimension is 8
y-dimension is -1
and call setSymmetry (1), meaning: x-translation symmetry.
Note the relation:
x-dimension = Symmetry end - Symmetry start + 1 , or
8 = 10 - 3 + 1.
Example The '5 by 7' Character Recognition
Problem (See ABM 2.7) has x- and y-translation symmetry. Let a pattern
be:
The class-neurons take digits from 0 to 10 and the pattern-neurons
take digits from 11 to 45.
The x-dimension is 5 and the y-dimension is 7. Call setSymDimension
(11, 45, 5, 7), meaning
and call setSymmetry (3), meaning 2-D translation symmetry.
Note the relation:
x-dimension * y-dimension = Symmetry end - Symmetry start + 1,
or 5 * 7 = 45 - 11 + 1.
When you specify the Translation symmetry, the numbers must satisfy the following conditions:
1-D: x-dimension = Symmetry end - Symmetry start + 1;
2-D: x-dimension * y-dimension
= Symmetry end - Symmetry start + 1.
When there are errors in the specification, an error message will be printed on a Rich Text Box.
3.8 Neural Commands
3.8.1 Binary and Polytomous Recognition Commands
The recognitions commands are divided into four categories:
The training commands are the same for all.
3.8.2 Classification and Distribution
All neural computation starts with training. Training means the PolyApplet learns the patterns from the training file.
Recognition comes after training. Recognition means the PolyApplet classifies the patterns in the recognition files.
There are two basic commands:
Classification -------- the Hopfield Model;
Distribution --------- the Boltzmann Machine.
The output of the computation goes to the output file.
The command, "Distribution" presents you with a distribution, which is a list of all possible classifications and how valuable the PolyApplet thinks each prediction is via a confidence number. This number is similar to the score in an Internet Search Engine: the higher that number, the more confidence the PolyApplet has in that distribution.
The command, "Classification" presents you with a classification, and a confidence number. This number is similar to the score in an Internet Search Engine: the higher that number, the more confidence the PolyApplet has in that classification.
Each of the above commands has two phases:
In the training phase, the training file is imposed
upon a neural network to force the network to remember the pattern of the
training data. A neural network can remember the training pattern by adjusting
its internal synaptic connections.
In the recognition phase, a part of the input data in the recognition file is not known. The neural network, based on its internal synaptic connections, will determine the unknown part.
A typical problem for a neural network to solve is the classification problem. The data is a set of doublets: (pattern, class). In the training phase, the network is taught which pattern belongs to which class. In the recognition phase, only the patterns are given to the network, and the network decides the classification of the patterns. Alternatively, when a part of a pattern and a classification are given, or just a part of a pattern is given, the network is asked to complete the pattern.
Click commands "Classification" or "Distribution", and you can expect
three possibilities for each recognition pattern:
Incorrect Classification: this is usually the case when: the Boltzmann Machine assigns a predominate probability to more than one configuration; or the relative probability is "small". It is hard to define "small" here because it depends on the problem, but for a given problem, an experienced user will know what is "small".
No Classification: this is usually the case when the Boltzmann Machine can find little correlation in the test pattern, based on the current training. In such a case, "No classification" is printed in the output data file.
3.8.3
1-Neuron-1-Class Classifications/Distributions
There is no restriction on how to represent a classification using classification
neurons. The most common method of representing a class is to use one neuron
for each class. Among class neurons, one of the neurons is '1'; all
others are '0':
Here each "1" represents a class classification. Of course, you
can choose any way to represent a class.
We will call the above representation "1 neuron for 1 class" or 1N1C
representation. If you do choose 1N1C representations, we have two more
commands:
The reason to offer these 1N1C commands is that they are
50% to 100% faster than the standard commands, especially for large
problems.
If your problem is reasonably large, meaning:
1N1C representation is the preferred mode for character recognition and image recognition.
3.8.4 Training, Retraining and Recognition
The command, public bool classification(), consists of:
The command, public bool distribution (), consists of:
The same is true for:
Command "Retrain" is used to retrain the network. Retraining cannot
take place until training has been done first. You can have as many retraining
as you wish. Every retraining looks for data from the training file. Make
sure you offer fresh data to the PolyApplet for each retraining.
The Array Commands are:
You can run PolyApplet without using any files, instead using
character arrays.
Before using the Arrays, use:
or
Example. Use setN (46) to assign the number of neurons
in this example.
An example of a Training Array is:
01000 00000 0
An example of a Recognition Array is:
xxxxx xxxxx x
Search Commands compare a new pattern with a set of existing patterns.
The neural net is trained with the new pattern, then it will loop through
the existing pattern. The commands are:
For example, an 1:N match (between a pattern, x[] , and N patterns
y[][]) algorithm will be:
The Test-Input-File command is:
If you are not sure of the correctness of the training and recognition
files, this command will tell you.
The Message commands are is stored in:
The Class Library, Attrasoft.PolyApplet63.Example provides you with several examples in ABM 2.7 and in PolyNet 4.0. To get this object, declare a PolyApplet x:
public Attrasoft.PolyApplet63.PolyApplet63 poly
= new Attrasoft. PolyApplet63.PolyApplet63 ();
Then poly.example will produce the example object. The public methods are:
public class Example
{
public int
symmtryStart = -1,
symmtryEnd = -1,
symmtrXDim = -1,
symmtryYDim = -1,
symmetryIndex = 0;
public String trainFileName = "example1a.txt";
public String recognitionFileName ="example1b.txt";
public String outputFileName = "example1c.txt";
public void ocr5x7 ()
public void ocr8x8 ()
public void ocr19x19 ()
public void ocr32x32 ()
public void shifter1 ()
public void shifter2 ()
public void shifter3 ()
public void shifter4 ()
public void scaling2D ()
public void rotation2D ()
public void rotationScaling2D ()
public void nursery ()
public void cancer ()
public void math1 ()
public void math2 ()
Please refer to User's Guide of ABM 2.7 and PolyNet 4.0 for these examples.
Common Errors are: