📄 the main form.cs
字号:
// textBox4
//
this.textBox4.BackColor = System.Drawing.SystemColors.Control;
this.textBox4.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.textBox4.Location = new System.Drawing.Point(16, 76);
this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(80, 13);
this.textBox4.TabIndex = 0;
this.textBox4.Text = "Error Tolerance:";
//
// textBox5
//
this.textBox5.BackColor = System.Drawing.SystemColors.Control;
this.textBox5.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.textBox5.Location = new System.Drawing.Point(16, 50);
this.textBox5.Name = "textBox5";
this.textBox5.Size = new System.Drawing.Size(80, 13);
this.textBox5.TabIndex = 0;
this.textBox5.Text = "Momentum:";
//
// textBox8
//
this.textBox8.BackColor = System.Drawing.SystemColors.Control;
this.textBox8.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.textBox8.Location = new System.Drawing.Point(208, 368);
this.textBox8.Name = "textBox8";
this.textBox8.TabIndex = 22;
this.textBox8.Text = "ANN Output:";
this.textBox8.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
// textBoxDisplaySample
//
this.textBoxDisplaySample.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.textBoxDisplaySample.Location = new System.Drawing.Point(312, 48);
this.textBoxDisplaySample.Multiline = true;
this.textBoxDisplaySample.Name = "textBoxDisplaySample";
this.textBoxDisplaySample.Size = new System.Drawing.Size(264, 280);
this.textBoxDisplaySample.TabIndex = 13;
this.textBoxDisplaySample.Text = "";
//
// buttonVisuallyTestSample
//
this.buttonVisuallyTestSample.Location = new System.Drawing.Point(312, 16);
this.buttonVisuallyTestSample.Name = "buttonVisuallyTestSample";
this.buttonVisuallyTestSample.Size = new System.Drawing.Size(160, 24);
this.buttonVisuallyTestSample.TabIndex = 12;
this.buttonVisuallyTestSample.Text = "Visually Test Sample";
this.buttonVisuallyTestSample.Click += new System.EventHandler(this.eventHandler_ButtonClick);
//
// textBoxErrorTolerance
//
this.textBoxErrorTolerance.Location = new System.Drawing.Point(96, 76);
this.textBoxErrorTolerance.Name = "textBoxErrorTolerance";
this.textBoxErrorTolerance.Size = new System.Drawing.Size(56, 20);
this.textBoxErrorTolerance.TabIndex = 7;
this.textBoxErrorTolerance.Text = "";
//
// textBoxHiddenNodes
//
this.textBoxHiddenNodes.Location = new System.Drawing.Point(96, 128);
this.textBoxHiddenNodes.Name = "textBoxHiddenNodes";
this.textBoxHiddenNodes.Size = new System.Drawing.Size(56, 20);
this.textBoxHiddenNodes.TabIndex = 8;
this.textBoxHiddenNodes.Text = "";
//
// textBoxMomentum
//
this.textBoxMomentum.Location = new System.Drawing.Point(96, 50);
this.textBoxMomentum.Name = "textBoxMomentum";
this.textBoxMomentum.Size = new System.Drawing.Size(56, 20);
this.textBoxMomentum.TabIndex = 6;
this.textBoxMomentum.Text = "";
//
// textBoxActualResult
//
this.textBoxActualResult.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.textBoxActualResult.Location = new System.Drawing.Point(312, 360);
this.textBoxActualResult.Name = "textBoxActualResult";
this.textBoxActualResult.Size = new System.Drawing.Size(264, 20);
this.textBoxActualResult.TabIndex = 16;
this.textBoxActualResult.Text = "";
//
// button1
//
this.button1.Location = new System.Drawing.Point(168, 304);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(128, 23);
this.button1.TabIndex = 21;
this.button1.Text = "Run in Batch MODE";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// buttonUpdate
//
this.buttonUpdate.Location = new System.Drawing.Point(24, 184);
this.buttonUpdate.Name = "buttonUpdate";
this.buttonUpdate.Size = new System.Drawing.Size(120, 23);
this.buttonUpdate.TabIndex = 9;
this.buttonUpdate.Text = "Update";
this.buttonUpdate.Click += new System.EventHandler(this.eventHandler_ButtonClick);
//
// groupBox1
//
this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.textBoxConvergeTo,
this.textBoxInputHeight,
this.textBoxInputWidth,
this.buttonUpdate,
this.textBox2,
this.textBoxMaxEpochs,
this.textBoxMomentum,
this.textBox4,
this.textBox5,
this.textBoxErrorTolerance,
this.textBox7,
this.textBoxLearningRate,
this.textBoxHiddenNodes,
this.textBox6,
this.textBox10,
this.textBox11,
this.textBox3});
this.groupBox1.Location = new System.Drawing.Point(8, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(288, 216);
this.groupBox1.TabIndex = 10;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "Global Parameters";
//
// textBoxLearningRate
//
this.textBoxLearningRate.Location = new System.Drawing.Point(96, 24);
this.textBoxLearningRate.Name = "textBoxLearningRate";
this.textBoxLearningRate.Size = new System.Drawing.Size(56, 20);
this.textBoxLearningRate.TabIndex = 5;
this.textBoxLearningRate.Text = "";
//
// textBoxSampleNumber
//
this.textBoxSampleNumber.Location = new System.Drawing.Point(488, 16);
this.textBoxSampleNumber.MaxLength = 4;
this.textBoxSampleNumber.Name = "textBoxSampleNumber";
this.textBoxSampleNumber.Size = new System.Drawing.Size(40, 20);
this.textBoxSampleNumber.TabIndex = 14;
this.textBoxSampleNumber.Text = "0";
//
// buttonTrain
//
this.buttonTrain.Location = new System.Drawing.Point(8, 272);
this.buttonTrain.Name = "buttonTrain";
this.buttonTrain.Size = new System.Drawing.Size(128, 23);
this.buttonTrain.TabIndex = 3;
this.buttonTrain.Text = "Train";
this.buttonTrain.Click += new System.EventHandler(this.eventHandler_ButtonClick);
//
// FormMainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(584, 396);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.buttonEpochDataLogging,
this.textBox1,
this.button1,
this.buttonTestWeightsWithFile,
this.buttonResetANNData,
this.buttonLoadTrainedData,
this.buttonSaveTrainedData,
this.textBoxActualResult,
this.textBoxDisplayResult,
this.textBoxSampleNumber,
this.textBoxDisplaySample,
this.buttonVisuallyTestSample,
this.buttonLoadSampleData,
this.groupBox1,
this.buttonTrain,
this.textBox8});
this.Name = "FormMainForm";
this.Text = "ANN Assignment by Paul Lockwood (Nov 2001)";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new FormMainForm());
}
private void eventHandler_ButtonClick(object sender, System.EventArgs e)
{
// String userGesture = "";
if ((Button)sender == this.buttonTrain)
{
int pSeconds, pEpochs;
if (this.nonGUILogic.train(out pEpochs, out pSeconds))
System.Windows.Forms.MessageBox.Show ("Successfuly converged in " + pEpochs + " Epochs and " + pSeconds + " seconds");
else
System.Windows.Forms.MessageBox.Show ("Failed to converge");
}
if ((Button)sender == this.buttonUpdate)
{
SingletonGlobalParameters.instance().OUTPUT_TOLERANCE = (float)Convert.ToDouble(this.textBoxErrorTolerance.Text);
SingletonGlobalParameters.instance().LEARNING_RATE = (float)Convert.ToDouble(this.textBoxLearningRate.Text);;
SingletonGlobalParameters.instance().MOMENTUM = (float)Convert.ToDouble(this.textBoxMomentum.Text);;
SingletonGlobalParameters.instance().MAXIMUM_EPOCHS = Convert.ToInt32(this.textBoxMaxEpochs.Text);
SingletonGlobalParameters.instance().HIDDEN_NODES = Convert.ToInt32(this.textBoxHiddenNodes.Text);
SingletonGlobalParameters.instance().INPUT_HEIGHT = Convert.ToInt32(this.textBoxInputHeight.Text);
SingletonGlobalParameters.instance().INPUT_WIDTH = Convert.ToInt32(this.textBoxInputWidth.Text);
SingletonGlobalParameters.instance().CONVERGE_PERCENTAGE= Convert.ToInt32(this.textBoxConvergeTo.Text);
this.updateDisplayValues();
}
if ((Button)sender == this.buttonLoadTrainedData)
{
this.nonGUILogic.loadData();
this.updateDisplayValues();
}
if ((Button)sender == this.buttonSaveTrainedData)
{
this.nonGUILogic.saveData("");
}
if ((Button)sender == this.buttonLoadSampleData)
{
this.nonGUILogic.LoadSampleData("");
}
if ((Button)sender == this.buttonResetANNData)
{
this.nonGUILogic.ResetANNData();
}
if ((Button)sender == this.buttonVisuallyTestSample)
{
int sampleNumber = Convert.ToInt32(textBoxSampleNumber.Text);
string expectedResult;
this.textBoxDisplaySample.Text = this.nonGUILogic.GetSampleDisplayData(sampleNumber, out expectedResult);
if (this.textBoxDisplaySample.Text.Length>0)
{
this.textBoxDisplayResult.Text = expectedResult;
// Now do a forward prop
this.textBoxActualResult.Text = this.nonGUILogic.GetDisplayResult(sampleNumber);
}
}
// Test Trained Weights With a .dat File
if ((Button)sender == this.buttonTestWeightsWithFile) {
float dummy1, dummy2;
this.nonGUILogic.TestWeightsWithADataFile("", out dummy1, out dummy2);
}
// Log data for each Epoch
if ((Button)sender == this.buttonEpochDataLogging)
{
this.nonGUILogic.trainAndSaveEpochData();
}
}
private void displayResults(float[] result)
{
string message = "";
for (int i=0; i<result.Length; i++)
message += result[i] + "\r\n";
MessageBox.Show("ANN Result = " + message);
}
private void updateDisplayValues()
{
this.textBoxErrorTolerance.Text = Convert.ToString(SingletonGlobalParameters.instance().OUTPUT_TOLERANCE);
this.textBoxLearningRate.Text = Convert.ToString(SingletonGlobalParameters.instance().LEARNING_RATE);
this.textBoxMaxEpochs.Text = Convert.ToString(SingletonGlobalParameters.instance().MAXIMUM_EPOCHS);
this.textBoxMomentum.Text = Convert.ToString(SingletonGlobalParameters.instance().MOMENTUM);
this.textBoxHiddenNodes.Text = Convert.ToString(SingletonGlobalParameters.instance().HIDDEN_NODES);
this.textBoxInputHeight.Text = Convert.ToString(SingletonGlobalParameters.instance().INPUT_HEIGHT);
this.textBoxInputWidth.Text = Convert.ToString(SingletonGlobalParameters.instance().INPUT_WIDTH);
this.textBoxConvergeTo.Text = Convert.ToString(SingletonGlobalParameters.instance().CONVERGE_PERCENTAGE);
}
private void button1_Click(object sender, System.EventArgs e)
{
XOR_ANN.Batch_Run.BatchMode batchInstance = new XOR_ANN.Batch_Run.BatchMode();
batchInstance.runABatchFile();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -