示例#1
0
        private static void CheckType2(int stage = 3)
        {
            List<FuzzyVariable> inputVariables = DataProvider.DataProvider.GetInputVariables();
            FuzzyVariable outputVariable = DataProvider.DataProvider.GetOutputVariable();
            RulesList ruleDefinitions = DataProvider.DataProvider.GetRulesDefinitions();

            List<string> includedVariables = DataProvider.DataProvider.GetIncludedVariables(stage);
            var decisionMakerT1 = new DecisionMakerType1(inputVariables, outputVariable, ruleDefinitions, includedVariables);

            // DataProvider.DataProvider.SaveInputVariables(decisionMakerT1.SerializableParameters);
            var decisionMakerT2 = new DecisionMakerType2(decisionMakerT1);

            var learningDataSet = DataProvider.DataProvider.GetLearningDataSet();
            decisionMakerT2.Initialize(learningDataSet);
            Console.WriteLine("Initialized the type-2 FLS.");

            // DataProvider.DataProvider.SaveInputVariables(decisionMakerT2.SerializableParameters);
            Console.WriteLine("Learning data set ({0} vectors):", learningDataSet.Count);

            int i = 1;
            foreach (MeasurementWithResult vector in learningDataSet)
            {
                var result = decisionMakerT2.Infer(vector.InputValues);
                Console.WriteLine(
                    "X{0}: [{1}; {2}]",
                    i,
                    Math.Round(result.Lower, 2),
                    Math.Round(result.Upper, 2));
                i++;
            }

            var testDataSet = DataProvider.DataProvider.GetTestDataSet();
            Console.WriteLine("Test data set ({0} vectors):", testDataSet.Count);
            i = 1;
            foreach (MeasurementWithResult vector in testDataSet)
            {
                var result = decisionMakerT2.Infer(vector.InputValues);
                Console.WriteLine(
                    "X{0}: [{1}; {2}]",
                    i,
                    Math.Round(result.Lower, 2),
                    Math.Round(result.Upper, 2));
                i++;
            }
        }
示例#2
0
        public ActionResult InitializeFLS()
        {
            try
            {
                // initialize the FLS
                List<FuzzyVariable> inputVariables = GetInputVariables(db);
                FuzzyVariable outputVariable = GetOutputVariable(db);
                var ruleDefinitions = new RulesList();
                ruleDefinitions.Items = (from r in db.Rules select new RuleDef { Definition = r.Definition, Weight = r.Weight }).ToList();
                var decisionMakerT1 = new DecisionMakerType1(inputVariables, outputVariable, ruleDefinitions);

                // DataProvider.DataProvider.SaveInputVariables(decisionMakerT1.SerializableParameters);
                var decisionMakerT2 = new DecisionMakerType2(decisionMakerT1);

                var learningDataSet = DataProvider.DataProvider.GetLearningDataSet();
                decisionMakerT2.Initialize(learningDataSet);

                // DataProvider.DataProvider.SaveInputVariables(decisionMakerT2.SerializableParameters);
                var decisionMakerProperties = new DecisionMakerProperties
                {
                    ParametersXml = DataProvider.DataProvider.WriteInputVariables(decisionMakerT2.SerializableParameters)
                };

                db.Database.ExecuteSqlCommand("TRUNCATE TABLE DecisionMakerProperties");
                db.SaveChanges();

                db.DecisionMakerProperties.Add(decisionMakerProperties);
                db.SaveChanges();

                return new HttpStatusCodeResult(HttpStatusCode.OK);
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message);
            }
        }
示例#3
0
        public ActionResult Infer(WorkspaceModel workspace)
        {
            try
            {
                List<FuzzyVariable> inputVariables = GetInputVariables();
                FuzzyVariable outputVariable = GetOutputVariable();
                RulesList ruleDefinitions = GetRulesDefinitions();

                List<string> includedVariables = GetIncludedVariables(workspace.ParametersValues);
                var decisionMakerT1 = new DecisionMakerType1(inputVariables, outputVariable, ruleDefinitions, includedVariables);

                // DataProvider.DataProvider.SaveInputVariables(decisionMakerT1.SerializableParameters);
                var decisionMakerT2 = new DecisionMakerType2(decisionMakerT1);

                var learningDataSet = DataProvider.DataProvider.GetLearningDataSet();
                decisionMakerT2.Initialize(learningDataSet);

               // var decisionMakerProperties = db.DecisionMakerProperties.Single(d => true);
               // var decisionMakerT2 = new DecisionMakerType2(decisionMakerProperties.ParametersXml, outputVariable, ruleDefinitions, inputVariables);
                Dictionary<string, double> vector = GetInputVector(workspace.ParametersValues);
                var result = decisionMakerT2.Infer(vector);
                var linguisticTerms = DecisionMakerType2.IntervalToLinguistic(result);

                ResultModel resultModel = ResultToModel(result, workspace.IsComplete, workspace.ID, workspace.Name, string.Join(", ", linguisticTerms));
                return this.PartialView("_Result", resultModel);
            }
            catch (Exception ex)
            {
                return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.Message);
            }
        }