Beispiel #1
0
 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.");
         }
     }
 }
Beispiel #2
0
 private void NudHiddenLayersValueChanged(object sender, EventArgs e)
 {
     if (_predictor == null)
     {
         return;
     }
     if (MessageBox.Show(Resources.ChangedNetwork, Resources.Warning, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
     {
         _predictor = null;
     }
 }
Beispiel #3
0
        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));
            }
        }
Beispiel #4
0
        private void BtnStartTrainingClick(object sender, EventArgs e)
        {
            if (_dgvTrainingResults.Rows.Count != 0)
            {
                _dgvTrainingResults.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;
                }
            }

            DateTime trainFrom = _dtpTrainFrom.Value;
            DateTime trainTo   = _dtpTrainUntil.Value;

            if (trainFrom > trainTo)
            {
                MessageBox.Show(Resources.TrainFromTrainTo, Resources.BadParameters, MessageBoxButtons.OK, MessageBoxIcon.Information);
                _dtpTrainFrom.Focus();
                return;
            }
            FadeControls(true);
            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;
                }
            }
            else if (_reloadFiles)
            {
                _pathToOrlen      = _tbPathToOrlen.Text;
                _pathToLotos      = _tbPathToLotos.Text;
                _pathToPrimeRates = _tbPathToPR.Text;
                _predictor.ReloadFiles(_pathToOrlen, _pathToPrimeRates, _pathToLotos);
                _dtpTrainFrom.MinDate  = _predictor.MinIndexDate;
                _dtpTrainUntil.MaxDate = _predictor.MaxIndexDate;
            }

            if (trainFrom < _predictor.MinIndexDate)
            {
                _dtpTrainFrom.MinDate = _dtpTrainFrom.Value = trainFrom = _predictor.MinIndexDate;
            }
            if (trainTo > _predictor.MaxIndexDate)
            {
                _dtpTrainUntil.MaxDate = _dtpTrainUntil.Value = trainTo = _predictor.MaxIndexDate;
            }
            TrainingStatus callback = TrainingCallback;

            _predictor.TrainNetworkAsync(trainFrom, trainTo, callback);
        }