Example #1
0
 public RightSigmoidTerm(LinguisticType type, string name, double center, double width)
 {
     Type   = type;
     Name   = name;
     Center = center;
     Width  = width;
 }
Example #2
0
        public async Task <IActionResult> Create(LinguisticType linguisticType)
        {
            linguisticType.Id = ObjectId.GenerateNewId().ToString();
            await _lingusticTypeRepositary.Save(linguisticType);

            return(RedirectToAction("Index"));
        }
 public GaussTerm(LinguisticType type, string name, double center, double width)
 {
     Type   = type;
     Name   = name;
     Center = center;
     Width  = width;
 }
        static void Main(string[] args)
        {
            // load types
            LegalStateType = LoadLinguisticType("data/types/legalstate.json");
            SaveLinguisticTypeLineCharDataSet(LegalStateType, "data/types/legalstate.graph.json");

            FinanceStateType = LoadLinguisticType("data/types/financestate.json");
            SaveLinguisticTypeLineCharDataSet(FinanceStateType, "data/types/financestate.graph.json");

            TransparencyType = LoadLinguisticType("data/types/transparency.json");
            SaveLinguisticTypeLineCharDataSet(TransparencyType, "data/types/transparency.graph.json");

            HonestyType = LoadLinguisticType("data/types/honesty.json");
            SaveLinguisticTypeLineCharDataSet(HonestyType, "data/types/honesty.graph.json");

            PlanType = LoadLinguisticType("data/types/plan.json");
            SaveLinguisticTypeLineCharDataSet(PlanType, "data/types/plan.graph.json");

            RatingType = LoadLinguisticType("data/types/rating.json");
            SaveLinguisticTypeLineCharDataSet(RatingType, "data/types/rating.graph.json");

            // load data
            LoadAndFuzzifyData("data/developers/developer.json");
            SaveFuzzifiedData("data/developers/developer.data");

            // load rules
            LoadRules("data/rules/ruleset.json");
            SaveRulesData("data/rules/ruleset.data");

            // get results
            SaveResultDataSet("data/results/result.graph.json");
            SaveResultValues("data/results/result.data");
        }
        private static void SaveLinguisticTypeLineCharDataSet(LinguisticType type, string fileName)
        {
            const int PointCount = 15;

            var labels   = new List <int>();
            var datasets = type.Terms.ToDictionary(x => x.Name, x => new List <double>());

            double step = (type.MaxValue - type.MinValue) / PointCount;

            for (double label = type.MinValue; label <= type.MaxValue; label += step)
            {
                labels.Add((int)Math.Round(label));

                foreach (var term in type.Terms)
                {
                    datasets[term.Name].Add(term.CalcTruthDegree(label));
                }
            }

            JObject result = new JObject();

            result["labels"]   = new JArray(labels.ToArray());
            result["datasets"] = new JArray(datasets.Select(x =>
            {
                var set            = new JObject();
                var color          = GenerateRandomColor();
                set["label"]       = x.Key;
                set["data"]        = new JArray(x.Value.ToArray());
                set["borderColor"] = color;
                set["fill"]        = false;
                return(set);
            }).ToArray());

            File.WriteAllText(fileName, result.ToString());
        }
Example #6
0
        private LinguisticVariableParameters ParseQualifiers(XElement qualifier)
        {
            string name = qualifier.Element("name").Value;
            var    min  = double.Parse(qualifier.Element("discourse").Element("min").Value);
            var    max  = double.Parse(qualifier.Element("discourse").Element("max").Value);

            var labels = new List <string>();
            var membershipFunctions = new List <string>();

            foreach (var l in qualifier.Elements("label"))
            {
                labels.Add(l.Element("name").Value);
                membershipFunctions.Add(l.Element("membershipFunction").Value);
            }
            LinguisticType type = LinguisticType.Qualifier;
            var            attr = qualifier.Element("attribute").Value;

            return(new LinguisticVariableParameters()
            {
                Name = name,
                range = new Tuple <double, double>(min, max),
                Labels = labels,
                memberShipFunction = membershipFunctions,
                type = type,
                attribute = attr
            });
        }
Example #7
0
        public async Task Save(LinguisticType linguisticType)
        {
            var existed = await LinguisticTypes.FindAsync(x => x.Id == linguisticType.Id);

            if (existed.Any())
            {
                await LinguisticTypes.FindOneAndReplaceAsync(x => x.Id == linguisticType.Id, linguisticType);
            }
            else
            {
                await LinguisticTypes.InsertOneAsync(linguisticType);
            }
        }
        static void Main(string[] args)
        {
            var points = new LinguisticType("Рейтинговые баллы");

            points.CreateTerm("Мало", 20, 5, TermType.Left);
            points.CreateTerm("Средне", 40, 20);
            points.CreateTerm("Много", 70, 10, TermType.Right);

            var skips = new LinguisticType("Пропуски");

            skips.CreateTerm("Мало", 0, 10, TermType.Left);
            skips.CreateTerm("Средне", 5, 5);
            skips.CreateTerm("Много", 10, 10, TermType.Right);

            var studentPoints = points.CreateVariable("Баллы студента");

            studentPoints.Value = points.GetValue(10.0);
            var studentSkips = skips.CreateVariable("Пропуски студента");

            studentSkips.Value = skips.GetValue(20.0);

            var statement1 = new OrStatement(
                new AtomicStatement(studentPoints, points["Мало"]),
                new AtomicStatement(studentSkips, skips["Много"]));


            var call = new LinguisticType("Необходимость звонка", 0, 10);

            call.CreateTerm("Срочно звонить", 0, 4, TermType.Left);
            call.CreateTerm("Поговорить на собрании", 5, 4);
            call.CreateTerm("Не звонить", 10, 4, TermType.Right);

            var statement2 = new AndStatement(
                new AtomicStatement(studentPoints, points["Много"]),
                new AtomicStatement(studentSkips, skips["Мало"]));

            var ruleset = new MISORuleSet(call);

            ruleset.AddRule(statement1, call["Срочно звонить"]);
            ruleset.AddRule(statement2, call["Не звонить"]);

            Console.WriteLine(studentPoints);
            Console.WriteLine(studentSkips);

            Console.WriteLine(ruleset);
            Console.WriteLine(call.GetValue(ruleset.GetResult().Defuzzify()));
        }
        private static LinguisticType LoadLinguisticType(string fileName)
        {
            var typeParameters = JObject.Parse(File.ReadAllText(fileName));

            var name     = (string)typeParameters["name"];
            var minValue = typeParameters.ContainsKey("min") ?
                           (double)typeParameters["min"] : 0;
            var maxValue = typeParameters.ContainsKey("max") ?
                           (double)typeParameters["max"] : int.MaxValue;

            var terms = (JArray)typeParameters["terms"];

            var type = new LinguisticType(name, minValue, maxValue);

            for (int i = 0; i < terms.Count; i++)
            {
                var term       = terms[i];
                var termName   = (string)term["name"];
                var termCenter = (double)term["center"];
                var termWidth  = (double)term["width"];

                if (i == 0)
                {
                    type.CreateTerm(termName, termCenter, termWidth, TermType.Left);
                }
                else if (i == terms.Count - 1)
                {
                    type.CreateTerm(termName, termCenter, termWidth, TermType.Right);
                }
                else
                {
                    type.CreateTerm(termName, termCenter, termWidth);
                }
            }

            return(type);
        }
Example #10
0
        public async Task <IActionResult> Edit(LinguisticType linguisticType)
        {
            await _lingusticTypeRepositary.Save(linguisticType);

            return(RedirectToAction("Index"));
        }
 public FuzzyValue(LinguisticType type, ITerm term, double degree)
 {
     Type = type;
     Term = term;
     Degree = degree;
 }