Пример #1
0
 public SeparationOfDataSet(ISolver solver, LearningScenario learnignScenario, float [][] x, float [] y)
 {
     ISolver    = solver;
     LS         = learnignScenario;
     InputData  = x;
     OutputData = y;
 }
Пример #2
0
        private void importScenario(ArchiveScenario archScenario)
        {
            LearningScenario scen = new LearningScenario(archScenario);

            scen.save();
            archScenario.ID = scen.ID;
        }
 public LearningScenarioManagerViewModel()
 {
     learningScenario      = new LearningScenario();
     listLearningScenarion = Entity.all(typeof(LearningScenario));
     ScenarioList          = new ObservableCollection <LearningScenarioViewModel>();
     updateLearningScenariosInfo();
     propertiesHandler = new ActionHandler(() => requestShowLearningScenario?.Invoke(SelectedScenario), e => SelectedScenario != null);
     deleteHandler     = new ActionHandler(() => removeLearningScenario(SelectedScenario), e => SelectedScenario != null);
     createHandler     = new ActionHandler(() => requestCreateLearningScenario?.Invoke(), e => true);
 }
        public void createScenario()
        {
            LearningScenario ls = new LearningScenario()
            {
                Name = this.Name,
                LearningAlgorithmName = TeacherType,
                LAParameters          = AlgoParam,
                SelectionParameters   = SelectionType + "," + MixSeed + "," + SeparationParamValue
            };

            ls.save();
            ID = ls.ID;
            OnClose?.Invoke(this, null);
        }
        public PreprocessingLearnViewModel(List <LearnedSolver> learnedSolvers)
        {
            List <LearningStatistic> learningStatistic = new List <LearningStatistic>();

            foreach (LearnedSolver learnedSolver in learnedSolvers)
            {
                LearningScenario learningScenario = (LearningScenario)LearningScenario.getById(learnedSolver.LearningScenarioID, typeof(LearningScenario));
                learningStatistic.Add(new LearningStatistic(learnedSolver)
                {
                    LearningScenarioName = learningScenario.Name
                });
            }
            LearningStatistics = learningStatistic.ToArray();
        }
Пример #6
0
        private static void Predict()
        {
            var matches = JsonDb.GetMatches();

            ILearningScenario <Match> scenario = new LearningScenario <Match>();

            scenario.MaxIterations = 1000;
            scenario.MaxError      = 0.1;
            scenario.InputParams   = new List <IParamDefinition <Match> >();
            scenario.InputParams.Add(MatchParams.GetLastFiveHomeMatches(matches));
            scenario.InputParams.Add(MatchParams.GetLastFiveAwayMatches(matches));
            scenario.OutputParams = new List <IParamDefinition <Match> >();
            scenario.OutputParams.Add(MatchParams.GetResultValue(matches));

            var network = Training.Train(scenario, matches);

            Prediction.Compute(network, scenario, matches);
        }
        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);
        }
Пример #8
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);
        }