コード例 #1
0
        /// <summary>
        /// This method is called when DataContex of the ModelPage is changed, or when the different model
        /// in different project is changed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void ModelPage_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            try
            {
                //for the old DataContex we should save the state
                if (e.OldValue != null)
                {
                    //set wait cursor
                    MainWindow.SetCursor(true);

                    MLConfigController model = e.OldValue as MLConfigController;
                    if (model != null && !model.Deleted)
                    {
                        model.Save();
                    }

                    //model.Dispose();
                }
                //for new model we should show previously stored state
                if (e.NewValue != null)
                {
                    MLConfigController model = e.NewValue as MLConfigController;
                    evaluation.DataContext = null;
                    evaluation.DataContext = model;
                    model.Init();
                    //disable testing in case metadata is not presented
                    if (model.TestData == null || model.TestData.Where(x => x.Kind == ANNdotNET.Core.DataKind.Feature).Count() == 0)
                    {
                        testTab.Visibility = Visibility.Collapsed;
                    }

                    //restore cursor
                    MainWindow.SetCursor(false);

                    if (trainingTab.SelectedIndex == 2)
                    {
                        //force the tab page to evaluate model if available
                        await evaluation.EvaluateModel();
                    }
                }
            }
            catch (System.Exception ex)
            {
                //restore cursor
                MainWindow.SetCursor(false);

                await Application.Current.Dispatcher.BeginInvoke(
                    DispatcherPriority.Background,
                    new Action(

                        () =>
                {
                    var appCnt = App.Current.MainWindow.DataContext as AppController;
                    appCnt.ReportException(ex);
                }

                        ));
            }
        }
コード例 #2
0
 private void deleteModel(MLConfigController model)
 {
     if (MessageBox.Show($"Are you sure you want to delete '{model.Name}' model and all related files?", "ANNdotNET", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
     {
         var cont = DataContext as AppController;
         if (cont == null)
         {
             return;
         }
         cont.DeleteModel(model);
     }
 }
コード例 #3
0
 internal void DeleteModel(MLConfigController mlconfigController)
 {
     try
     {
         var prj = AppModel.Project[1] as ANNProjectController;
         prj.Models.Remove(mlconfigController);
         mlconfigController.Delete();
     }
     catch (Exception ex)
     {
         if (ReportException != null)
         {
             ReportException(ex);
         }
     }
 }
コード例 #4
0
        private void onCreateModel(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                var prj = ActiveViewModel as ANNProjectController;
                if (prj != null)
                {
                    var m = new MLConfigController(ActiveModelChanged);
                    prj.CreateMLConfig(m);
                }

                return;
            }
            catch (Exception ex)
            {
                ReportException(ex);
            }
        }
コード例 #5
0
 private void duplicateModel(MLConfigController model)
 {
 }
コード例 #6
0
 private void renameModel(MLConfigController model)
 {
     model.IsEditing = true;
 }
コード例 #7
0
        public async Task <ModelEvaluation> EvaluateModel()
        {
            try
            {
                MainWindow.SetCursor(true);

                MLConfigController pCont = this.DataContext as MLConfigController;
                var appCnt = anndotnet.wnd.App.Current.MainWindow.DataContext as AppController;

                appCnt.ModelEvaluationAction(false);

                //send model evaluation in the background
                var modeEval = await Task <ModelEvaluation> .Run(() => pCont.EvaluateModel());

                appCnt.ModelEvaluationAction(true);

                PrepareGraphs(modeEval);

                for (int i = 0; i < modeEval.TrainingValue.Count; i++)
                {
                    actualTraining.AddPoint(modeEval.TrainingValue[i]);
                    predictedTraining.AddPoint(modeEval.ModelValueTraining[i]);
                }
                for (int i = 0; i < modeEval.ValidationValue.Count; i++)
                {
                    actualValidation.AddPoint(modeEval.ValidationValue[i]);
                    predictedValidation.AddPoint(modeEval.ModelValueValidation[i]);
                }


                //Refresh the charts
                trainingGraph.RestoreScale(trainingGraph.GraphPane);
                validationGraph.RestoreScale(validationGraph.GraphPane);

                //regression
                if (modeEval.ModelOutputDim == 1)
                {
                    var itm = trainingItems.Items[0] as Regression;
                    itm.Visibility = Visibility.Visible;
                    var itm2 = trainingItems.Items[1] as BinaryClassification;
                    itm2.Visibility = Visibility.Collapsed;
                    var itm3 = trainingItems.Items[2] as Multiclass;
                    itm3.Visibility = Visibility.Collapsed;
                    itm.DataContext = modeEval.TrainPerformance;
                    //validation set
                    var itm11 = validatingItems.Items[0] as Regression;
                    itm11.Visibility = Visibility.Visible;
                    var itm21 = validatingItems.Items[1] as BinaryClassification;
                    itm21.Visibility = Visibility.Collapsed;
                    var itm31 = validatingItems.Items[2] as Multiclass;
                    itm31.Visibility  = Visibility.Collapsed;
                    itm11.DataContext = modeEval.ValidationPerformance;
                }//binary classification
                else if (modeEval.ModelOutputDim == 2)
                {
                    var itm = trainingItems.Items[0] as Regression;
                    itm.Visibility = Visibility.Collapsed;
                    var itm2 = trainingItems.Items[1] as BinaryClassification;
                    itm2.Visibility = Visibility.Visible;
                    var itm3 = trainingItems.Items[2] as Multiclass;
                    itm3.Visibility  = Visibility.Collapsed;
                    itm2.DataContext = modeEval.TrainPerformance;

                    var itm11 = validatingItems.Items[0] as Regression;
                    itm11.Visibility = Visibility.Collapsed;
                    var itm21 = validatingItems.Items[1] as BinaryClassification;
                    itm21.Visibility = Visibility.Visible;
                    var itm31 = validatingItems.Items[2] as Multiclass;
                    itm31.Visibility  = Visibility.Collapsed;
                    itm21.DataContext = modeEval.ValidationPerformance;
                }//multi-class classification
                else if (modeEval.ModelOutputDim > 2)
                {
                    var itm = trainingItems.Items[0] as Regression;
                    itm.Visibility = Visibility.Collapsed;
                    var itm2 = trainingItems.Items[1] as BinaryClassification;
                    itm2.Visibility = Visibility.Collapsed;
                    var itm3 = trainingItems.Items[2] as Multiclass;
                    itm3.Visibility  = Visibility.Visible;
                    itm3.DataContext = modeEval.TrainPerformance;

                    var itm11 = validatingItems.Items[0] as Regression;
                    itm11.Visibility = Visibility.Collapsed;
                    var itm21 = validatingItems.Items[1] as BinaryClassification;
                    itm21.Visibility = Visibility.Collapsed;
                    var itm31 = validatingItems.Items[2] as Multiclass;
                    itm31.Visibility  = Visibility.Visible;
                    itm31.DataContext = modeEval.ValidationPerformance;
                }

                return(modeEval);
            }
            catch (Exception ex)
            {
                AppController appCont = App.Current.MainWindow.DataContext as AppController;
                appCont.ReportException(ex);
                return(null);
            }
            finally
            {
                MainWindow.SetCursor(false);
                await Application.Current.Dispatcher.BeginInvoke(
                    DispatcherPriority.Background,
                    new Action(

                        () =>
                {
                    MainWindow.SetCursor(false);
                }

                        ));
            }
        }