/// <name>btnRun_Click</name> /// <type>Event</type> /// <author>John Wittenauer</author> /// <summary> /// Trains the map using user-select settings and input. /// </summary> /// <param name="sender">Windows event parameter</param> /// <param name="e">Windows event parameter</param> private void btnRun_Click(object sender, EventArgs e) { // Validate that required parameters have been specified bool verifiedParameters = false; if (txtFileName.Text.Length == 0) { MessageBox.Show("No file name was specified.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (numAttributes.Value == 0 || numInstances.Value == 0) { MessageBox.Show("Number of attributes and number of instances were not properly specified.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (!int.TryParse(txtXMapSize.Text, out xMapSize) || !int.TryParse(txtYMapSize.Text, out yMapSize)) { MessageBox.Show("Map size parameters were not properly specified.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { verifiedParameters = true; } if (verifiedParameters) { // Declare a parser object and parse the provided input file into a table Parser parser = new Parser((int)numAttributes.Value, (int)numInstances.Value); try { parser.ParseInputFile(txtFileName.Text); } catch (IOException ex) { MessageBox.Show("File Read Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (Exception ex) { MessageBox.Show("Exception Thrown: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } // Declare a new map object and initialize it appropriately som = new Map(xMapSize, yMapSize, parser.NumberOfDimensions, (int)numIterations.Value, (double)numLearningRate.Value, parser); som.ExponentialRadiusDecay = radNeighborhoodExp.Checked; som.ExponentialLearningDecay = radLearningExp.Checked; som.ExponentialInfluenceDecay = radInfluenceExp.Checked; // Now that the map has been initialized we can draw the initial // version before training has started drawMap = true; proTrainingTime.Value = 0; pnlDisplayBlend.Refresh(); // Timer for the overall map training time Stopwatch timer = new Stopwatch(); timer.Start(); // Each loop is one training iteration - continues until the // user-defined maximum is reached while (som.Epoch < som.EpochLimit) { som.TrainMap(); if ((som.Epoch % (som.EpochLimit / 10)) == 0) { proTrainingTime.Value += 10; pnlDisplayBlend.Refresh(); } } // Update the timer display TimeSpan elapsedTime = timer.Elapsed; timer.Stop(); double timeDisplay = (double)elapsedTime.TotalMilliseconds / 1000; lblTrainingTime.Text = "Training Time: " + timeDisplay.ToString().Substring(0, 5) + " sec"; // Calculate the average quantization error of the map and update the label som.CalculateAQE(); //lblAQE.Text = "AQE: " + som.AverageQuantizationError.ToString().Substring(0, 8); lblAQE.Text = "AQE: " + som.AverageQuantizationError.ToString(); // Do a final refresh on the blended visualization display pnlDisplayBlend.Refresh(); // Calculate the unified distance matrix of the trained map and refresh the // display for the panel showing the U-matrix som.CalculateUMatrix(); pnlDisplayUMatrix.Refresh(); // Display the first four dimensions of the map as four component planes pnlDisplayComponents.Refresh(); } }