Пример #1
0
        private void importLearnSolver(ArchiveLearnedSolver archSolver)
        {
            LearnedSolver solver = new LearnedSolver(archSolver);

            solver.save();
            archSolver.ID = solver.ID;
            importQualities(archSolver.Qualities, archSolver.ID);
        }
        public LearningStatistic(LearnedSolver learnedSolver)
        {
            LearningQuality learningQuality = (LearningQuality)LearningQuality.where (new Query("LearningQuality").addTypeQuery(TypeQuery.select)
                                                                                      .addCondition("LearnedSolverID", "=", learnedSolver.ID.ToString()), typeof(LearningQuality))[0];

            MistakeTest  = learningQuality.MistakeTest;
            MistakeTrain = learningQuality.MistakeTrain;
            ClosingError = Convert.ToSingle(learningQuality.ClosingError);
        }
        override public bool equalsEntity(models.Entity entity)
        {
            if (entity.GetType() != typeof(models.LearnedSolver))
            {
                return(false);
            }
            LearnedSolver solver = (LearnedSolver)entity;

            return(this.TaskSolver.ID == solver.TaskSolverID && this.Selection.ID == solver.SelectionID && this.scenario.ID == solver.LearningScenarioID);
        }
Пример #4
0
        public void deleteSelection(Entity selection)
        {
            List <Entity> listForDelete = new List <Entity>();

            int          templateId = ((Selection)selection).TaskTemplateID;
            TaskTemplate template   = ((TaskTemplate)services.DatabaseManager.SharedManager.entityById(templateId, typeof(TaskTemplate)));

            List <Entity> taskTemplates = TaskTemplate.where (new Query("TaskTemplate").addTypeQuery(TypeQuery.select)
                                                              .addCondition("TaskID", "=", template.TaskID.ToString()), typeof(TaskTemplate));
            List <Entity> selections = new List <Entity>();

            foreach (Entity entity in taskTemplates)
            {
                List <Entity> sels = TaskTemplate.where (new Query("Selection").addTypeQuery(TypeQuery.select)
                                                         .addCondition("TaskTemplateId", "=", entity.ID.ToString())
                                                         .addCondition("Name", "=", ((Selection)selection).Name), typeof(Selection));
                if (sels.Count == 0)
                {
                    continue;
                }
                else
                {
                    listForDelete = listForDelete.Concat(sels).ToList();
                    selections    = selections.Concat(sels).ToList();
                }
            }

            foreach (Entity sel in selections)
            {
                List <Entity> selectionRows = SelectionRow.where (new Query("SelectionRow").addTypeQuery(TypeQuery.select)
                                                                  .addCondition("SelectionID", "=", sel.ID.ToString()), typeof(SelectionRow));
                listForDelete = listForDelete.Concat(selectionRows).ToList();
                for (int i = 0; i < selectionRows.Count; i++)
                {
                    List <Entity> values = ValueParameter.where (new Query("ValueParameter").addTypeQuery(TypeQuery.select)
                                                                 .addCondition("SelectionRowID", "=", selectionRows[i].ID.ToString()), typeof(ValueParameter));
                    listForDelete = listForDelete.Concat(values).ToList();
                }

                List <Entity> learnedSolverList = LearnedSolver.where (new Query("LearnedSolver").addTypeQuery(TypeQuery.select)
                                                                       .addCondition("SelectionID", "=", sel.ID.ToString()), typeof(LearnedSolver));
                listForDelete = listForDelete.Concat(learnedSolverList).ToList();
                foreach (Entity lSolver in learnedSolverList)
                {
                    List <Entity> learningQualityList = LearningQuality.where (new Query("LearningQuality").addTypeQuery(TypeQuery.select)
                                                                               .addCondition("LearnedSolverID", "=", lSolver.ID.ToString()), typeof(LearningQuality));
                    listForDelete = listForDelete.Concat(learningQualityList).ToList();
                }
            }

            DatabaseManager.SharedManager.deleteMultipleEntities(listForDelete);
        }
Пример #5
0
        public void deleteTask(Entity task)
        {
            List <Entity> listForDelete = new List <Entity>();

            listForDelete.Add(task);

            List <Entity> templates = TaskTemplate.where (new Query("TaskTemplate").addTypeQuery(TypeQuery.select)
                                                          .addCondition("TaskID", "=", task.ID.ToString()), typeof(TaskTemplate));

            listForDelete = listForDelete.Concat(templates).ToList();

            foreach (Entity template in templates)
            {
                List <Entity> parameters = models.Parameter.where (new Query("Parameter").addTypeQuery(TypeQuery.select)
                                                                   .addCondition("TaskTemplateID", "=", template.ID.ToString()), typeof(models.Parameter));
                listForDelete = listForDelete.Concat(parameters).ToList();

                List <Entity> selections = Selection.where (new Query("Selection").addTypeQuery(TypeQuery.select)
                                                            .addCondition("TaskTemplateID", "=", template.ID.ToString()), typeof(Selection));
                listForDelete = listForDelete.Concat(selections).ToList();

                foreach (Entity selection in selections)
                {
                    List <Entity> selectionRows = SelectionRow.where (new Query("SelectionRow").addTypeQuery(TypeQuery.select)
                                                                      .addCondition("SelectionID", "=", selection.ID.ToString()), typeof(SelectionRow));
                    listForDelete = listForDelete.Concat(selectionRows).ToList();

                    for (int i = 0; i < selectionRows.Count; i++)
                    {
                        List <Entity> values = ValueParameter.where (new Query("ValueParameter").addTypeQuery(TypeQuery.select)
                                                                     .addCondition("SelectionRowID", "=", selectionRows[i].ID.ToString()), typeof(ValueParameter));
                        listForDelete = listForDelete.Concat(values).ToList();
                    }

                    List <Entity> learnedSolverList = LearnedSolver.where (new Query("LearnedSolver").addTypeQuery(TypeQuery.select)
                                                                           .addCondition("SelectionID", "=", selection.ID.ToString()), typeof(LearnedSolver));
                    listForDelete = listForDelete.Concat(learnedSolverList).ToList();
                    foreach (Entity lSolver in learnedSolverList)
                    {
                        List <Entity> learningQualityList = LearningQuality.where (new Query("LearningQuality").addTypeQuery(TypeQuery.select)
                                                                                   .addCondition("LearnedSolverID", "=", lSolver.ID.ToString()), typeof(LearningQuality));
                        listForDelete = listForDelete.Concat(learningQualityList).ToList();
                    }
                }
            }

            DatabaseManager.SharedManager.deleteMultipleEntities(listForDelete);
        }
        private void learnSolver()
        {
            foreach (LearningModel learningModel in LearningList)
            {
                TaskTemplate taskTemplate = (TaskTemplate)TaskTemplate.where (new Query("TaskTemplate").addTypeQuery(TypeQuery.select)
                                                                              .addCondition("Name", "=", learningModel.SelectedPreprocessing), typeof(TaskTemplate))[0];
                Selection selection = (Selection)Selection.where (new Query("Selection").addTypeQuery(TypeQuery.select)
                                                                  .addCondition("TaskTemplateID", "=", taskTemplate.ID.ToString())
                                                                  .addCondition("Name", "=", learningModel.SelectedSelection), typeof(Selection))[0];
                int countRows = selection.RowCount;
                LearningScenario learningScenario = (LearningScenario)LearningScenario.where (new Query("LearningScenario").addTypeQuery(TypeQuery.select)
                                                                                              .addCondition("Name", "=", learningModel.SelectedScenario), typeof(LearningScenario))[0];

                List <Entity> selectionRows = SelectionRow.where (new Query("SelectionRow").addTypeQuery(TypeQuery.select)
                                                                  .addCondition("SelectionID", "=", selection.ID.ToString()), typeof(SelectionRow));
                List <Entity> parameters = dms.models.Parameter.where (new Query("Parameter").addTypeQuery(TypeQuery.select)
                                                                       .addCondition("TaskTemplateID", "=", selection.TaskTemplateID.ToString()), typeof(dms.models.Parameter));
                int       stepRow    = 0;
                float[][] inputData  = new float[countRows][];
                float[]   outputData = new float[countRows];
                for (int i = 0; i < countRows; i++)
                {
                    inputData[i] = new float[parameters.Count - 1];
                }
                int outputParam = 0;
                for (int i = 0; i < parameters.Count; i++)
                {
                    if (((models.Parameter)parameters[i]).IsOutput == 1)
                    {
                        outputParam = parameters[i].ID;
                    }
                }

                string[][] vals  = Selection.valuesOfSelectionId(selection.ID);
                float[][]  fvals = new float[selection.RowCount][];
                for (int i = 0; i < selection.RowCount; i++)
                {
                    fvals[i] = new float[parameters.Count];
                    for (int j = 0; j < parameters.Count - 1; j++)
                    {
                        inputData[i][j] = float.Parse(vals[i][j].Replace(".", ","));
                    }
                    outputData[i] = float.Parse(vals[i][parameters.Count - 1].Replace(".", ","));
                }
                ISolver isolver = null;
                if (Solver.Description is PerceptronTopology)
                {
                    PerceptronTopology topology = Solver.Description as PerceptronTopology;
                    isolver = new PerceptronManaged(topology);
                }
                else if (Solver.Description is ConvNNTopology)
                {
                    ConvNNTopology topology = Solver.Description as ConvNNTopology;
                    isolver = new ConvNNManaged(topology);
                }
                else if (Solver.Description is WardNNTopology)
                {
                    WardNNTopology topology = Solver.Description as WardNNTopology;
                    isolver = new WardNNManaged(topology);
                }
                else if (Solver.Description is KohonenNNTopology)
                {
                    KohonenNNTopology topology = Solver.Description as KohonenNNTopology;
                    isolver = new KohonenManaged(topology);
                }
                else if (Solver.Description is TreeDescription)
                {
                    TreeDescription topology = Solver.Description as TreeDescription;
                    isolver = new DecisionTree(topology);
                }
                else if (Solver.Description is TreeDescriptionC4_5)
                {
                    TreeDescriptionC4_5 topology = Solver.Description as TreeDescriptionC4_5;
                    isolver = new DecisionTreeC4_5(topology);
                }
                else
                {
                    throw new EntryPointNotFoundException();
                }
                SeparationOfDataSet s  = new SeparationOfDataSet(isolver, learningScenario, inputData, outputData);
                LearnedSolver       ls = new LearnedSolver()
                {
                    SelectionID        = selection.ID,
                    LearningScenarioID = learningScenario.ID,
                    TaskSolverID       = Solver.ID,
                    Soul = s.separationAndLearn(selection.ID, outputParam)
                };
                ls.save();

                LearningQuality lq = new LearningQuality()
                {
                    LearnedSolverID = ls.ID,
                    MistakeTrain    = Convert.ToInt32(s.MistakeTrain),
                    MistakeTest     = Convert.ToInt32(s.MistakeTest),
                    ClosingError    = s.ClosingError
                };
                lq.save();
            }
            OnClose?.Invoke(this, null);
        }
Пример #7
0
        private void learnSolver()
        {
            foreach (LearningModel learningModel in LearningList)
            {
                TaskTemplate taskTemplate = (TaskTemplate)TaskTemplate.where (new Query("TaskTemplate").addTypeQuery(TypeQuery.select)
                                                                              .addCondition("Name", "=", learningModel.SelectedPreprocessing), typeof(TaskTemplate))[0];
                Selection selection = (Selection)Selection.where (new Query("Selection").addTypeQuery(TypeQuery.select)
                                                                  .addCondition("TaskTemplateID", "=", taskTemplate.ID.ToString())
                                                                  .addCondition("Name", "=", learningModel.SelectedSelection), typeof(Selection))[0];
                int countRows = selection.RowCount;
                LearningScenario learningScenario = (LearningScenario)LearningScenario.where (new Query("LearningScenario").addTypeQuery(TypeQuery.select)
                                                                                              .addCondition("Name", "=", learningModel.SelectedScenario), typeof(LearningScenario))[0];

                List <Entity> selectionRows = SelectionRow.where (new Query("SelectionRow").addTypeQuery(TypeQuery.select)
                                                                  .addCondition("SelectionID", "=", selection.ID.ToString()), typeof(SelectionRow));
                List <Entity> parameters = dms.models.Parameter.where (new Query("Parameter").addTypeQuery(TypeQuery.select)
                                                                       .addCondition("TaskTemplateID", "=", selection.TaskTemplateID.ToString()), typeof(dms.models.Parameter));
                int       stepRow    = 0;
                float[][] inputData  = new float[countRows][];
                float[]   outputData = new float[countRows];
                for (int i = 0; i < countRows; i++)
                {
                    inputData[i] = new float[parameters.Count - 1];
                }
                int outputParam = 0;
                foreach (Entity selRow in selectionRows)
                {
                    int selectionRowId = selRow.ID;
                    int stepParam      = 0;
                    foreach (Entity param in parameters)
                    {
                        int           paramId = param.ID;
                        List <Entity> value   = ValueParameter.where (new Query("ValueParameter").addTypeQuery(TypeQuery.select)
                                                                      .addCondition("ParameterID", "=", paramId.ToString()).
                                                                      addCondition("SelectionRowID", "=", selectionRowId.ToString()), typeof(ValueParameter));
                        if (((dms.models.Parameter)param).IsOutput == 1)
                        {
                            outputParam = param.ID;
                            string outputValue = ((ValueParameter)value[0]).Value;
                            float  outputFloat;
                            if (float.TryParse(outputValue, out outputFloat))
                            {
                                outputData[stepRow] = outputFloat;
                            }
                        }
                        else
                        {
                            inputData[stepRow][stepParam] = float.Parse(((ValueParameter)value[0]).Value, CultureInfo.InvariantCulture.NumberFormat);
                        }
                        stepParam++;
                    }
                    stepRow++;
                }
                ISolver isolver = null;
                if (Solver.Description is PerceptronTopology)
                {
                    PerceptronTopology topology = Solver.Description as PerceptronTopology;
                    isolver = new PerceptronManaged(topology);
                }
                else if (Solver.Description is ConvNNTopology)
                {
                    ConvNNTopology topology = Solver.Description as ConvNNTopology;
                    isolver = new ConvNNManaged(topology);
                }
                else if (Solver.Description is WardNNTopology)
                {
                    WardNNTopology topology = Solver.Description as WardNNTopology;
                    isolver = new WardNNManaged(topology);
                }
                else if (Solver.Description is TreeDescription)
                {
                    TreeDescription topology = Solver.Description as TreeDescription;
                    isolver = new DecisionTree(topology);
                }
                else
                {
                    throw new EntryPointNotFoundException();
                }
                SeparationOfDataSet s  = new SeparationOfDataSet(isolver, learningScenario, inputData, outputData);
                LearnedSolver       ls = new LearnedSolver()
                {
                    SelectionID        = selection.ID,
                    LearningScenarioID = learningScenario.ID,
                    TaskSolverID       = Solver.ID,
                    Soul = s.separationAndLearn(selection.ID, outputParam)
                };
                ls.save();

                LearningQuality lq = new LearningQuality()
                {
                    LearnedSolverID = ls.ID,
                    MistakeTrain    = Convert.ToInt32(s.MistakeTrain),
                    MistakeTest     = Convert.ToInt32(s.MistakeTest),
                    ClosingError    = s.ClosingError
                };
                lq.save();
            }
            OnClose?.Invoke(this, null);
        }
        public Archive generateArchiveSystem()
        {
            scenarioRelations.Clear();
            selectionRelations.Clear();
            taskSolverRelations.Clear();
            Archive       archive = new Archive();
            List <Entity> tasks   = models.Task.all(typeof(models.Task));

            foreach (models.Task task in tasks)
            {
                ArchiveTask         archTask  = new ArchiveTask(task);
                List <TaskTemplate> templates = TaskTemplate.templatesOfTaskId(task.ID);
                foreach (TaskTemplate template in templates)
                {
                    ArchiveTemplate  archTemp   = new ArchiveTemplate(template);
                    List <Selection> selections = Selection.selectionsOfTaskTemplateId(template.ID);
                    foreach (Selection sel in selections)
                    {
                        ArchiveSelection archSel = new ArchiveSelection(sel);
                        selectionRelations.Add(new RelationExport(sel.ID, archSel));
                        archTemp.Selections.Add(archSel);
                    }
                    List <Parameter> parameters = Parameter.parametersOfTaskTemplateId(template.ID);
                    foreach (Parameter par in parameters)
                    {
                        ArchiveParameter archPar = new ArchiveParameter(par);
                        archTemp.Parameters.Add(archPar);
                    }
                    archTask.Templates.Add(archTemp);
                }
                List <TaskSolver> solvers = TaskSolver.solversOfTaskId(task.ID);
                foreach (TaskSolver solver in solvers)
                {
                    ArchiveTaskSolver archSol = new ArchiveTaskSolver(solver);
                    taskSolverRelations.Add(new RelationExport(solver.ID, archSol));
                    archTask.Solvers.Add(archSol);
                }
                archive.Tasks.Add(archTask);
            }
            List <Entity> scenarios = LearningScenario.all(typeof(LearningScenario));

            foreach (LearningScenario scenario in scenarios)
            {
                ArchiveScenario archScenario = new ArchiveScenario(scenario);
                scenarioRelations.Add(new RelationExport(scenario.ID, archScenario));
                archive.Scenarios.Add(archScenario);
            }
            List <Entity> lSolvers = LearnedSolver.all(typeof(LearnedSolver));

            foreach (LearnedSolver solver in lSolvers)
            {
                ArchiveLearnedSolver   archSol   = new ArchiveLearnedSolver(solver);
                List <LearningQuality> quailties = LearningQuality.qualitiesOfSolverId(solver.ID);
                foreach (LearningQuality quality in quailties)
                {
                    ArchiveLearningQuality archQ = new ArchiveLearningQuality(quality);
                    archSol.Qualities.Add(archQ);
                }
                var find = taskSolverRelations.Find(x => x.ID == solver.TaskSolverID);
                archSol.TaskSolver = (find != null) ? (ArchiveTaskSolver)find.model : null;
                find = selectionRelations.Find(x => x.ID == solver.SelectionID);
                archSol.Selection = (find != null) ? (ArchiveSelection)find.model : null;
                find             = scenarioRelations.Find(x => x.ID == solver.LearningScenarioID);
                archSol.Scenario = (find != null) ? (ArchiveScenario)find.model : null;
                archive.LearnedSolvers.Add(archSol);
            }
            return(archive);
        }
        public SelectionLearnStatisticViewModel(Selection selection, string taskName)
        {
            CurSelection = selection;
            List <Entity> selections = Selection.where (new Query("Selection").addTypeQuery(TypeQuery.select)
                                                        .addCondition("Name", "=", selection.Name), typeof(Selection));
            List <Entity> learnedSolvers = new List <Entity>();

            foreach (Selection sel in selections)
            {
                learnedSolvers.AddRange(LearnedSolver.where (new Query("LearnedSolver").addTypeQuery(TypeQuery.select)
                                                             .addCondition("SelectionID", "=", sel.ID.ToString()), typeof(LearnedSolver)));
            }
            List <LearnedSolverViewModel> listLearnedSolverViewModel = new List <LearnedSolverViewModel>();
            ISet <string> nameLearnedSolver = new HashSet <string>();
            Dictionary <string, List <LearnedSolver> > dictionarytaskSolverToLearnedSolver = new Dictionary <string, List <LearnedSolver> >();

            foreach (LearnedSolver learnedSolver in learnedSolvers)
            {
                TaskSolver           taskSolver = (TaskSolver)TaskSolver.getById(learnedSolver.TaskSolverID, typeof(TaskSolver));
                List <LearnedSolver> learnedSolverForCurSolver;
                if (dictionarytaskSolverToLearnedSolver.TryGetValue(taskSolver.Name, out learnedSolverForCurSolver))
                {
                    learnedSolverForCurSolver.Add(learnedSolver);
                    dictionarytaskSolverToLearnedSolver[taskSolver.Name] = learnedSolverForCurSolver;
                }
                else
                {
                    learnedSolverForCurSolver = new List <LearnedSolver>()
                    {
                        learnedSolver
                    };
                    dictionarytaskSolverToLearnedSolver.Add(taskSolver.Name, learnedSolverForCurSolver);
                }
            }
            foreach (KeyValuePair <string, List <LearnedSolver> > pair in dictionarytaskSolverToLearnedSolver)
            {
                listLearnedSolverViewModel.Add(new LearnedSolverViewModel(pair.Value)
                {
                    Name = pair.Key
                });
            }
            LearnedSolvers = listLearnedSolverViewModel.ToArray();

            SolversToLearn = new ObservableCollection <SolverLearnRowViewModel>
            {
                new SolverLearnRowViewModel(this)
                {
                    SelectedName = "Персептрон 1"
                }
            };
            TaskName      = taskName;
            SelectionName = selection.Name;
            addHandler    = new ActionHandler(
                () =>
            {
                SolversToLearn.Add(new SolverLearnRowViewModel(this)
                {
                    SelectedName = "Персептрон " + (SolversToLearn.Count + 1)
                });
            }, e => true);
            learnCommand = new ActionHandler(learnSolver, e => true);
        }