コード例 #1
0
 public void setup()
 {
     Json1 =
         @"
         {
           ""Name"" : """ + LinguisticName + @""",
           ""MembershipFunction"" : """ + Expression + @""",
           ""StartAxis"" : " + StartX + @",
           ""AxisRange"" : " + LengthX + @",
           ""LinguisticWeight"" : " + testWeight + @"
         }
         ";
     Json2 =
         @"
         {
           ""Name"" : """ + LinguisticName + @""",
           ""Type"" : """ + Type + @""",
           ""Spec"" : [" + string.Join(",", Spec.Select(x => x.ToString()).ToArray()) + @"],
           ""LinguisticWeight"" : " + testWeight + @"
         }
         ";
     TestMF = new MembershipFunction(
         LinguisticName,
         Expression);
 }
コード例 #2
0
        public void T3RangeCalibration()
        {
            LinguisticVariable =
                LinguisticVariable.fromJson(JsonLingVar);
            LinguisticVariable.RangeCalibration(1, 0.01);
            string LogMsg = "{Range Calibration Test Result]\n";

            LogMsg += string.Format(
                "{0,-15}\t| {1,-15}{2,-15}\t| {3,-15}{4,-15}\n",
                "Linguistic",
                "Start",
                "",
                "length",
                ""
                );
            LogMsg += "=============== <Before> / <After> ===============\n";
            foreach (MembershipFunction MF in LinguisticVariable.membershipFunctions)
            {
                MembershipFunction PreCalib = MFs.Find(
                    x =>
                    x.membershipValue.linguistic == MF.membershipValue.linguistic);
                LogMsg += string.Format(
                    "{0,-15}\t| {1,15} / {2,-15}\t| {3,15} / {4,-15}\n",
                    MF.membershipValue.linguistic,
                    PreCalib.start,
                    MF.start,
                    PreCalib.length,
                    MF.length
                    );
            }
            Debug.Log(LogMsg);
        }
コード例 #3
0
        private MembershipFunction combine(MembershipFunction first, MembershipFunction second)
        {
            if (!first.Any())
                return second;
            if (!second.Any())
                return first;


            var scanPoints = new List<double>();
            scanPoints.AddRange(first.Keys);
            foreach (var key in second.Keys.Where(key => !scanPoints.Contains(key)))
                scanPoints.Add(key);
            scanPoints.Sort();



            var result = new MembershipFunction();
            foreach (var scanPoint in scanPoints)
            {
                var valueFirst = first.Apply(scanPoint);
                var valueSecond = second.Apply(scanPoint);

                result.Add(scanPoint, valueFirst + valueSecond);
            }

            return result.ClearUp();
        }
コード例 #4
0
        public double Apply(NumericVariable numericVariable, MembershipFunction msf)
        {
            if (msf.Count == 0)
                return (numericVariable.MaxValue - numericVariable.MinValue) / 2.0;
            if (msf[0].Y > 0 && msf[0].X > numericVariable.MinValue)
            {
                msf.Add(numericVariable.MinValue, msf[0].Y);
            }
            if (msf[msf.Count - 1].Y > 0 && msf[msf.Count - 1].X < numericVariable.MaxValue)
            {
                msf.Add(numericVariable.MaxValue, msf[msf.Count - 1].Y);
            }

            var numerator = 0d;
            var denominator = 0d;
            for (var i = 0; i < msf.Count - 1; i++)
            {
                var value1 = msf[i];
                var value2 = msf[i + 1];

                var min = Math.Min(value1.Y, value2.Y);
                var max = Math.Max(value1.Y, value2.Y);
                
                var line = new LineSegment(value1, value2);
                var m = line.Gradient.Value;
                var b = line.B.Value;
                numerator += ((m / 3.0) * (Math.Pow(value2.X, 3) - Math.Pow(value1.X, 3))) + ((b / 2.0) * (Math.Pow(value2.X, 2) - Math.Pow(value1.X, 2)));
                denominator += ((max + min) / 2.0) * (value2.X - value1.X);

            }
            return numerator / denominator;
        }
コード例 #5
0
 public void SetValues(MembershipFunction function)
 {
     a     = function.a;
     b     = function.b;
     alpha = function.alpha;
     beta  = function.beta;
 }
コード例 #6
0
        public double Apply(NumericVariable numericVariable, MembershipFunction msf)
        {
            var maximum = double.NegativeInfinity;
            var left = 0d;
            var right = 0d;
            foreach (var item in msf)
            {
                if (item.Value > maximum)
                {
                    maximum = item.Value;
                    left = item.Key;
                    right = item.Key;
                }
                else if(Math.Abs(item.Value - maximum) < 0.00000000001)
                {
                    right = item.Key;
                }
            }
            var first = msf[0];
            if (Math.Abs(first.Y - maximum) < 0.00000000001)
            {
                left = numericVariable.MinValue;
            }
            var last = msf[msf.Count -1];
            if (Math.Abs(last.Y - maximum) < 0.00000000001)
            {
                right = numericVariable.MaxValue;
            }

            return getValue(left, right);
        }
コード例 #7
0
ファイル: FuzzyTermTest.cs プロジェクト: NaoDevils/FuzzyLabs
        public void ToStringTest()
        {
            var membershipFunction = new MembershipFunction();

            var sut = new FuzzyTerm("MyFuzzyTerm", membershipFunction);

            Assert.AreEqual("MyFuzzyTerm", sut.ToString());
        }
コード例 #8
0
        public void ApplyWithOnePoint()
        {
            var sut = new MembershipFunction{ { 42, 1 } };

            Assert.AreEqual(1, sut.Apply(42.0));
            // The membership value of the one point exists everywhere
            Assert.AreEqual(1, sut.Apply(0));
            Assert.AreEqual(1, sut.Apply(1701));
        }
コード例 #9
0
 private static List<double> getScanPoints(MembershipFunction first, MembershipFunction second)
 {
     var scanPoints = new List<double>();
     scanPoints.AddRange(first.Keys);
     foreach (var key in second.Keys.Where(key => !scanPoints.Contains(key)))
         scanPoints.Add(key);
     scanPoints.Sort();
     return scanPoints;
 }
コード例 #10
0
 public void T3Generate()
 {
     TestMF = MembershipFunction.fromJson(Json2);
     Assert.AreEqual(
         LinguisticName,
         TestMF.membershipValue.linguistic);
     TestMF.Fuzzification(4);
     Debug.Log("[Generate Test MF Result]\n" + TestMF.encodeCompleteJson().Print(true));
 }
コード例 #11
0
ファイル: FuzzyTermTest.cs プロジェクト: NaoDevils/FuzzyLabs
        public void ConstructorFails()
        {
            var membershipFunction = new MembershipFunction();

            Assert.AreEqual("term",
                Assert.Throws<ArgumentException>(() => new FuzzyTerm("", membershipFunction)).Message);
            Assert.AreEqual("membershipFunction",
                Assert.Throws<ArgumentNullException>(() => new FuzzyTerm("MyFuzzyTerm", null)).ParamName);
        }
コード例 #12
0
ファイル: FuzzyTerm.cs プロジェクト: NaoDevils/FuzzyLabs
 /// <summary>
 /// Constructs a FuzzyTerm.
 /// </summary>
 /// <param name="term">The linguistic value.</param>
 /// <param name="membershipFunction">The membership function.</param>
 public FuzzyTerm(string term, MembershipFunction membershipFunction)
 {
     if (string.IsNullOrEmpty(term))
         throw new ArgumentException("term");
     if (membershipFunction == null)
         throw new ArgumentNullException("membershipFunction");
     Term = term;
     MembershipFunction = membershipFunction;
 }
コード例 #13
0
        public void Merge_6()
        {
            var expected = new MembershipFunction();

            var sut = new SumMsfMergingStrategy();
            var result = sut.Apply(new MembershipFunction[] { });

            Assert.AreEqual(expected, result);
        }
コード例 #14
0
ファイル: FuzzyTermTest.cs プロジェクト: NaoDevils/FuzzyLabs
        public void Constructor()
        {
            var membershipFunction = new MembershipFunction();

            var sut = new FuzzyTerm("MyFuzzyTerm", membershipFunction);

            Assert.AreEqual("MyFuzzyTerm", sut.Term);
            Assert.AreEqual(membershipFunction, sut.MembershipFunction);
        }
コード例 #15
0
 public void T1Construct()
 {
     TestMF = new MembershipFunction(
         LinguisticName,
         Expression);
     Assert.AreEqual(
         LinguisticName,
         TestMF.membershipValue.linguistic);
     Assert.AreEqual(Expression, TestMF.expression);
 }
コード例 #16
0
        public static bool MembershipFunctionsAreEqual(
            MembershipFunction membershipFunctionToCompare,
            MembershipFunction membershipFunctionToCompareWith)
        {
            Type membershipFunctionToCompareType     = membershipFunctionToCompare.GetType();
            Type membershipFunctionToCompareWithType = membershipFunctionToCompareWith.GetType();

            return(membershipFunctionToCompareType == membershipFunctionToCompareWithType &&
                   membershipFunctionToCompare.Equals(membershipFunctionToCompareWith));
        }
コード例 #17
0
 public void T4RangeCalibration()
 {
     TestMF = MembershipFunction.fromJson(Json2);
     Assert.AreEqual(
         LinguisticName,
         TestMF.membershipValue.linguistic);
     TestMF.Fuzzification(4);
     TestMF.rangeCalculation(1, 30, 0.1, 0.1);
     Debug.Log("[Range Calibration Test Result]\n" + TestMF.encodeCompleteJson().Print(true));
 }
コード例 #18
0
        public void Apply_With_No_Point()
        {
            var msf = new MembershipFunction();

            var sut = new ProdMsfScalingStrategy();

            var result = sut.Apply(msf, 0.5);

            Assert.AreEqual(0, result.Count);
        }
コード例 #19
0
        public void FindByVariableName_ReturnsMembershipFunctionForVariable()
        {
            // Arrange
            string variableName = "FunctionNr1";

            // Act
            MembershipFunction actualMembershipFunction = _membershipFunctionList.FindByVariableName(variableName);

            // Assert
            Assert.AreEqual(variableName, actualMembershipFunction.LinguisticVariableName);
        }
コード例 #20
0
        public void Apply_4(string method, double expected)
        {
            var numVar = new NumericVariable("Num Variable", 0, 3);
            var msf = new MembershipFunction { { 1, 1 } };

            var sut = createSut(method);

            var result = sut.Apply(numVar, msf);

            Assert.AreEqual(expected, result);
        }
コード例 #21
0
        public void Merge_6()
        {
            var msf1 = new MembershipFunction{ { 0, 0 }, { 1, 1 }, { 2, 0 } };

            var expected = new MembershipFunction{ { 0, 0 }, { 1, 1 }, { 2, 0 } };

            var sut = new MaxMsfMergingStrategy();
            var result = sut.Apply(new[] { msf1 });

            Assert.AreEqual(expected, result);
        }
コード例 #22
0
        public MembershipFunction Apply(MembershipFunction msf, double value)
        {
            var result = new MembershipFunction();

            foreach (var point in msf)
            {
                result.Add(point.Key, value*point.Value);
            }

            return result;
        }
コード例 #23
0
 public void T7LinguisticEncode()
 {
     TestMF = new MembershipFunction(
         LinguisticName, Expression);
     Assert.AreEqual(
         LinguisticName,
         TestMF.encodeLinguisticJson().GetField("Name").str);
     Assert.AreEqual(
         Expression,
         TestMF.encodeLinguisticJson().
         GetField("MembershipFunction").str);
 }
コード例 #24
0
        public void ApplyForTriangle()
        {
            var sut = new MembershipFunction {{1, 0}, {3, 1}, {5, 0}};

            Assert.AreEqual(0.0, sut.Apply(0));
            Assert.AreEqual(0.0, sut.Apply(1));
            Assert.AreEqual(0.5, sut.Apply(2));
            Assert.AreEqual(1.0, sut.Apply(3));
            Assert.AreEqual(0.5, sut.Apply(4));
            Assert.AreEqual(0.0, sut.Apply(5));
            Assert.AreEqual(0.0, sut.Apply(6));
        }
コード例 #25
0
 public void T2JsonConstruct()
 {
     TestMF = MembershipFunction.fromJson(Json1);
     Assert.AreEqual(
         LinguisticName,
         TestMF.membershipValue.linguistic);
     Assert.AreEqual(Expression, TestMF.expression);
     Assert.AreEqual(StartX, TestMF.start);
     Assert.AreEqual(LengthX, TestMF.length);
     Assert.AreEqual(testWeight, TestMF.weight);
     Debug.Log("[Construct Test MF Json]\n" + TestMF.encodeCompleteJson().Print(true));
 }
コード例 #26
0
        public void Apply_5()
        {
            var msf1 = new MembershipFunction { { 1, 0.5 } };
            var msf2 = new MembershipFunction { { 1, 1 } };

            var expected = new MembershipFunction { { 1, 1.5 } };

            var sut = new SumMsfMergingStrategy();
            var result = sut.Apply(new[] { msf1, msf2 });

            Assert.AreEqual(expected, result);
        }
コード例 #27
0
        public void Apply_With_One_Point()
        {
            var msf = new MembershipFunction{ { 0, 0.7 } };

            var sut = new ProdMsfScalingStrategy();

            var result1 = sut.Apply(msf, 0.5);

            Assert.AreEqual(1, result1.Count);
            foreach (var point in result1)
                Assert.AreEqual(0.5*0.7, point.Value);
        }
コード例 #28
0
        /// <summary>
        /// Mamdani-implication
        /// </summary>
        /// <param name="msf"></param>
        /// <param name="minValue"></param>
        /// <returns></returns>
        public MembershipFunction Apply(MembershipFunction msf, double minValue)
        {
            var result = new MembershipFunction();

            var count = msf.Count;

            if(count == 0)
                return msf;

            if (count == 1)
            {
                foreach (var point in msf)
                    result.Add(point.Key, Math.Min(point.Value, minValue));
            }
            else
            {
                for (var i = 0; i < count - 1; i++)
                {
                    var key = msf.Keys[i];
                    var nextKey = msf.Keys[i + 1];
                    var value = msf.Values[i];
                    var nextValue = msf.Values[i + 1];

                    if (value <= minValue)
                    {
                        result.Add(key, value);
                        if (nextValue > minValue)
                        {
                            var m = (nextValue - value)/(nextKey - key);

                            var newKey = key + minValue/m;
                            if(!result.Keys.Contains(newKey))
                                result.Add(newKey, minValue);
                        }
                    }
                    else if (nextValue < minValue)
                    {
                        var m = (nextValue - value)/(nextKey - key);

                        var newKey = key + (minValue - value)/m;

                        result.Add(newKey, minValue);
                    }
                }
                if (msf.Values[count - 1] <= minValue)
                {
                    result.Add(msf.Keys[count - 1], msf.Values[count - 1]);
                }
            }

            return result.ClearUp();
        }
コード例 #29
0
        public void Apply_On_Symmetric_Msf_4()
        {
            var var = new NumericVariable("Var", -5, 5);
            var msf = new MembershipFunction { { -5, 0 }, { -4, 1 }, { -3, 0 }, { -2, 1 }, { 2, 1 }, { 3, 0 }, { 4, 1 }, { 5, 0 } };

            var sut = new CoGDefuzzifyStrategy();

            const double expectedResult = 0;

            var result = sut.Apply(var, msf);

            Assert.AreEqual(expectedResult, result, 0.00000000001);
        }
コード例 #30
0
        public void Apply_On_Empty_Msf()
        {
            var var = new NumericVariable("Var", 0, 2);
            var msf = new MembershipFunction();

            var sut = new CoGDefuzzifyStrategy();

            const double expectedResult = 1d;

            var result = sut.Apply(var, msf);

            Assert.AreEqual(expectedResult, result, 0.00000000001);
        }
コード例 #31
0
        public void Apply_On_Symmetric_Msf_3()
        {
            var var = new NumericVariable("Var", 0, 4);
            var msf = new MembershipFunction { { 0, 0 }, { 1, 1 }, { 2, 0.5 }, { 3, 1 }, { 4, 0 } };

            var sut = new CoGDefuzzifyStrategy();

            const double expectedResult = 2;

            var result = sut.Apply(var, msf);

            Assert.AreEqual(expectedResult, result, 0.00000000001);
        }
コード例 #32
0
        public void Fuzzify_ReturnsMostAppropriateMembershipFunction_ContradictionCase()
        {
            // Arrange
            double             inputValue = 29;
            string             expectedMembershipFunctionName = "Cold";
            LinguisticVariable variable = PrepareLinguisticVariable();

            // Act
            MembershipFunction function = _fuzzyEngine.Fuzzify(variable, inputValue);

            // Assert
            Assert.AreEqual(expectedMembershipFunctionName, function.LinguisticVariableName);
        }
コード例 #33
0
        public void Apply_With_Triangle_3()
        {
            var msf = new MembershipFunction { { -7, 0 }, { -5, 1 }, { 0, 0 } };

            var sut = new MinMsfScalingStrategy();

            var result = sut.Apply(msf, 0.5);

            Assert.AreEqual(4, result.Count);
            Assert.AreEqual(0, msf.Apply(-7), 0.000000000001);
            Assert.AreEqual(0.5, msf.Apply(-6), 0.000000000001);
            Assert.AreEqual(0.5, msf.Apply(-2.5), 0.000000000001);
            Assert.AreEqual(0, msf.Apply(0), 0.000000000001);
        }
コード例 #34
0
        public void Apply_With_Inverse_Triangle()
        {
            var msf = new MembershipFunction{ { 0, 1 }, { 1, 0 }, { 2, 1 } };

            var sut = new ProdMsfScalingStrategy();

            var result = sut.Apply(msf, 0.5);

            Assert.AreEqual(3, result.Count);

            Assert.IsTrue(result.Contains(new KeyValuePair<double, double>(0, 0.5)));
            Assert.IsTrue(result.Contains(new KeyValuePair<double, double>(1, 0)));
            Assert.IsTrue(result.Contains(new KeyValuePair<double, double>(2, 0.5)));
        }
コード例 #35
0
        public void ApplyForComplex()
        {
            var sut = new MembershipFunction { { 0, 0.5 }, { 1, 0 }, { 2, 0.5 }, { 3, 0.5 }, { 5, 1 }, { 6, 0.5 } };

            Assert.AreEqual( 0.5, sut.Apply(-1));
            Assert.AreEqual( 0.5, sut.Apply(0));
            Assert.AreEqual(0.25, sut.Apply(1.5));
            Assert.AreEqual( 0.5, sut.Apply(2));
            Assert.AreEqual( 0.5, sut.Apply(3));
            Assert.AreEqual(0.75, sut.Apply(4));
            Assert.AreEqual(   1, sut.Apply(5));
            Assert.AreEqual( 0.5, sut.Apply(6));
            Assert.AreEqual( 0.5, sut.Apply(7));
        }
コード例 #36
0
        public void Apply_Unit_Test()
        {
            var numVar = new NumericVariable("Num Variable", 0, 42);
            var msf1 = new MembershipFunction { { 1, 0 } };
            var msf2 = new MembershipFunction { { 2, 0 } };
            var term1 = new FuzzyTerm("Term1", msf1);
            var term2 = new FuzzyTerm("Term2", msf2);
            const double value1 = 0.3;
            const int value2 = 06;

            var fuzzyVariable = new FuzzyVariable("Var", numVar, term1, term2);
            var fuzzyValue = new FuzzyValue(fuzzyVariable,
                new Dictionary<FuzzyTerm, double> {{term1, value1}, {term2, value2}});
            var scaledMsf1 = new MembershipFunction {{0, 0}};
            var scaledMsf2 = new MembershipFunction {{1, 1}};

            var mergedValue = new MembershipFunction {{2, 1}};

            const double expectedDefuzzifiedValue = 42;

            var mocks = new MockRepository();

            var scaleStrategy = mocks.StrictMock<IMsfScalingStrategy>();
            var mergeStrategy = mocks.StrictMock<IMsfMergingStrategy>();
            var defuzzifyStrategy = mocks.StrictMock<IDefuzzifyStrategy>();

            // 1. Scale the membership functions according to the fuzzy value
            Expect.Call(scaleStrategy.Apply(msf1, value1)).Return(scaledMsf1).Repeat.Once();
            Expect.Call(scaleStrategy.Apply(msf2, value2)).Return(scaledMsf2).Repeat.Once();

            // 2. Merge all membership functions into single one
            Expect.Call(mergeStrategy.Apply(new[] {scaledMsf1, scaledMsf2})).IgnoreArguments().Return(mergedValue).Repeat.Once();

            // 3. Create a defuzzified value for the result of the previous merge.
            Expect.Call(defuzzifyStrategy.Apply(numVar, mergedValue)).Return(expectedDefuzzifiedValue).Repeat.Once();
            
            mocks.ReplayAll();

            var sut = new Defuzzifier(scaleStrategy, mergeStrategy, defuzzifyStrategy);

            var result = sut.Apply(fuzzyValue);

            Assert.AreEqual(fuzzyVariable, result.Variable);
            Assert.AreEqual(mergedValue, result.MembershipFunction);
            Assert.AreEqual(expectedDefuzzifiedValue, result.Value);

            mocks.VerifyAll();
        }
コード例 #37
0
        void LoadRulesForTime()
        {
            var sure = new MembershipFunction("Süre", 0, 100);
            var sureFuzzyClusters = new List <FuzzyCluster>
            {
                new FuzzyCluster("Kısa", new Trapezoid(-46.5, -25.28, 22.3, 39.9), sure),
                new FuzzyCluster("Normal Kısa", new Triangle(22.3, 39.9, 57.5), sure),
                new FuzzyCluster("Orta", new Triangle(39.9, 57.5, 75.1), sure),
                new FuzzyCluster("Normal Uzun", new Triangle(57.5, 75.1, 92.7), sure),
                new FuzzyCluster("Uzun", new Trapezoid(75, 92.7, 111.6, 130), sure)
            };

            sure.FuzzyClusters.AddRange(sureFuzzyClusters);

            outputMembershipFunctions.Add(sure);
        }
コード例 #38
0
        void LoadRulesForDetergentAmount()
        {
            var detergentAmount = new MembershipFunction("Deterjan Miktarı", 0, 300);
            var detergentAmountFuzzyClusters = new List <FuzzyCluster>
            {
                new FuzzyCluster("Çok Az", new Trapezoid(0, 0, 20, 85), detergentAmount),
                new FuzzyCluster("Az", new Triangle(20, 85, 150), detergentAmount),
                new FuzzyCluster("Orta", new Triangle(85, 150, 215), detergentAmount),
                new FuzzyCluster("Fazla", new Triangle(150, 215, 280), detergentAmount),
                new FuzzyCluster("Çok Fazla", new Trapezoid(215, 280, 300, 300), detergentAmount)
            };

            detergentAmount.FuzzyClusters.AddRange(detergentAmountFuzzyClusters);

            outputMembershipFunctions.Add(detergentAmount);
        }
コード例 #39
0
        void LoadRulesForRotateSpeed()
        {
            var rotateSpeed = new MembershipFunction("Dönüş Hızı", 0, 10);
            var rotateSpeedFuzzyClusters = new List <FuzzyCluster>
            {
                new FuzzyCluster("Hassas", new Trapezoid(5.8, -2.8, 0.5, 1.5), rotateSpeed),
                new FuzzyCluster("Normal Hassas", new Triangle(0.5, 2.75, 5), rotateSpeed),
                new FuzzyCluster("Orta", new Triangle(2.75, 5, 7.25), rotateSpeed),
                new FuzzyCluster("Normal Güçlü", new Triangle(5, 7.25, 9.5), rotateSpeed),
                new FuzzyCluster("Güçlü", new Trapezoid(8.5, 9.5, 12.8, 15.2), rotateSpeed)
            };

            rotateSpeed.FuzzyClusters.AddRange(rotateSpeedFuzzyClusters);

            outputMembershipFunctions.Add(rotateSpeed);
        }
コード例 #40
0
        void LoadRulesForSensitive()
        {
            var hassaslik = new MembershipFunction("Hassaslık", 0, 10);
            var hassaslikFuzzyClusters = new List <FuzzyCluster>
            {
                new FuzzyCluster("Sağlam", new Trapezoid(-4, -1.5, 2, 4), hassaslik),
                new FuzzyCluster("Orta", new Triangle(3, 5, 7), hassaslik),
                new FuzzyCluster("Hassas", new Trapezoid(5.5, 8, 12.5, 14), hassaslik)
            };

            hassaslik.FuzzyClusters.AddRange(hassaslikFuzzyClusters);

            numHassaslik.Tag  = hassaslik;
            lblHassaslik.Text = hassaslik.GetFuzzyValueString();
            inputMembershipFunctions.Add(hassaslik);
        }
コード例 #41
0
        void LoadRulesForDirty()
        {
            var kirlilik = new MembershipFunction("Kirlilik", 0, 10);
            var kirlilikFuzzyClusters = new List <FuzzyCluster>
            {
                new FuzzyCluster("Küçük", new Trapezoid(-4.5, -2.5, 2, 4.5), kirlilik),
                new FuzzyCluster("Orta", new Triangle(3, 5, 7), kirlilik),
                new FuzzyCluster("Büyük", new Trapezoid(5.5, 8, 12.5, 15), kirlilik)
            };

            kirlilik.FuzzyClusters.AddRange(kirlilikFuzzyClusters);

            numKirlilik.Tag  = kirlilik;
            lblKirlilik.Text = kirlilik.GetFuzzyValueString();
            inputMembershipFunctions.Add(kirlilik);
        }
コード例 #42
0
        void LoadRulesForQuantity()
        {
            var miktar = new MembershipFunction("Miktar", 0, 10);
            var miktarFuzzyClusters = new List <FuzzyCluster>
            {
                new FuzzyCluster("Küçük", new Trapezoid(-4, -1.5, 2, 4), miktar),
                new FuzzyCluster("Orta", new Triangle(3, 5, 7), miktar),
                new FuzzyCluster("Büyük", new Trapezoid(5.5, 8, 12.5, 14), miktar)
            };

            miktar.FuzzyClusters.AddRange(miktarFuzzyClusters);

            numMiktar.Tag  = miktar;
            lblMiktar.Text = miktar.GetFuzzyValueString();
            inputMembershipFunctions.Add(miktar);
        }
コード例 #43
0
        private static MembershipFunction combine(MembershipFunction first, MembershipFunction second)
        {
            if (!first.Any())
                return second;
            if (!second.Any())
                return first;
            
            var scanPoints = getScanPoints(first, second);
            
            var result = new MembershipFunction();
            for (var i = 0; i < scanPoints.Count; i++)
            {
                var scanPoint = scanPoints[i];

                var valueFirst = first.Apply(scanPoint);
                var valueSecond = second.Apply(scanPoint);

                result.Add(scanPoint, Math.Max(valueFirst, valueSecond));
                
                // Check if there is an intersection between this scan point and the next
                // and add it to the list of scan points:
                var nextKeyFirst = getNextKey(first, scanPoint);
                var nextKeySecond = getNextKey(second, scanPoint);
                if (nextKeyFirst.HasValue && nextKeySecond.HasValue)
                {
                    var nextValueFirst = first[nextKeyFirst.Value];
                    var nextValueSecond = second[nextKeySecond.Value];

                    if (valueFirst >= valueSecond && nextValueFirst < nextValueSecond ||
                        valueFirst < valueSecond && nextValueFirst >= nextValueSecond)
                    {
                        var lineFirst = new LineSegment(new Point(scanPoint, valueFirst),
                            new Point(nextKeyFirst.Value, nextValueFirst));
                        var lineSecond = new LineSegment(new Point(scanPoint, valueSecond),
                            new Point(nextKeySecond.Value, nextValueSecond));

                        var intersection = lineFirst.Intersect(lineSecond);
                        if (intersection != null && !scanPoints.Contains(intersection.X) && intersection.X > scanPoint)
                            scanPoints.Insert(i + 1, intersection.X);
                    }
                }
            }

            return result.ClearUp();
        }
コード例 #44
0
        public MembershipFunction Apply(IList<MembershipFunction> membershipFunctions)
        {
            var result = new MembershipFunction();

            var msfs = membershipFunctions;

            while (msfs.Count > 1)
            {
                var combined = combine(msfs[0], msfs[1]);
                var newMsfs = new List<MembershipFunction> { combined };
                newMsfs.AddRange(msfs.Skip(2));
                msfs = newMsfs;
            }
            if (msfs.Any())
                return msfs[0];

            return result;
        }
コード例 #45
0
        public MembershipFunction Fuzzify(LinguisticVariable variable, double inputValue)
        {
            MembershipFunction function    = null;
            double             finalDegree = -1;

            foreach (var membershipFunction in variable.MembershipFunctionList)
            {
                var membershipDegree = membershipFunction.MembershipDegree(inputValue);
                if (membershipDegree < finalDegree)
                {
                    continue;
                }

                finalDegree = membershipDegree;
                function    = membershipFunction;
            }

            return(function);
        }
コード例 #46
0
 public void T6CompleteEncode()
 {
     TestMF = new MembershipFunction(
         LinguisticName, Expression);
     TestMF.Fuzzification(CrispVal);
     Assert.AreEqual(
         LinguisticName,
         TestMF.encodeCompleteJson().GetField("Name").str);
     Assert.AreEqual(
         Expression,
         TestMF.encodeCompleteJson().
         GetField("MembershipFunction").str);
     Assert.AreEqual(
         Eval.ReplaceNEvaluate(
             Expression, "@",
             CrispVal),
         TestMF.encodeCompleteJson().GetField("Fuzzy").f,
         0.01d);
 }
コード例 #47
0
        public BoilerSimulator(double SetPoint, double InitialPressure, int Samples, DefuzificationMethod Method)
        {
            this.SetPoint = SetPoint;
            this.Pressure = InitialPressure;
            this.Samples  = Samples;
            this.Method   = Method;

            controller = new Controller(MinX, MaxX, Samples, Method);  //use center of area fuzzy classification

            MembershipFunctionFactory factory = new MembershipFunctionFactory(MinX, MaxX, Samples);

            factory.MultiplyBy = 5;

            //membership functions to use in the controller
            MembershipFunction nb = factory.Create("nb", -1, -0.7, 0, 0.2);
            MembershipFunction nm = factory.Create("nm", -0.65, -0.35, 0.2, 0.2);
            MembershipFunction ns = factory.Create("ns", -0.3, 0, 0.2, 0);
            MembershipFunction nz = factory.Create("nz", -0.05, 0, 0.05, 0);
            MembershipFunction ze = factory.Create("ze", -0.05, 0.05, 0.05, 0.05);
            MembershipFunction pz = factory.Create("pz", 0, 0.05, 0, 0.05);
            MembershipFunction ps = factory.Create("ps", 0, 0.3, 0, 0.2);
            MembershipFunction pm = factory.Create("ps", 0.35, 0.65, 0.2, 0.2);
            MembershipFunction pb = factory.Create("pn", 0.7, 1, 0.2, 0);

            //need to double check these values
            controller.AddRule(new Rule("Rule 1", nb, ns + pb, pb));       //1
            controller.AddRule(new Rule("Rule 2", nb + nm, ns, pm));       //2
            controller.AddRule(new Rule("Rule 3", ns, nz + ps, pm));       //3
            controller.AddRule(new Rule("Rule 4", nz, pm + pb, pm));       //4
            controller.AddRule(new Rule("Rule 5", nz, nb + nm, nm));       //5
            controller.AddRule(new Rule("Rule 6", nz + pz, nz, nz));       //6
            controller.AddRule(new Rule("Rule 7", pz, nb + nm, pm));       //7
            controller.AddRule(new Rule("Rule 8", pz, pm + pb, nm));       //8
            controller.AddRule(new Rule("Rule 9", ps, nz + ps, nm));       //9
            controller.AddRule(new Rule("Rule 10", pm + pb, ns, nm));      //10
            controller.AddRule(new Rule("Rule 11", pb, ns + pb, nb));      //11
            controller.AddRule(new Rule("Rule 12", nz, ps, ps));           //12
            controller.AddRule(new Rule("Rule 13", nz, ns, ns));           //13
            controller.AddRule(new Rule("Rule 14", pz, ns, ps));           //14
            controller.AddRule(new Rule("Rule 15", pz, ps, ns));           //15
            //controller.AddRule(new Rule( "Rule 16", nb + nm, nb + nm, pb));  //16
            controller.AddRule(new Rule("Rule 17", pm + pb, nb + nm, nb)); //17
        }
コード例 #48
0
        public ClassicMembershipFunction(string sign, double threshold)
        {
            mThreshold = threshold;

            switch (sign)
            {
            case ">":
            case "g":
                mMembershipFunction = new MembershipFunction(gt);
                break;

            case ">=":
            case "ge":
                mMembershipFunction = new MembershipFunction(ge);
                break;

            case "<":
            case "l":
                mMembershipFunction = new MembershipFunction(lt);
                break;

            case "<=":
            case "le":
                mMembershipFunction = new MembershipFunction(le);
                break;

            case "==":
            case "eq":
                mMembershipFunction = new MembershipFunction(eq);
                break;

            case "!=":
            case "nq":
                mMembershipFunction = new MembershipFunction(ne);
                break;
            }
        }
コード例 #49
0
        public void Merge_9()
        {
            var msf1 = new MembershipFunction { { -1, 1 }, { 0, 0 }};
            var msf2 = new MembershipFunction { { -1, 0 }, { -0.75, 0.25 }, { 0.75, 0.25 }, { 1, 0 } };

            var expected = new MembershipFunction { { -1, 1 }, { -0.25, 0.25 }, { 0.75, 0.25 }, { 1, 0 } };

            var sut = new MaxMsfMergingStrategy();
            var result = sut.Apply(new[] { msf1, msf2 });
            Assert.AreEqual(expected, result);
            result = sut.Apply(new[] { msf2, msf1 });
            Assert.AreEqual(expected, result);
        }
コード例 #50
0
 public double CalculateMembership(double value)
 {
     return(MembershipFunction.GetMembershipDegree(value));
 }
コード例 #51
0
 public FuzzySet(FuzzyContext.Variable variable, string name, MembershipFunction membershipFunction)
 {
     this.variable           = variable;
     this.name               = name;
     this.membershipFunction = membershipFunction;
 }
コード例 #52
0
 public FuzzyClass(string name, float l, float c, float r)
 {
     className          = name;
     membershipFunction = new MembershipFunction(l, c, r);
     action             = c;
 }
コード例 #53
0
        public void setup()
        {
            //TextAsset MembershipFunctTextAsset =
            //    Resources.Load("MembershipFunctions") as TextAsset;
            LinguisticVariable = new LinguisticVariable();
            MFs = new List <MembershipFunction>();
            LRs = new List <LinguisticRule>();
            MFs.Add(MembershipFunction.Generate("EasyFight", "Triangle", new double[] { -1, 3, 5 }, 5));
            MFs.Add(MembershipFunction.Generate("NormalFight", "Trapezoid", new double[] { 4, 5, 9, 11 }, 9));
            MFs.Add(MembershipFunction.Generate("HardFight", "Triangle", new double[] { 10, 15, 17 }, 15));
            LRs.Add(new LinguisticRule(
                        "HardFight",
                        "Health High and Power High",
                        FuzzyImplication.Lukasiewicz,
                        FuzzyOperator.Probabilistic));
            LRs.Add(new LinguisticRule(
                        "NormalFight",
                        "Health Low and Power Medium",
                        FuzzyImplication.KleeneDienes,
                        FuzzyOperator.Probabilistic));
            LRs.Add(new LinguisticRule(
                        "EasyFight",
                        "Health Medium and Power Low",
                        FuzzyImplication.Larson,
                        FuzzyOperator.MinMax));
            JsonLingVar =
                @"
{
    ""Version"" : """ + Version + @""",
    ""LinguisticVariable"" : """ + Name + @""",
    ""Type"" : """ + Type + @""",
    ""MinimumValue"" : " + minVal + @",
    ""RangeLength"" : " + RangeLen + @",
    ""LinguisticValues"" : 
    [
    ";
            foreach (MembershipFunction MF in MFs)
            {
                JsonLingVar += MF.encodeLinguisticJson().Print(true);
                if (!MF.Equals(MFs[MFs.Count - 1]))
                {
                    JsonLingVar += ",";
                }
            }
            JsonLingVar +=
                @"
    ],
    ""LinguisticRule"" : 
    [";
            foreach (LinguisticRule LR in LRs)
            {
                JsonLingVar += LR.encodeLinguisticJson().Print(true);
                if (!LR.Equals(LRs[LRs.Count - 1]))
                {
                    JsonLingVar += ",";
                }
            }
            JsonLingVar +=
                @"]
}
";
        }
コード例 #54
0
 public FunctionControl(MembershipFunction function)
 {
     InitializeComponent();
     SetValues(function);
 }
コード例 #55
0
        private FuzzySystem GetModifiedFuzzySystem(ArrayList ActualParameters)
        {
            // Clone fuzzysystem
            FuzzySystem tempFuz = (FuzzySystem)Activator.CreateInstance(fuzzySystem.GetType());

            tempFuz.CopyDataFrom(fuzzySystem);

            /*FuzzySystem tempFuz = null;
             * switch (fuzzySystem.Type)
             * {
             *  case FuzzyType.Mamdani:
             *      tempFuz = new MamdaniFS();
             *      break;
             *  case FuzzyType.Larsen:
             *      tempFuz = new LarsenFS();
             *      break;
             *  case FuzzyType.Sugeno:
             *      tempFuz = new SugenoFS();
             *      break;
             *  case FuzzyType.Sparse:
             *  default:
             *      throw new NotImplementedException();
             *      break;
             * }*/

            // Read settings
            bool In  = false;
            bool Out = false;
            bool RP  = false;

            Dispatcher.Invoke(() =>
            {
                In  = CheckInput.IsChecked == true;
                Out = CheckOutput.IsChecked == true;
                RP  = RadioRefPoint.IsChecked == true;
            });

            // Store the number of MFs handled by the optimization
            int finishedMfCount = 0;

            if (In)
            {
                for (int inputId = 0; inputId < tempFuz.Inputs.Length; inputId++)
                {
                    for (int mfId = 0; mfId < tempFuz.Inputs[inputId].MFs.Length; mfId++)
                    {
                        if (RP)
                        {
                            tempFuz.Inputs[inputId].MFs[mfId] = tempFuz.Inputs[inputId].MFs[mfId].GetAtRefPoint(
                                (float)((double)ActualParameters[finishedMfCount + mfId]));
                        }
                        else
                        {
                            tempFuz.Inputs[inputId].MFs[mfId] = MembershipFunction.CreateTrapezoid(
                                tempFuz.Inputs[inputId].MFs[mfId].GetTrapReferencePoint(),
                                tempFuz.Inputs[inputId].MFs[mfId].GetTrapBottomBase(),
                                tempFuz.Inputs[inputId].MFs[mfId].GetTrapBottomBase() * (float)((double)ActualParameters[finishedMfCount + mfId]));
                        }
                    }
                    finishedMfCount += tempFuz.Inputs[inputId].NumMFs;
                }
            }
            if (Out)
            {
                for (int outputId = 0; outputId < tempFuz.Outputs.Length; outputId++)
                {
                    for (int mfId = 0; mfId < tempFuz.Outputs[outputId].MFs.Length; mfId++)
                    {
                        if (RP)
                        {
                            tempFuz.Outputs[outputId].MFs[mfId] = tempFuz.Outputs[outputId].MFs[mfId].GetAtRefPoint(
                                (float)((double)ActualParameters[finishedMfCount + mfId]));
                        }
                        else
                        {
                            tempFuz.Outputs[outputId].MFs[mfId] = MembershipFunction.CreateTrapezoid(
                                tempFuz.Outputs[outputId].MFs[mfId].GetTrapReferencePoint(),
                                tempFuz.Outputs[outputId].MFs[mfId].GetTrapBottomBase(),
                                tempFuz.Outputs[outputId].MFs[mfId].GetTrapBottomBase() * (float)((double)ActualParameters[finishedMfCount + mfId]));
                        }
                    }
                    finishedMfCount += tempFuz.Outputs[outputId].NumMFs;
                }
            }

            return(tempFuz);
        }
コード例 #56
0
ファイル: FuzzySet.cs プロジェクト: jurczewski/KSR
 public virtual double Cardinality()
 {
     return(MembershipFunction.Cardinality());
 }
コード例 #57
0
        public void EqualTest()
        {
            var obj1 = new MembershipFunction { { 1, 0 }, { 3, 1 }, { 5, 0 } };
            var obj2 = new MembershipFunction { { 1, 0 }, { 2, 1 }};

            var sut = new MembershipFunction { { 1, 0 }, { 3, 1 }, { 5, 0 } };

            Assert.IsFalse(sut.Equals(null as object));
            Assert.IsTrue(sut.Equals(sut as object));
            Assert.IsTrue(sut.Equals(obj1 as object));
            Assert.IsFalse(sut.Equals(obj2));
        }
コード例 #58
0
        public void ToStringTest()
        {
            var sut = new MembershipFunction { { 1, 0 }, { 3, 1 }, { 5, 0 } };

            Assert.AreEqual("{ (1;0) | (3;1) | (5;0) }", sut.ToString());
        }
コード例 #59
0
ファイル: FuzzySet.cs プロジェクト: jurczewski/KSR
 public virtual double GetMembership(Player entry)
 {
     return(MembershipFunction.GetMembership(FieldExtractor(entry)));
 }
コード例 #60
0
 private List <Point> BuildGraph(MembershipFunction mf)
 {
     return(BuildGraph(mf.values));
 }