private void BtnLoadClick(object sender, EventArgs e) { if (!File.Exists(_tbPathToLotos.Text) || !File.Exists(_tbPathToPR.Text) || !File.Exists(_tbPathToOrlen.Text)) { MessageBox.Show(Resources.InputMissing, Resources.FileMissing, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (_predictor == null || _predictor.Loaded == false) { this.Cursor = Cursors.WaitCursor; _hiddenLayers = (int)_nudHiddenLayers.Value; _hiddenUnits = (int)_nudHiddenUnits.Value; try { _predictor = new PredictIndicators(_pathToOrlen, _pathToPrimeRates, _pathToLotos, _hiddenUnits, _hiddenLayers); } catch (Exception ex) { MessageBox.Show(ex.Message, Resources.Exception, MessageBoxButtons.OK, MessageBoxIcon.Error); _predictor = null; return; } finally { this.Cursor = Cursors.Default; } } using (OpenFileDialog ofd = new OpenFileDialog() { FileName = "predictor.ntwrk", Filter = Resources.NtwrkFilter }) { bool result = true; if (ofd.ShowDialog() == DialogResult.OK) { try { _predictor.LoadNeuralNetwork(Path.GetFullPath(ofd.FileName)); _nudHiddenLayers.Value = _predictor.HiddenLayers; _nudHiddenUnits.Value = _predictor.HiddenUnits; } catch (System.Security.SecurityException) { MessageBox.Show(Resources.SecurityExceptionFolderLevel, Resources.Exception, MessageBoxButtons.OK, MessageBoxIcon.Error); result = false; } catch { MessageBox.Show(Resources.ExceptionMessage, Resources.Exception, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } if (result) { MessageBox.Show("The file with the trained data loaded successfully."); } } }
private void BtnPredictClick(object sender, EventArgs e) { if (_dgvPredictionResults.Rows.Count != 0) { _dgvPredictionResults.Rows.Clear(); } if (_predictor == null) { _reloadFiles = false; if (!File.Exists(_tbPathToLotos.Text) || !File.Exists(_tbPathToPR.Text) || !File.Exists(_tbPathToOrlen.Text)) { MessageBox.Show(Resources.InputMissing, Resources.FileMissing, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } switch (MessageBox.Show(Resources.UntrainedPredictorWarning, Resources.NoNetwork, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information)) { case DialogResult.Yes: break; case DialogResult.No: this.Cursor = Cursors.WaitCursor; _hiddenLayers = (int)_nudHiddenLayers.Value; _hiddenUnits = (int)_nudHiddenUnits.Value; try { _predictor = new PredictIndicators(_pathToOrlen, _pathToPrimeRates, _pathToLotos, _hiddenUnits, _hiddenLayers); } catch (Exception ex) { MessageBox.Show(ex.Message, Resources.Exception, MessageBoxButtons.OK, MessageBoxIcon.Error); _predictor = null; return; } finally { this.Cursor = Cursors.Default; } using (OpenFileDialog ofd = new OpenFileDialog() { FileName = "predictor.ntwrk", Filter = Resources.NtwrkFilter }) { if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { _predictor.LoadNeuralNetwork(Path.GetFullPath(ofd.FileName)); } catch { MessageBox.Show(Resources.ExceptionMessage, Resources.Exception, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } } break; case DialogResult.Cancel: return; } } DateTime predictFrom = _dtpPredictFrom.Value; DateTime predictTo = _dtpPredictTo.Value; if (predictFrom > predictTo) { MessageBox.Show(Resources.PredictFromToWarning, Resources.BadParameters, MessageBoxButtons.OK, MessageBoxIcon.Information); _dtpPredictFrom.Focus(); return; } if (_predictor == null) { _pathToOrlen = _tbPathToOrlen.Text; _pathToLotos = _tbPathToLotos.Text; _pathToPrimeRates = _tbPathToPR.Text; Cursor = Cursors.WaitCursor; _hiddenLayers = (int)_nudHiddenLayers.Value; _hiddenUnits = (int)_nudHiddenUnits.Value; try { _predictor = new PredictIndicators(_pathToOrlen, _pathToPrimeRates, _pathToLotos, _hiddenUnits, _hiddenLayers); } catch (Exception ex) { MessageBox.Show(ex.Message, Resources.Exception, MessageBoxButtons.OK, MessageBoxIcon.Error); _predictor = null; return; } finally { Cursor = Cursors.Default; } } List <PredictionResults> results = null; try { if (_reloadFiles) { _pathToOrlen = _tbPathToOrlen.Text; _pathToLotos = _tbPathToLotos.Text; _pathToPrimeRates = _tbPathToPR.Text; _predictor.ReloadFiles(_pathToOrlen, _pathToPrimeRates, _pathToLotos); } results = _predictor.Predict(predictFrom, predictTo); } catch (Exception ex) { MessageBox.Show(ex.Message, Resources.Exception, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } foreach (var item in results) { _dgvPredictionResults.Rows.Add(item.Date.ToShortDateString(), item.ActualLotos, item.PredictedLotos.ToString("F2", CultureInfo.InvariantCulture), item.ActualOrlen, item.PredictedOrlen.ToString("F2", CultureInfo.InvariantCulture), item.ActualPir, item.PredictedPir.ToString("F2", CultureInfo.InvariantCulture), item.Error.ToString("F4", CultureInfo.InvariantCulture)); } }