8. Predictor Translation Layer8.1 What is the Attrasoft Predictor ?
8.2 Abm2 Class Library
8.3 Link to Abm2 Class Library
8.4 File Properties and Commands
8.5 Encoding and Decoding Methods
8.6 Parameters
8.7 Chapter Project 1: File IO
8.8 Chapter Project 2: Neural Computing
8.9 Chapter Project 3: Encoding and Decoding
8.10 Chapter Project 4: Run
8. Predictor Translation LayerChapters 3 � 7 introduce Attrasoft.PolyApplet63.PolyApplet63.
Chapters 8 � 11 will introduce another component, abm2. If you do not want know the internal structure, please skip chapters 8 - 11.The neural network attempts to simulate the human brain. The human brain has front-end subsystems and can only handle preprocessed information. The front-end subsystems for humans are eyes, ears, ... The same is also true for neural networks.
There are two types of data used by neural network systems: user data (or application data), and neural data. Neural networks use neural data. User data depends on the application. Neural nets speak neural language; users speak user language.
The information processed by a neural network has to be prepared by a front-end subsystem. This is called Data Encoding. A neural network usually cannot handle the user-application data directly. Similarly, after neural computation, the result usually does not make sense to humans directly; the front-end system is responsible for converting the neural output data back into user-application data. This is called Data Decoding.
Attrasoft has two libraries for the Encoding and Decoding:
The TransApplet library is for image recognition and is used in the software, ImageFinder.
- TransApplet
- Abm2
The Abm2 library is used for processing data and is used in software, DecisionMaker and Predictor.8.1 What is the Attrasoft Predictor ?
Attrasoft Predictor is software that predicts a sequence. Making decisions based on your projection of the future events is a way of life. Attrasoft Predictor is a fast terabyte data processing tool for your database. It uses a sequence of numbers to predict the next row of numbers in line. It uses historical data to predict future possibilities. It does not matter what you want to predict.
90% of the work in using the Predictor is preparing your database containing your historical data. (Many corporations already have their database in place, which contains years of historical data. It is often overwhelming because of the sheer volume to mine the data for the purpose of strategic thinking.) The remaining 10% of the work is to operate the Predictor (a few clicks). The Predictor is especially good if you have a terabyte or gigabyte database because of its accuracy and speed.
Once your data is prepared correctly, the Predictor is able to provide you with rated predictions on any subject or any problem. The Attrasoft Predictor can:
8.2 Abm2 Class Library
- Predict the Stock Market
- Predict earnings and revenue of a company
- Predict short term and long term interest rates
- Predict commodity (gold, oil, corn,...) prices
- Predict regional/worldwide price fluctuations for a particular merchandise item
- Predict various indicators/indexes of the economy for strategic thinking and policy issues
- Predict Dynamic Systems, Markov Chains
- Predict system failure probabilities
- Predict other complex systems
- �
The Abm2 class library is an interface between the PolyApplet63 introduced in the last 5 chapters and the data used by the Predictor software. Abm2 class library is also responsible for the DecisionMaker, which is another Attrasoft software.
There are two image-matching algorithms in the PolyApplet: Abm and PolyNet. The Abm2 class library will translate data for both algorithms. The Abm2 class library will play four roles:
Data Source Data Consumer Description
Predictor Data Abm Chap 8
Predictor Data PolyNet Chap 9
DecisionMaker Data Abm Chap 10
DecisionMaker Data PolyNet Chap 11
The interface for Abm2 is:interface I_abm2
{bool openAbmTrainFile( );
bool openAbmRetrainFile( );
bool openAbmRecognitionFile( );bool openOutputFile( );
bool openPredictorTrainFile( );
bool openDecisionMakerTrainFile( );
bool openDecisionMakerRecoFile( );//*******************************************
//*******************************************
//Encoder
bool decisionMakerEncodeBinaryLinearPlus ();
bool decisionMakerEncodeBinaryLinearMinus ();
bool decisionMakerEncodeBinaryLinearZero ();bool decisionMakerEncodePolyLinear ();
//*******************************************
bool predictorEncodeBinaryLinearPlus ();
bool predictorEncodeBinaryLinearMinus ();
bool predictorEncodeBinaryLinearZero ();bool predictorEncodePolyLinear ();
//*******************************************
bool predictorEncodeBinaryExpPlus ();
bool predictorEncodeBinaryExpMinus ();
bool predictorEncodeBinaryExpZero ();
//*******************************************
//*******************************************
//Decoder
bool decisionMakerDecodeBinaryLinearPlusReal ();
bool decisionMakerDecodeBinaryLinearPlusInt ();
bool decisionMakerDecodeBinaryLinearMinusReal ();
bool decisionMakerDecodeBinaryLinearMinusInt ();
bool decisionMakerDecodeBinaryLinearZeroReal ();
bool decisionMakerDecodeBinaryLinearZeroInt ();bool decisionMakerDecodePolyLinearReal ();
bool decisionMakerDecodePolyLinearInt ();
//*******************************************
bool predictorDecodeBinaryLinearPlusReal ();
bool predictorDecodeBinaryLinearPlusInt ();
bool predictorDecodeBinaryLinearMinusReal ();
bool predictorDecodeBinaryLinearMinusInt ();
bool predictorDecodeBinaryLinearZeroInt ();
bool predictorDecodeBinaryLinearZeroReal ();bool predictorDecodePolyLinearReal ();
bool predictorDecodePolyLinearInt ();
//*******************************************
bool predictorDecodeBinaryExpPlus ();
bool predictorDecodeBinaryExpMinus ();
bool predictorDecodeBinaryExpZero ();
}
The Abm2 also has the following properties:public string PredictorTrainName ;8.3 Link to Abm2 Class Library
public string DecisionMakerTrainName ;
public string DecisionMakerRecoName ;public string AbmTrainName ;
public string AbmRetrainName ;
public string AbmRecognitionName ;
public string AbmOutputName ;public string OutputName;
public int Precision ;
public int Trend;
public double Emptyfield;To include the class library in the project,
To use the class library, add:
- In the Solution Explorer, right click References and select Add Reference;
- Browse to find �abm2.dll� in c:\polyaplet63\;
- Highlight it and click the �OK� button.
using Attrasoft.PolyApplet63.abm2;To declare an object, add:public Attrasoft.PolyApplet63.abm2.abm2Main y;To create the object, add the following in the constructor:public Form1()Now Abm2 object, y, is ready to use.
{//}
// Required for Windows Form Designer support
//
InitializeComponent();
x = new PolyApplet63 (richTextBox1 );
y = new abm2Main (richTextBox1 );8.4 File Properties and Commands
A neural network usually cannot handle the user-application data directly. Similarly, after neural computation, the result usually does not make sense to humans directly; the front-end system is responsible for converting application data to neural data (Encoding) and the neural output data back into user-application data (Decoding).
Files are used at two different levels:
The Encoding part uses the following files:
- Application data
- Neural Net data
Input files:
public string PredictorTrainName ;Output files:public string AbmTrainName ;To open these files, use the following functions:
public string AbmRetrainName ;
public string AbmRecognitionName ;
public string AbmOutputName ;bool openPredictorTrainFile( );The Decoding part uses the following files:
bool openAbmTrainFile( );
bool openAbmRetrainFile( );
bool openAbmRecognitionFile( );
bool openAbmOutputFile( );Input files:
public string AbmOutputName ;Output files:public string OutputName;To open these files, use the following functions:bool openAbmOutputFile( );8.5 Encoding and Decoding Methods
bool openOutputFile( );These commands are divided into two groups:
The Linear mode deals with two situations:
- Linear
- Exponential
The Exponential mode deals with:
- Data is in fixed intervals [a, b];
- Data grows linearly, 1, 2, 3, 4, � .
Each group has three commands:
- Data grows exponentially, 1, 2, 4, 8, � .
Here, "+" and "--" means the upper bound and the lower bound, respectively. Assume a prediction is
- +
- --
- 0
x = 5.6 + 0.3 - 0.2 ,i.e. the result is likely to be 5.6, but could be in the range [5.4, 5.9]; then'0' prediction ==> 5.6
'+' prediction ==> 5.9
'--' prediction ==> 5.4 .'+' and '--' predictions yield results more often than the '0' prediction, therefore, consider these two commands first.
'0' prediction, on other hand, is more accurate than the other two, if it produces a prediction.The Decoding part is further divided into:
The Encoding functions are:
- Real numbers
- Integers
bool predictorEncodeBinaryLinearPlus ();Based on the above discussion:
bool predictorEncodeBinaryLinearMinus ();
bool predictorEncodeBinaryLinearZero ();bool predictorEncodeBinaryExpPlus ();
bool predictorEncodeBinaryExpMinus ();
bool predictorEncodeBinaryExpZero ();The Decoding functions are:
- the function, predictorEncodeBinaryLinearPlus (), means linear and �+� encoding; and
- the function, predictorEncodeBinaryExpZero (), means exponential and �-� encoding.
bool predictorDecodeBinaryLinearPlusReal ();Based on the above discussion:
bool predictorDecodeBinaryLinearPlusInt ();
bool predictorDecodeBinaryLinearMinusReal ();
bool predictorDecodeBinaryLinearMinusInt ();
bool predictorDecodeBinaryLinearZeroInt ();
bool predictorDecodeBinaryLinearZeroReal ();bool predictorDecodeBinaryExpPlus ();
bool predictorDecodeBinaryExpMinus ();
bool predictorDecodeBinaryExpZero ();8.6 Parameters
- the function, predictorDecodeBinaryLinearPlusReal (), means linear, �+�, Real decoding; and
- the function, predictorDecodeBinaryExpZero (), means exponential and �-� decoding.
- the exponential Decoding only supports real number predictions.
The Parameters are:
public int Precision ;Let the Trend be N, the Predictor will look at all N-row patterns, then it looks at the last N - 1 rows and makes a prediction. The number of rows in the Trend is a user-selected variable: you decide the number of rows in the Trend. If you do not make a choice, the default value uses a 5-trend. To change the Trend, use this property.
public int Trend;
public double Empty-Field.The Precision-level determines the error level in each variable.
The Empty-Field means whenever the Predictor meets this number, it will ignore the number. The reason for this parameter is to handle cases where there are missing entries in the historical data.
Figure 8.1 Chapter 8 Project.
8.7 Chapter Project 1: File IO
This chapter project is in C:\polyapplet63\chap8\.
There are 5 files used:
Application InputThe default file names are:
Neural Net Training
Neural Net Recognition
Neural Net Output
Application OutputPredictor Input: example2a.txtWe implemented three of the five files earlier. The neural output text box will need to be modified as follows:
Train: example1a.txt
Retrain: example1b.txt
Recognition: example1c.txt
Neural Output: example1d.txt
Output: example2c.txtprivate void textBox3_TextChanged(object sender, System.EventArgs e)Now we will add two more files. Note that the abm2 object is called y.{
x.setOutputFile (textBox3.Text);
y.AbmOutputName = textBox3.Text;
}Application Input:
File Selection button:
private void button20_Click(object sender, System.EventArgs e)
{
if ( openFileDialog1.ShowDialog () != DialogResult.OK )
return;
textBox4.Text = openFileDialog1.FileName ;
}
Text Box:
private void textBox4_TextChanged(object sender, System.EventArgs e)
{
y.PredictorTrainName = textBox4.Text;
richTextBox1.AppendText ("Predictor Input: " + y.PredictorTrainName + "\n");
}Open Button:
private void button21_Click(object sender, System.EventArgs e)
{
y.openPredictorTrainFile ();
}
Application Output:File Selection button:8.8 Chapter Project 2: Neural Computing
private void button22_Click(object sender, System.EventArgs e)
{
if ( openFileDialog1.ShowDialog () != DialogResult.OK )
return;
textBox5.Text = openFileDialog1.FileName ;
}
Text Box:
private void textBox5_TextChanged(object sender, System.EventArgs e)
{
y.OutputName = textBox5.Text;
richTextBox1.AppendText ("Predictor Output: " + y.OutputName + "\n");
}Open Button
private void button23_Click(object sender, System.EventArgs e)
{
y.openOutputFile ();
}Both the Predictor and the DecisionMaker use the same binary command in the Abm. We will add multi-valued commands for later chapters. So there are two commands:
Binary:
private void button24_Click(object sender, System.EventArgs e){
if ( ! x.distribution () )
{
richTextBox1.AppendText ( "Classification fails!\n");
return;
}
x.openOutputFile ();
}
Polytomous:private void button8_Click(object sender, System.EventArgs e){if ( ! x.polyDistribution () )
{
richTextBox1.AppendText ( "Classification fails!\n");
return;
}
x.openOutputFile ();
}
8.9 Chapter Project 3: Encoding and DecodingWe have chosen 4 pairs of Encoding and Decoding:
+ Linear Integer Prediction:
private void button18_Click(object sender, System.EventArgs e)- Linear Integer Prediction:
{
y.predictorEncodeBinaryLinearPlus ();
richTextBox1.Text = "Encoding End!\n" ;
}private void button19_Click(object sender, System.EventArgs e)
{
y.predictorDecodeBinaryLinearPlusInt ();
y.openOutputFile ();
}private void button7_Click_1(object sender, System.EventArgs e)+ Linear Real Prediction:
{
y.predictorEncodeBinaryLinearMinus ();
richTextBox1.Text = "Encoding End!\n" ;
}private void button11_Click_1(object sender, System.EventArgs e)
{
y.predictorDecodeBinaryLinearMinusInt ();
y.openOutputFile ();
}private void button12_Click_1(object sender, System.EventArgs e)+ Exponential (Real) Prediction:
{
y.predictorEncodeBinaryLinearPlus ();
richTextBox1.Text = "Encoding End!\n" ;
}private void button13_Click_1(object sender, System.EventArgs e)
{
y.predictorDecodeBinaryLinearPlusReal ();
y.openOutputFile ();
}private void button14_Click_1(object sender, System.EventArgs e)8.10 Chapter Project 4: Run
{
y.predictorEncodeBinaryExpPlus ();
richTextBox1.Text = "Encoding End!\n" ;
}private void button15_Click_1(object sender, System.EventArgs e)
{
y.predictorDecodeBinaryExpPlus ();
y.openOutputFile ();
}There are two data files in this chapter project; both data files are from the Predictor. These two files are:
D_math1a.txt:
*
*
3
1 0 0
1 1 0
2 1 1
4 2 1
0 4 2
6 0 4
3 6 0
2 3 1
6 2 3
4 6 2
�
D_math2a.txt:
*
*
5
1 0 0 0 0
1 1 0 1 0
2 1 2 3 1
5 2 1 0 0
1 5 3 2 0
2 1 0 4 2
3 2 2 1 1
�The question is: �what is the next row in each case�?
Step 1. Files.
Enter the five data files in the following:
Input: D_math1a.txt:
Train: example1a.txt
Recognition: example1c.txt
Neural Output: example1d.txt
Output: example2c.txtStep 2. Encoding
Click the �+ Linear Int� encoding button.
Step 3. Neural Computing.
Click the �B Distribute� button (B = Binary) to complete the neural computing.
Step 4. Decoding.
Click the �+ Linear Int� decoding button.
Repeat Steps 2- 4 for:
- Linear Integer PredictionIn summary, we introduced the Abm2 class library in this chapter. Abm2 translates the Predictor data to and from neural data.
+ Linear Real Prediction
+ Exponential (Real) Prediction:
Return