private void edtVMax_TextChanged(object sender, EventArgs e) { double dfVal; if (BaseParameter.TryParse(edtVMax.Text, out dfVal)) { edtVMin.BackColor = Color.White; } else { edtIterations.BackColor = Color.LightSalmon; } }
/// <summary> /// This method is inherited from the IComparer interface. It compares the two objects passed using a case insensitive comparison. /// </summary> /// <param name="x">First object to be compared</param> /// <param name="y">Second object to be compared</param> /// <returns>The result of the comparison. "0" if equal, negative if 'x' is less than 'y' and positive if 'x' is greater than 'y'</returns> public int Compare(object x, object y) { int compareResult; ListViewItem listviewX, listviewY; // Cast the objects to be compared to ListViewItem objects listviewX = (ListViewItem)x; listviewY = (ListViewItem)y; double dfA; double dfB; string strA = listviewX.SubItems[ColumnToSort].Text.TrimEnd(' ', '%'); string strB = listviewY.SubItems[ColumnToSort].Text.TrimEnd(' ', '%'); if (BaseParameter.TryParse(strA, out dfA) && BaseParameter.TryParse(strB, out dfB)) { compareResult = ObjectCompare.Compare(dfA, dfB); } else { compareResult = ObjectCompare.Compare(strA, strB); } // Calculate correct return value based on object comparison if (OrderOfSort == SortOrder.Ascending) { // Ascending sort is selected, return normal result of compare operation return(compareResult); } else if (OrderOfSort == SortOrder.Descending) { // Descending sort is selected, return negative result of compare operation return(-compareResult); } else { // Return '0' to indicate they are equal return(0); } }
private void btnOK_Click(object sender, EventArgs e) { string strModel = cmbModel.Text; string strSolverType = cmbSolver.Text; int nIterations; int nIntermediateIterations = 0; double dfLr; double dfTvLoss = 0; int nMaxImageSize = 640; if (!int.TryParse(edtIterations.Text, out nIterations) || nIterations < 1) { MessageBox.Show("The 'Iterations' value is invalid - enter a positive integer greater than one.", "Invalid Iterations", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.None; edtIterations.Focus(); return; } if (!BaseParameter.TryParse(edtLearningRate.Text, out dfLr) || dfLr <= 0) { MessageBox.Show("The 'Learning Rate' value is invalid - enter a positive real value greater than one.", "Invalid Learning Rate", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.None; edtLearningRate.Focus(); return; } if (!int.TryParse(edtMaxImageSize.Text, out nMaxImageSize) || nMaxImageSize < 64 || nMaxImageSize > 2048) { MessageBox.Show("The 'Max Image Size' value is invalid - enter a positive integer within the range [64, 2048].", "Invalid Max Image Size", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.None; edtMaxImageSize.Focus(); return; } if (!Directory.Exists(edtResultPath.Text)) { MessageBox.Show("The 'Result Path' is invalid, please enter the path to an existing folder.", "Invalid Result Path", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.None; btnBrowseResultPath.Focus(); return; } if (chkIntermediateOutput.Checked) { if (!int.TryParse(edtIntermediateIterations.Text, out nIntermediateIterations) || nIntermediateIterations < 0 || nIntermediateIterations > nIterations) { MessageBox.Show("The 'Intermediate Iterations' value is invalid - enter a positive integer within the range [1," + nIterations.ToString() + "].", "Invalid Intermediate Iterations", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.None; edtIntermediateIterations.Focus(); return; } } if (chkEnableTvLoss.Checked) { if (!BaseParameter.TryParse(edtTvLoss.Text, out dfTvLoss) || dfTvLoss < 0 || dfTvLoss > 0.1) { MessageBox.Show("The 'TV-Loss' value is invalid - enter a real value within the range [0,0.1].", "Invalid TV-Loss", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.None; edtTvLoss.Focus(); return; } } if (!File.Exists(edtContentImageFile.Text)) { MessageBox.Show("Could not find the content file '" + edtContentImageFile.Text + "'!", "Invalid Content File", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.None; btnBrowseContent.Focus(); return; } if (!File.Exists(edtStyleImageFile.Text)) { MessageBox.Show("Could not find the style file '" + edtStyleImageFile.Text + "'!", "Invalid Style File", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.None; btnBrowseStyle.Focus(); return; } m_info = new NeuralStyleInfo(edtStyleImageFile.Text, edtContentImageFile.Text, nIterations, strModel.ToLower(), strSolverType, dfLr, edtResultPath.Text, nIntermediateIterations, dfTvLoss, nMaxImageSize); }
private void btnOK_Click(object sender, EventArgs e) { if (!int.TryParse(edtIterations.Text, out m_nIterations) || m_nIterations < 1) { MessageBox.Show("The 'Iterations' value is invalid - please enter a valid positive integer value greater than or equal to 1.", "Invalid Iterations", MessageBoxButtons.OK, MessageBoxIcon.Error); edtIterations.Focus(); DialogResult = DialogResult.None; return; } if (!int.TryParse(edtMiniBatch.Text, out m_nMiniBatch) || m_nMiniBatch < 1) { MessageBox.Show("The 'Mini-Batch' value is invalid - please enter a valid positive integer value greater than or equal to 1.", "Invalid Mini-Batch", MessageBoxButtons.OK, MessageBoxIcon.Error); edtMiniBatch.Focus(); DialogResult = DialogResult.None; return; } Properties.Settings.Default.CustIteration = m_nIterations; Properties.Settings.Default.CustMiniBatch = m_nMiniBatch; m_bShowUi = chkShowUi.Checked; m_bUseAcceleratedTraining = chkUseAcceleratedTraining.Checked; m_bAllowDiscountReset = chkAllowDiscountReset.Checked; m_bAllowNegativeRewards = chkAllowNegativeRewards.Checked; m_bTerminateOnRallyEnd = chkTerminateOnRallyEnd.Checked; m_bLoadWeights = chkLoadWeights.Checked; if (radPGSimple.Checked) { m_strTrainer = "PG.SIMPLE"; } else if (radPGSingleThread.Checked) { m_strTrainer = "PG.ST"; } else if (radC51SingleThread.Checked) { m_strTrainer = "C51.ST"; } else if (radNoisyNetSingleThread.Checked) { m_strTrainer = "DQN.ST"; } else if (radNoisyNetSimple.Checked) { m_strTrainer = "DQN.SIMPLE"; } else { m_strTrainer = "PG.MT"; } if (radAtariBreakout.Checked) { m_strRomName = "breakout"; } else if (radAtariPong.Checked) { m_strRomName = "pong"; } else { m_strRomName = ""; } if (radC51SingleThread.Checked) { double dfVMin; double dfVMax; if (!BaseParameter.TryParse(edtVMin.Text, out dfVMin)) { MessageBox.Show("The 'VMin' value is invalid. Please enter a valid number.", "Invalid VMin", MessageBoxButtons.OK, MessageBoxIcon.Error); edtVMin.Focus(); DialogResult = DialogResult.None; return; } if (!BaseParameter.TryParse(edtVMax.Text, out dfVMax)) { MessageBox.Show("The 'VMax' value is invalid. Please enter a valid number.", "Invalid VMax", MessageBoxButtons.OK, MessageBoxIcon.Error); edtVMax.Focus(); DialogResult = DialogResult.None; return; } if (dfVMax <= dfVMin) { MessageBox.Show("The 'VMax' value must be greater than the 'VMin' value.", "Invalid VMin,VMax", MessageBoxButtons.OK, MessageBoxIcon.Error); edtVMin.Focus(); DialogResult = DialogResult.None; return; } m_dfVMin = dfVMin; m_dfVMax = dfVMax; Properties.Settings.Default.CustVmin = m_dfVMin; Properties.Settings.Default.CustVmax = m_dfVMax; } Properties.Settings.Default.Save(); }