public void GetCartesianProductLarsenProductTest()
        {
            var setA = new FuzzySet();
            var list = new List<IFuzzyElement>
                           {
                               new FuzzyElement { X = -1, Value = 0.33 },
                               new FuzzyElement { X = 0, Value = 0.67 },
                               new FuzzyElement { X = 1, Value = 1.0 },
                               new FuzzyElement { X = 2, Value = 0.75 },
                               new FuzzyElement { X = 3, Value = 0.5 },
                               new FuzzyElement { X = 4, Value = 0.25 }
                           };
            setA.AddElements(list);

            var setB = new FuzzySet();
            list = new List<IFuzzyElement>
                           {
                               new FuzzyElement { X = -4, Value = 0.5 },
                               new FuzzyElement { X = -3, Value = 1.0 },
                               new FuzzyElement { X = -2, Value = 0.67 },
                               new FuzzyElement { X = -1, Value = 0.33 }
                           };
            setB.AddElements(list);

            var result = Relations.GetCartesianProduct(setA, setB, Implications.LarsenProductImplication, () => new FuzzyRow());

            Assert.AreEqual(result.ElementAt(0).ElementAt(0).Value, (new FuzzyElement { X = 2, Value = 0.165 }).Value);
            Assert.AreEqual(result.ElementAt(0).ElementAt(1).Value, (new FuzzyElement { X = 2, Value = 0.33 }).Value);
            Assert.AreEqual(result.ElementAt(0).ElementAt(2).Value.Round(4), (new FuzzyElement { X = 2, Value = 0.2211 }).Value);
            Assert.AreEqual(result.ElementAt(0).ElementAt(3).Value.Round(4), (new FuzzyElement { X = 2, Value = 0.1089 }).Value);
            Assert.AreEqual(result.ElementAt(1).ElementAt(0).Value, (new FuzzyElement { X = 2, Value = 0.335 }).Value);
            Assert.AreEqual(result.ElementAt(1).ElementAt(1).Value, (new FuzzyElement { X = 2, Value = 0.67 }).Value);
            Assert.AreEqual(result.ElementAt(1).ElementAt(2).Value.Round(4), (new FuzzyElement { X = 2, Value = 0.4489 }).Value);
            Assert.AreEqual(result.ElementAt(1).ElementAt(3).Value.Round(4), (new FuzzyElement { X = 2, Value = 0.2211 }).Value);
        }
        public void TestMethod1()
        {
            var setA = new FuzzySet();
            var listA = new List<IFuzzyElement>
                           {
                               new FuzzyElement { X = 6, Value = 0.30 },
                               new FuzzyElement { X = 7, Value = 0.60 },
                               new FuzzyElement { X = 8, Value = 1 }
                           };
            setA.AddElements(listA);

            var setB = new FuzzySet();
            var listB = new List<IFuzzyElement>
                           {
                               new FuzzyElement { X = 5, Value = 1 },
                               new FuzzyElement { X = 6, Value = 0.60 },
                               new FuzzyElement { X = 7, Value = 0.20 }
                           };
            setB.AddElements(listB);

            var list = new List<IFuzzySet> { setA, setB };

            var defuzzifier = new CenterOfSumDefuzzifier(Functions.Union);

            var result = defuzzifier.Defuzzifier(list).Round(3);

            Assert.AreEqual(result, 6.486);
        }
        public void RemoveFuzzyValueTestFailNameNotExists()
        {
            var values = new FuzzyValues();

            var inseted = new FuzzySet();
            values.AddFuzzyValue("medium", inseted);
            values.RemoveFuzzyValue("Medium");
        }
        public void CalculateMembershipDegreeTest()
        {
            var set = new FuzzySet();
            set.RegisterMembershipFunction(Function);

            var value = set.CalculateMembershipDegree(10);

            Assert.AreEqual(value, 0.038461538461538464);
        }
        public void RemoveFuzzyValueTestFailGetRemovedItem()
        {
            var values = new FuzzyValues();

            var inseted = new FuzzySet();
            values.AddFuzzyValue("medium", inseted);
            values.RemoveFuzzyValue("medium");
            values.GetFuzzyValue("medium");
        }
        public void GetFuzzyValueTestFailNameNotExists()
        {
            var values = new FuzzyValues();

            var inseted = new FuzzySet();
            values.AddFuzzyValue("medium", inseted);

            var result = values.GetFuzzyValue("Medium");

            Assert.AreEqual(inseted, result);
        }
        public void AddAndGetFuzzyValueTest()
        {
            var values = new FuzzyValues();

            var inseted = new FuzzySet();
            values.AddFuzzyValue("medium", inseted);

            var result = values.GetFuzzyValue("medium");

            Assert.AreEqual(inseted, result);
        }
        public void ToStringTest()
        {
            var set = new FuzzySet();
            set.RegisterMembershipFunction(new Func<double, double>(x => x));
            double[] values = { 6, 7, 8, 9, 10 };
            set.AddRange(values);

            var expected = "1/6, 1/7, 1/8, 1/9, 1/10";
            var result = set.ToString();

            Assert.AreEqual(expected, result);
        }
        public void AddRangeTest()
        {
            var set = new FuzzySet();
            set.RegisterMembershipFunction(Function);

            double[] values = { 6, 7, 8, 9, 10, 1, 2, 3, 4, 5 };
            set.AddRange(values);

            Assert.AreEqual(set.Elements.Count, values.Length);

            var cursor = set.Elements.GetEnumerator();
            double i = 1;
            while (cursor.MoveNext())
            {
                Assert.AreEqual(cursor.Current.Value.X, i);
                i += 1;
            }
        }
        public void GetCartesianProductMamdaniMinTest()
        {
            var setA = new FuzzySet();
            var list = new List<IFuzzyElement>
                           {
                               new FuzzyElement { X = 2, Value = 0.5 },
                               new FuzzyElement { X = 3, Value = 1.0 },
                               new FuzzyElement { X = 4, Value = 0.5 }
                           };
            setA.AddElements(list);

            var setB = new FuzzySet();
            list = new List<IFuzzyElement>
                           {
                               new FuzzyElement { X = 5, Value = 0.33 },
                               new FuzzyElement { X = 6, Value = 0.67 },
                               new FuzzyElement { X = 7, Value = 1.0 },
                               new FuzzyElement { X = 8, Value = 0.67 },
                               new FuzzyElement { X = 9, Value = 0.33 }
                           };
            setB.AddElements(list);

            var result = Relations.GetCartesianProduct(setA, setB, Implications.MamdaniMinImplication, () => new FuzzyRow());

            Assert.AreEqual(result.ElementAt(0).ElementAt(0).Value, (new FuzzyElement { X = 2, Value = 0.33 }).Value);
            Assert.AreEqual(result.ElementAt(0).ElementAt(1).Value, (new FuzzyElement { X = 2, Value = 0.5 }).Value);
            Assert.AreEqual(result.ElementAt(0).ElementAt(2).Value, (new FuzzyElement { X = 2, Value = 0.5 }).Value);
            Assert.AreEqual(result.ElementAt(0).ElementAt(3).Value, (new FuzzyElement { X = 2, Value = 0.5 }).Value);
            Assert.AreEqual(result.ElementAt(0).ElementAt(4).Value, (new FuzzyElement { X = 2, Value = 0.33 }).Value);
            Assert.AreEqual(result.ElementAt(1).ElementAt(0).Value, (new FuzzyElement { X = 2, Value = 0.33 }).Value);
            Assert.AreEqual(result.ElementAt(1).ElementAt(1).Value, (new FuzzyElement { X = 2, Value = 0.67 }).Value);
            Assert.AreEqual(result.ElementAt(1).ElementAt(2).Value, (new FuzzyElement { X = 2, Value = 1.0 }).Value);
            Assert.AreEqual(result.ElementAt(1).ElementAt(3).Value, (new FuzzyElement { X = 2, Value = 0.67 }).Value);
            Assert.AreEqual(result.ElementAt(2).ElementAt(4).Value, (new FuzzyElement { X = 2, Value = 0.33 }).Value);
            Assert.AreEqual(result.ElementAt(2).ElementAt(0).Value, (new FuzzyElement { X = 2, Value = 0.33 }).Value);
            Assert.AreEqual(result.ElementAt(2).ElementAt(1).Value, (new FuzzyElement { X = 2, Value = 0.5 }).Value);
            Assert.AreEqual(result.ElementAt(2).ElementAt(2).Value, (new FuzzyElement { X = 2, Value = 0.5 }).Value);
            Assert.AreEqual(result.ElementAt(2).ElementAt(3).Value, (new FuzzyElement { X = 2, Value = 0.5 }).Value);
            Assert.AreEqual(result.ElementAt(2).ElementAt(4).Value, (new FuzzyElement { X = 2, Value = 0.33 }).Value);
        }
Exemple #11
0
        /// <summary>
        /// CreateFuzzySetDeltaError
        /// </summary>
        private void CreateFuzzySetForce()
        {
            //armazena os FuzzySets e seu valor linguistico
            var values = this.FuzzyValues;

            // Valores para delta erro (angulo do pendulo)
            var set = new FuzzySet();
            set.RegisterMembershipFunction(
                x => TipicalMembershipFunction.TriangularMembershipFunction(-110, -70.0, -30.0, x));
            set.AddRange((-70.0).GetRoundedRange(-30.0, Step, RoundDigits));
            this.FuzzySetForce.Add(set);
            values.AddFuzzyValue("FMN", set);

            set = new FuzzySet();
            set.RegisterMembershipFunction(
                x => TipicalMembershipFunction.TriangularMembershipFunction(-60.0, -30.0, 0.0, x));
            set.AddRange((-60.0).GetRoundedRange(0.0, Step, RoundDigits));
            this.FuzzySetForce.Add(set);
            values.AddFuzzyValue("FN", set);

            set = new FuzzySet();
            set.RegisterMembershipFunction(
                x => TipicalMembershipFunction.TriangularMembershipFunction(-15, 0, 15, x));
            set.AddRange((-15.0).GetRoundedRange(15.0, Step, RoundDigits));
            this.FuzzySetForce.Add(set);
            values.AddFuzzyValue("FZ", set);

            set = new FuzzySet();
            set.RegisterMembershipFunction(
                x => TipicalMembershipFunction.TriangularMembershipFunction(0, 30, 60, x));
            set.AddRange(0d.GetRoundedRange(60, Step, RoundDigits));
            this.FuzzySetForce.Add(set);
            values.AddFuzzyValue("FP", set);

            set = new FuzzySet();
            set.RegisterMembershipFunction(
                x => TipicalMembershipFunction.TriangularMembershipFunction(30, 70, 110, x));
            set.AddRange(30d.GetRoundedRange(70, Step, RoundDigits));
            this.FuzzySetForce.Add(set);
            values.AddFuzzyValue("FMP", set);
        }
Exemple #12
0
        /// <summary>
        /// CreateFuzzySetError
        /// </summary>
        private void CreateFuzzySetError()
        {
            //armazena os FuzzySets e seu valor linguistico
            var values = this.FuzzyValues;

            // Valores para erro (angulo do pendulo)
            var set = new FuzzySet();
            set.RegisterMembershipFunction(
                x => TipicalMembershipFunction.TriangularMembershipFunction(-6.30, -3.15, 0, x));
            set.AddRange((-3.15).GetRoundedRange(0, Step, RoundDigits));
            this.FuzzySetError.Add(set);
            values.AddFuzzyValue("EN", set);

            set = new FuzzySet();
            set.RegisterMembershipFunction(
                x => TipicalMembershipFunction.TriangularMembershipFunction(-0.50, 0, 0.50, x));
            set.AddRange((-0.50).GetRoundedRange(0.50, Step, RoundDigits));
            this.FuzzySetError.Add(set);
            values.AddFuzzyValue("EZ", set);

            set = new FuzzySet();
            set.RegisterMembershipFunction(
                x => TipicalMembershipFunction.TriangularMembershipFunction(0, 3.15, 6.30, x));
            set.AddRange(0d.GetRoundedRange(3.15, Step, RoundDigits));
            this.FuzzySetError.Add(set);
            values.AddFuzzyValue("EP", set);
        }
Exemple #13
0
        /// <summary>
        /// CreateFuzzySetDeltaError
        /// </summary>
        private void CreateFuzzySetDeltaError()
        {
            //armazena os FuzzySets e seu valor linguistico
            var values = this.FuzzyValues;

            // Valores para delta erro (angulo do pendulo)
            var set = new FuzzySet();
            set.RegisterMembershipFunction(
                x => TipicalMembershipFunction.TriangularMembershipFunction(-4.30, -3.15, -2.0, x));
            set.AddRange((-3.15).GetRoundedRange(-2.0, Step, RoundDigits));
            this.FuzzySetDeltaError.Add(set);
            values.AddFuzzyValue("DMN", set);

            set = new FuzzySet();
            set.RegisterMembershipFunction(
                x => TipicalMembershipFunction.TriangularMembershipFunction(-2.5, -1.25, 0, x));
            set.AddRange((-2.5).GetRoundedRange(0, Step, RoundDigits));
            this.FuzzySetDeltaError.Add(set);
            values.AddFuzzyValue("DN", set);

            set = new FuzzySet();
            set.RegisterMembershipFunction(
                x => TipicalMembershipFunction.TriangularMembershipFunction(-0.5, 0, 0.5, x));
            set.AddRange((-0.5).GetRoundedRange(0.5, Step, RoundDigits));
            this.FuzzySetDeltaError.Add(set);
            values.AddFuzzyValue("DZ", set);

            set = new FuzzySet();
            set.RegisterMembershipFunction(
                x => TipicalMembershipFunction.TriangularMembershipFunction(0.0, 1.25, 2.5, x));
            set.AddRange(0.0.GetRoundedRange(2.5, Step, RoundDigits));
            this.FuzzySetDeltaError.Add(set);
            values.AddFuzzyValue("DP", set);

            set = new FuzzySet();
            set.RegisterMembershipFunction(
                x => TipicalMembershipFunction.TriangularMembershipFunction(2.0, 3.15, 4.30, x));
            set.AddRange(2.0.GetRoundedRange(3.15, Step, RoundDigits));
            this.FuzzySetDeltaError.Add(set);
            values.AddFuzzyValue("DMP", set);

            //var set = new FuzzySet();
            //set.RegisterMembershipFunction(
            //    x => TipicalMembershipFunction.TriangularMembershipFunction(-6.30, -3.15, -0.30, x));
            //set.AddRange((-3.15).GetRoundedRange(-0.30, Step, RoundDigits));
            //this.FuzzySetDeltaError.Add(set);
            //values.AddFuzzyValue("DN", set);

            //set = new FuzzySet();
            //set.RegisterMembershipFunction(
            //    x => TipicalMembershipFunction.TriangularMembershipFunction(-0.30, 0, 0.30, x));
            //set.AddRange((-0.30).GetRoundedRange(0.30, Step, RoundDigits));
            //this.FuzzySetDeltaError.Add(set);
            //values.AddFuzzyValue("DZ", set);

            //set = new FuzzySet();
            //set.RegisterMembershipFunction(
            //    x => TipicalMembershipFunction.TriangularMembershipFunction(0.30, 3.15, 6.30, x));
            //set.AddRange(0.30.GetRoundedRange(3.15, Step, RoundDigits));
            //this.FuzzySetDeltaError.Add(set);
            //values.AddFuzzyValue("DP", set);
        }
        public void IntersectionTest()
        {
            var setA = new FuzzySet();
            var listA = new List<IFuzzyElement>
                           {
                               new FuzzyElement { X = 6, Value = 0.33 },
                               new FuzzyElement { X = 7, Value = 0.67 },
                               new FuzzyElement { X = 8, Value = 1 },
                               new FuzzyElement { X = 9, Value = 0.67 },
                               new FuzzyElement { X = 10, Value = 0.33 }
                           };
            setA.AddElements(listA);

            var setB = new FuzzySet();
            var listB = new List<IFuzzyElement>
                           {
                               new FuzzyElement { X = 3, Value = 0.20 },
                               new FuzzyElement { X = 4, Value = 0.60 },
                               new FuzzyElement { X = 5, Value = 1 },
                               new FuzzyElement { X = 6, Value = 0.60 },
                               new FuzzyElement { X = 7, Value = 0.20 }
                           };
            setB.AddElements(listB);

            var result = setA.Intersection(setB);

            Assert.AreEqual(result.Elements.Count, 2);
            Assert.AreEqual(result.Elements[6.0].Value, 0.33);
            Assert.AreEqual(result.Elements[7.0].Value, 0.2);
        }
        public void UnionTest()
        {
            var setA = new FuzzySet();
            var listA = new List<IFuzzyElement>
                           {
                               new FuzzyElement { X = 6, Value = 0.33 },
                               new FuzzyElement { X = 7, Value = 0.67 },
                               new FuzzyElement { X = 8, Value = 1 },
                               new FuzzyElement { X = 9, Value = 0.67 },
                               new FuzzyElement { X = 10, Value = 0.33 }
                           };
            setA.AddElements(listA);

            var setB = new FuzzySet();
            var listB = new List<IFuzzyElement>
                           {
                               new FuzzyElement { X = 3, Value = 0.20 },
                               new FuzzyElement { X = 4, Value = 0.60 },
                               new FuzzyElement { X = 5, Value = 1 },
                               new FuzzyElement { X = 6, Value = 0.60 },
                               new FuzzyElement { X = 7, Value = 0.20 }
                           };
            setB.AddElements(listB);

            var result = setA.Union(setB);

            Assert.AreEqual(result.Elements.Count, 8);
            Assert.AreEqual(result.Elements[3.0].Value, 0.2);
            Assert.AreEqual(result.Elements[4.0].Value, 0.6);
            Assert.AreEqual(result.Elements[5.0].Value, 1.0);
            Assert.AreEqual(result.Elements[6.0].Value, 0.6);
            Assert.AreEqual(result.Elements[7.0].Value, 0.67);
            Assert.AreEqual(result.Elements[8.0].Value, 1.0);
            Assert.AreEqual(result.Elements[9.0].Value, 0.67);
            Assert.AreEqual(result.Elements[10.0].Value, 0.33);
        }