// Json Encode and Decode
        public static MembershipFunction fromJson(string JsonData)
        {
            JSONObject MFJSO = new JSONObject(JsonData);

            if (MFJSO.HasField("MembershipFunction"))
            {
                return(new MembershipFunction(
                           MFJSO.GetField("Name").str,
                           MFJSO.GetField("MembershipFunction").str,
                           MFJSO.GetField("StartAxis").n,
                           MFJSO.GetField("AxisRange").n,
                           MFJSO.GetField("LinguisticWeight").n
                           ));
            }
            else
            {
                List <double> specVals = new List <double>();
                foreach (JSONObject j in MFJSO.GetField("Spec").list)
                {
                    specVals.Add(j.n);
                }

                return(MembershipFunction.Generate(
                           MFJSO.GetField("Name").str,
                           MFJSO.GetField("Type").str,
                           specVals.ToArray(),
                           MFJSO.GetField("LinguisticWeight").n
                           ));
            }
        }
Exemple #2
0
        public void Implicate(MembershipFunction MF, double space)
        {
            this.implicationData             = new ImplicationData();
            this.implicationData.StartAxis   = MF.start;
            this.implicationData.spacing     = space;
            this.implicationData.maximum     = 0;
            this.implicationData.centerPoint = MF.start + MF.length / 2;
            if (ruleWeight == -1)
            {
                this.ruleWeight = MF.weight;
            }
            double n = MF.start;
            double nImplication;
            double limit = MF.start + MF.length;

            while (n < limit)
            {
                nImplication = this.Implication(n, MF);
                if (nImplication > this.implicationData.maximum)
                {
                    this.implicationData.maximum = nImplication;
                    this.implicationData.MaxAxis.Clear();
                }
                if (nImplication == this.implicationData.maximum)
                {
                    this.implicationData.MaxAxis.Add(n);
                }
                implicationData.data.Add(nImplication);
                n += space;
            }
        }
Exemple #3
0
        // Constructor
        public static LinguisticVariable fromJson(string jsonData)
        {
            LinguisticVariable result = new LinguisticVariable();
            JSONObject         MFJSO  = new JSONObject(jsonData);
            string             type   = MFJSO.GetField("Type").str;

            if (!type.Equals("Linguistics") && !type.Equals("Fuzzy"))
            {
                return(null);
            }
            result.linguisticVariableVersion = MFJSO.GetField("Version").str;
            switch (result.JsonVersion)
            {
            case "0.1":
                result.linguisticName =
                    MFJSO.GetField("LinguisticVariable").str;
                result.minimumValue =
                    MFJSO.GetField("MinimumValue").n;
                result.rangeLength =
                    MFJSO.GetField("RangeLength").n;
                foreach (JSONObject MF in
                         MFJSO.GetField("LinguisticValues").list)
                {
                    result.membershipFunctions.Add(
                        MembershipFunction.fromJson(MF.Print())
                        );
                }
                if (MFJSO.HasField("LinguisticRule"))
                {
                    foreach (JSONObject Rule in
                             MFJSO.GetField("LinguisticRule").list)
                    {
                        result.linguisticRules.Add(
                            LinguisticRule.fromJson(Rule.Print()));
                    }
                }
                break;

            default:
                break;
            }
            return(result);
        }
Exemple #4
0
 public double Implication(double nValue, MembershipFunction MF)
 {
     return(this.implicationM.Implication(nValue, MF.expression, membershipValue.fuzzy));
 }