Ejemplo n.º 1
0
        static void Primjer13()
        {
            IDomain   d    = Domain.IntRange(0, 11);
            IFuzzySet set1 = new MutableFuzzySet(d)
                             .Set(DomainElement.Of(0), 1.0)
                             .Set(DomainElement.Of(1), 0.8)
                             .Set(DomainElement.Of(2), 0.6)
                             .Set(DomainElement.Of(3), 0.4)
                             .Set(DomainElement.Of(4), 0.2);

            Debug1.Print(set1, "Set1:");

            IFuzzySet notSet1 = Operations.Operations.UnaryOperation(
                set1, Operations.Operations.ZadehNot());

            Debug1.Print(notSet1, "notSet1:");



            IFuzzySet union = Operations.Operations.BinaryOperation(
                set1, notSet1, Operations.Operations.ZadehOr());

            Debug1.Print(union, "Set1 union notSet1:");

            IFuzzySet hinters = Operations.Operations.BinaryOperation(
                set1, notSet1, Operations.Operations.HamacherTNorm(1.0));

            Debug1.Print(hinters, "Set1 intersection with notSet1 using parameterised Hamacher T norm with parameter 1.0:");

            IFuzzySet presjek = Operations.Operations.BinaryOperation(set1, notSet1, Operations.Operations.ZadehAnd());

            Debug1.Print(presjek, "Set1 presjek notSet1:");
        }
Ejemplo n.º 2
0
        public static void Test33()
        {
            double[] antecMembershipFunctions = new double[] {
                0.8, 0.8, 0.7, 1, 0.7, 0.9
            };

            double minMembershipFunc = antecMembershipFunctions.Min();

            IDomain u = Domain.IntRange(-5, 6);

            IFuzzySet _conseq = new CalculatedFuzzySet(
                u,
                StandardFuzzySets.LambdaFunction(
                    u.IndexOfElement(DomainElement.Of(-5)),
                    u.IndexOfElement(DomainElement.Of(-3)),
                    u.IndexOfElement(DomainElement.Of(0))
                    )
                );

            Debug1.Print(_conseq, "Konsekv1:");


            IFuzzySet antecedents = new CalculatedFuzzySet(                                     //mjere pripadnosti su na minimumu mj.pripadnosti antecedenata
                _conseq.GetDomain(),
                StandardFuzzySets.UniversalFunction(minMembershipFunc)
                );

            IFuzzySet conclusion = Operations.Operations.BinaryOperation(antecedents, _conseq, Operations.Operations.ZadehAnd());

            Debug1.Print(conclusion, "Zakljucak1:");
        }
Ejemplo n.º 3
0
        public static bool IsMaxMinTransitive(IFuzzySet relation)
        {
            IFuzzySet copiedRelation = DeepCopy(relation);              //jer ugnjezdjeni foreach nad istom 'relation' instancom stvara probleme

            foreach (DomainElement element1 in relation.GetDomain())
            {
                int    x      = element1.GetComponentValue(0);
                int    z      = element1.GetComponentValue(1);
                double funcxz = relation.GetValueAt(DomainElement.Of(x, z));
                double Max    = 0;
                foreach (DomainElement element2 in copiedRelation.GetDomain())
                {
                    if (element2.GetComponentValue(0) == element2.GetComponentValue(1))
                    {
                        int y = element2.GetComponentValue(0);
                        if (Math.Min(copiedRelation.GetValueAt(DomainElement.Of(x, y)), copiedRelation.GetValueAt(DomainElement.Of(y, z))) > Max)
                        {
                            Max = Math.Min(copiedRelation.GetValueAt(DomainElement.Of(x, y)), copiedRelation.GetValueAt(DomainElement.Of(y, z)));
                        }
                    }
                }
                if (funcxz < Max)
                {
                    return(false);
                }
            }
            return(true);
        }
        public IFuzzySet SingleRuleConclusionProduct(int L, int D, int LK, int DK, int V, int S)       //TODO napravi varijantu i za StrojMinimum i za StrojProdukt
        {
            double[] antecMembershipFunctions = new double[] {
                _antec1.GetValueAt(DomainElement.Of(L)),
                _antec2.GetValueAt(DomainElement.Of(D)),
                _antec3.GetValueAt(DomainElement.Of(LK)),
                _antec4.GetValueAt(DomainElement.Of(DK)),
                _antec5.GetValueAt(DomainElement.Of(V)),
                _antec6.GetValueAt(DomainElement.Of(S))
            };

            double prodMembershipFunc = 1;

            foreach (double var in antecMembershipFunctions)
            {
                prodMembershipFunc *= var;
            }

            IFuzzySet antecedents = new CalculatedFuzzySet(                                     //mjere pripadnosti su na minimumu mj.pripadnosti antecedenata
                _conseq.GetDomain(),
                StandardFuzzySets.UniversalFunction(prodMembershipFunc)
                );


            //KormiloFuzzySystemMin.Print(antecedents, "antecedents:");
            //KormiloFuzzySystemMin.Print(_conseq, "_conseq:");
            //KormiloFuzzySystemMin.Print(_antec5, "_antec:");


            IFuzzySet conclusion = Operations.Operations.BinaryOperation(antecedents, _conseq, Operations.Operations.AlgProduct());

            //KormiloFuzzySystemMin.Print(conclusion, "conclusion:");

            return(conclusion);
        }
Ejemplo n.º 5
0
        public static IFuzzySet CompositionOfBinaryRelations(IFuzzySet relation1, IFuzzySet relation2, IBinaryFunction tNorm, IBinaryFunction sNorm)    //zadatak ne specificira koristi li se max-min kompozicija
        {                                                                                                                                               //stoga je konfigurabilno
            MutableFuzzySet compositeRelation = new MutableFuzzySet(Domain.Combine(relation1.GetDomain().GetComponent(0), relation2.GetDomain().GetComponent(1)));

            if (relation1 == relation2)             //jer ugnjezdjeni foreach nad istom 'relation' instancom stvara probleme
            {
                relation2 = DeepCopy(relation1);
            }

            foreach (DomainElement element1 in compositeRelation.GetDomain())
            {
                int    x        = element1.GetComponentValue(0);
                int    z        = element1.GetComponentValue(1);
                double funccomp = compositeRelation.GetValueAt(DomainElement.Of(x, z));
                double Max      = 0;

                foreach (DomainElement element_a in relation1.GetDomain())          //funca
                {
                    foreach (DomainElement element_b in relation2.GetDomain())      //funcb
                    {
                        if (element_a.GetComponentValue(1) == element_b.GetComponentValue(0))
                        {
                            int y = element_a.GetComponentValue(1);                 //y
                            Max = sNorm.ValueAt(tNorm.ValueAt(relation1.GetValueAt(DomainElement.Of(x, y)), relation2.GetValueAt(DomainElement.Of(y, z))), Max);
                        }
                    }
                }

                compositeRelation.Set(DomainElement.Of(x, z), Max);
            }

            return(compositeRelation);
        }
Ejemplo n.º 6
0
        public static void Primjer23()
        {
            IDomain   u = Domain.IntRange(1, 5); // {1,2,3,4}
            IFuzzySet r = new MutableFuzzySet(Domain.Combine(u, u))
                          .Set(DomainElement.Of(1, 1), 1)
                          .Set(DomainElement.Of(2, 2), 1)
                          .Set(DomainElement.Of(3, 3), 1)
                          .Set(DomainElement.Of(4, 4), 1)
                          .Set(DomainElement.Of(1, 2), 0.3)
                          .Set(DomainElement.Of(2, 1), 0.3)
                          .Set(DomainElement.Of(2, 3), 0.5)
                          .Set(DomainElement.Of(3, 2), 0.5)
                          .Set(DomainElement.Of(3, 4), 0.2)
                          .Set(DomainElement.Of(4, 3), 0.2);

            IFuzzySet r2 = r;

            Console.WriteLine("Početna relacija je neizrazita relacija ekvivalencije? " + Relations.Relations.IsFuzzyEquivalence(r2));
            Console.WriteLine();

            for (int i = 1; i <= 3; i++)
            {
                r2 = Relations.Relations.CompositionOfBinaryRelations(r2, r, Operations.Operations.ZadehAnd(), Operations.Operations.ZadehOr());
                Console.WriteLine("Broj odrađenih kompozicija: " + i + ". Relacija je:");
                foreach (DomainElement e in r2.GetDomain())
                {
                    Console.WriteLine("mu(" + e + ")=" + r2.GetValueAt(e));
                }
                Console.WriteLine("Ova relacija je neizrazita relacija ekvivalencije? " + Relations.Relations.IsFuzzyEquivalence(r2));
                Console.WriteLine();
            }
        }
Ejemplo n.º 7
0
        public static bool IsMaxMinTransitive(IFuzzySet relation)
        {
            if (!IsUTimesURelation(relation))
            {
                return(false);
            }

            IDomain domain = relation.GetDomain()[0];

            foreach (var x in domain)
            {
                foreach (var z in domain)
                {
                    var value = 0.0;

                    foreach (var y in domain)
                    {
                        var xy = relation.GetValueAt(DomainElement.Of(x[0], y[0]));
                        var yz = relation.GetValueAt(DomainElement.Of(y[0], z[0]));

                        value = Math.Max(value, Math.Min(xy, yz));
                    }
                    if (value > relation.GetValueAt(DomainElement.Of(x[0], z[0])))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 8
0
        public static void Test32()
        {
            IDomain u  = Domain.IntRange(-5, 6); // {-5,-4,...,4,5}
            IDomain u2 = Domain.Combine(u, u);

            IFuzzySet set = new CalculatedFuzzySet(
                u2,
                StandardFuzzySets.LambdaFunction(
                    u2.IndexOfElement(DomainElement.Of(-4, 2)),
                    u2.IndexOfElement(DomainElement.Of(0, 0)),
                    u2.IndexOfElement(DomainElement.Of(4, 2))
                    )
                );

            Debug1.Print(set, "Set cf:");

            IFuzzySet notSet1 = Operations.Operations.UnaryOperation(
                set, Operations.Operations.ZadehNot());

            Debug1.Print(notSet1, "notSet1:");



            IFuzzySet union = Operations.Operations.BinaryOperation(
                set, notSet1, Operations.Operations.ZadehOr());

            Debug1.Print(union, "Set1 union notSet1:");
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            IDomain u1 = Domain.IntRange(1, 5);  // {1,2,3,4}
            IDomain u2 = Domain.IntRange(1, 4);  // {1,2,3}
            IDomain u3 = Domain.IntRange(1, 5);  // {1,2,3,4}

            IFuzzySet r1 = new MutableFuzzySet(Domain.Combine(u1, u2))
                           .Set(DomainElement.Of(1, 1), 0.3)
                           .Set(DomainElement.Of(1, 2), 1)
                           .Set(DomainElement.Of(3, 3), 0.5)
                           .Set(DomainElement.Of(4, 3), 0.5);

            IFuzzySet r2 = new MutableFuzzySet(Domain.Combine(u2, u3))
                           .Set(DomainElement.Of(1, 1), 1)
                           .Set(DomainElement.Of(2, 1), 0.5)
                           .Set(DomainElement.Of(2, 2), 0.7)
                           .Set(DomainElement.Of(3, 3), 1)
                           .Set(DomainElement.Of(3, 4), 0.4);

            IFuzzySet r1r2 = Relations.CompositionOfBinaryRelations(r1, r2);

            Console.WriteLine(r1r2);

            Console.ReadKey();
        }
Ejemplo n.º 10
0
        private static void PrintExample5()
        {
            Console.WriteLine("EXAMPLE 5");
            IDomain   u1 = IDomain.IntRange(1, 5); // {1,2,3,4}
            IDomain   u2 = IDomain.IntRange(1, 4); // {1,2,3}
            IDomain   u3 = IDomain.IntRange(1, 5); // {1,2,3,4}
            IFuzzySet r1 = new MutableFuzzySet(IDomain.Combine(u1, u2))
                           .Set(DomainElement.Of(1, 1), 0.3)
                           .Set(DomainElement.Of(1, 2), 1)
                           .Set(DomainElement.Of(3, 3), 0.5)
                           .Set(DomainElement.Of(4, 3), 0.5);
            IFuzzySet r2 = new MutableFuzzySet(IDomain.Combine(u2, u3))
                           .Set(DomainElement.Of(1, 1), 1)
                           .Set(DomainElement.Of(2, 1), 0.5)
                           .Set(DomainElement.Of(2, 2), 0.7)
                           .Set(DomainElement.Of(3, 3), 1)
                           .Set(DomainElement.Of(3, 4), 0.4);
            IFuzzySet r1r2 = Relations.CompositionOfBinaryRelations(r1, r2) !;

            foreach (var element in r1r2.GetDomain())
            {
                Console.WriteLine($"mu({element}) = {r1r2.GetValueAt(element)}");
            }
            Console.WriteLine("---------------------------------------");
            Console.WriteLine();
        }
Ejemplo n.º 11
0
        public static IFuzzySet CompositionOfBinaryRelations(IFuzzySet r1, IFuzzySet r2)
        {
            IDomain xDomain = r1.GetDomain()[0];
            IDomain yDomain = r1.GetDomain()[1];
            IDomain zDomain = r2.GetDomain()[1];

            var result = new MutableFuzzySet(Domain.Combine(xDomain, zDomain));
            var or     = Operations.ZadehOr();
            var and    = Operations.ZadehAnd();

            foreach (var x in xDomain)
            {
                foreach (var z in zDomain)
                {
                    var value = 0.0;

                    foreach (var y in yDomain)
                    {
                        var value1 = r1.GetValueAt(DomainElement.Of(x[0], y[0]));
                        var value2 = r2.GetValueAt(DomainElement.Of(y[0], z[0]));

                        value = or(value, and(value1, value2));
                    }

                    result.Set(DomainElement.Of(x[0], z[0]), value);
                }
            }

            return(result);
        }
        public static bool IsSymmetric(IFuzzySet relation)
        {
            if (!IsUTimesURelation(relation))
            {
                return(false);
            }

            var domain = relation.GetDomain();

            var firstComponent  = domain.GetComponent(0);
            var secondComponent = domain.GetComponent(1);

            for (var i = 0; i < firstComponent.GetCardinality(); i++)
            {
                for (var j = i + 1; j < secondComponent.GetCardinality(); j++)
                {
                    var iElementIndex = firstComponent.ElementForIndex(i).GetComponentValue(0);
                    var jElementIndex = secondComponent.ElementForIndex(j).GetComponentValue(0);

                    var ijValue = relation.GetValueAt(new DomainElement(iElementIndex, jElementIndex));
                    var jiValue = relation.GetValueAt(new DomainElement(jElementIndex, iElementIndex));

                    if (ijValue != jiValue)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 13
0
        private static void PrintExample3()
        {
            Console.WriteLine("EXAMPLE 3");
            IDomain d = IDomain.IntRange(0, 11);

            IFuzzySet set1 = new MutableFuzzySet(d).Set(DomainElement.Of(0), 1.0)
                             .Set(DomainElement.Of(1), 0.8)
                             .Set(DomainElement.Of(2), 0.6)
                             .Set(DomainElement.Of(3), 0.4)
                             .Set(DomainElement.Of(4), 0.2);

            PrintFuzzySet(set1, "Set1: ");

            IFuzzySet notSet1 = Operations.UnaryOperation(set1, Operations.ZadehNot());

            PrintFuzzySet(notSet1, "notSet1: ");

            IFuzzySet union = Operations.BinaryOperation(set1, notSet1, Operations.ZadehOr());

            PrintFuzzySet(union, "Set1 U notSet1: ");

            IFuzzySet hinters = Operations.BinaryOperation(set1, notSet1, Operations.HamacherTNorm(1.0));

            PrintFuzzySet(hinters, "Set1 Intersection with notSet1 using parameterised Hamacher T norm with parameter 1.0: ");
            Console.WriteLine("---------------------------------------");
            Console.WriteLine();
        }
 public BadDirection(string name)
 {
     Name     = name;
     FuzzySet = new MutableFuzzySet(IDomain.IntRange(0, 2))
                .Set(DomainElement.Of(0), 1.0)
                .Set(DomainElement.Of(1), 0.0);
 }
Ejemplo n.º 15
0
        public Rule(IFuzzySet[] antecedent, IFuzzySet consequent, BinaryFunction tNorm, BinaryFunction implication)
        {
            this.antecedent = antecedent;
            this.consequent = consequent;

            this.tNorm       = tNorm;
            this.implication = implication;
        }
Ejemplo n.º 16
0
 private void CreateAmmoFLV()
 {
     IFuzzySet[] ammoFlVFuzzySets = new IFuzzySet[3];
     ammoFlVFuzzySets[0] = new LeftShoulderFuzzySet(0, 10);
     ammoFlVFuzzySets[1] = new TriangleFuzzySet(0, 10, 30);
     ammoFlVFuzzySets[2] = new RightShoulderFuzzySet(10, 30);
     AmmoFLV             = new FuzzyLinguisticVariables(ammoFlVFuzzySets);
 }
Ejemplo n.º 17
0
        public int Solve(int[] inputs, int pravilo)
        {
            IFuzzySet solution = rules[pravilo].Accept(inputs);

            Console.WriteLine(solution);

            return(defuzzifier.Defuzzify(solution));
        }
Ejemplo n.º 18
0
 private void CreateDistanceFLV()
 {
     IFuzzySet[] distanceFlVFuzzySets = new IFuzzySet[3];
     distanceFlVFuzzySets[0] = new LeftShoulderFuzzySet(25, 150);
     distanceFlVFuzzySets[1] = new TriangleFuzzySet(25, 150, 300);
     distanceFlVFuzzySets[2] = new RightShoulderFuzzySet(150, 300);
     DistanceToTargetFLV     = new FuzzyLinguisticVariables(distanceFlVFuzzySets);
 }
 public void GivenMultipleDomains_TestOutputSet()
 {
     IDomain   d1 = DomainFactory.CreateDomain(new int[] { 1, 2, 3 });
     IDomain   d2 = DomainFactory.CreateDomain(new string[] { "a", "b" });
     IDomain   d3 = DomainFactory.CreateDomain(new IDomain[] { d1, d2 });
     IFuzzySet f1 = FuzzySetFactory.CreateFuzzySet(d1, new double[] { 1, 0.5, 0 });
     IFuzzySet f2 = f1.CylindricalExtension(d3);
 }
        public static IFuzzySet?CompositionOfBinaryRelations(IFuzzySet A, IFuzzySet B)
        {
            if (!AreRelationsMultiplicative(A, B))
            {
                return(null);
            }

            var rowAComponent    = A.GetDomain().GetComponent(0);
            var columnAComponent = A.GetDomain().GetComponent(1);
            var rowBComponent    = B.GetDomain().GetComponent(0);
            var columnBComponent = B.GetDomain().GetComponent(1);

            var rowsA = rowAComponent.GetCardinality();
            var colsA = columnAComponent.GetCardinality();

            var colsB = columnBComponent.GetCardinality();

            var fuzzySet = new MutableFuzzySet(new CompositeDomain(new SimpleDomain[]
            {
                (SimpleDomain)rowAComponent,
                (SimpleDomain)columnBComponent
            }));

            for (var i = 0; i < rowsA; i++)
            {
                for (var j = 0; j < colsB; j++)
                {
                    var maxValue = 0.0;
                    for (var k = 0; k < colsA; k++)
                    {
                        var iElement = rowAComponent.ElementForIndex(i).GetComponentValue(0);
                        var jElement = columnBComponent.ElementForIndex(j).GetComponentValue(0);
                        var kElement = rowAComponent.ElementForIndex(k).GetComponentValue(0);

                        var ikElement = new DomainElement(iElement, kElement);
                        var kjElement = new DomainElement(kElement, jElement);

                        var ikElementValue  = A.GetValueAt(ikElement);
                        var kjElementValue  = B.GetValueAt(kjElement);
                        var newElementValue = Math.Min(ikElementValue, kjElementValue);

                        if (maxValue < newElementValue)
                        {
                            maxValue = newElementValue;
                        }
                    }
                    var iiElement = rowAComponent.ElementForIndex(i).GetComponentValue(0);
                    var jjElement = columnBComponent.ElementForIndex(j).GetComponentValue(0);

                    var ijElement = new DomainElement(iiElement, jjElement);
                    fuzzySet.Set(ijElement, maxValue);
                }
            }

            return(fuzzySet);
        }
Ejemplo n.º 21
0
        public static IFuzzySet UnaryOperation(IFuzzySet fuzzySet, IUnaryFunction unary)
        {
            MutableFuzzySet A = new MutableFuzzySet(fuzzySet.GetDomain());

            foreach (DomainElement e in fuzzySet.GetDomain())
            {
                A.Set(e, unary.ValueAt(fuzzySet.GetValueAt(e)));
            }
            return(A);
        }
Ejemplo n.º 22
0
 public IFuzzySet Calculate(IFuzzySet set)
 {
     IList<double> memberships = new List<double>();
     for (int i = 0; i < set.GetDomain().GetCardinality(); i++)
     {
         double value = set.GetMembershipFor(set.GetDomain().ElementAt(i));
         memberships.Add(1 - value);
     }
     return FuzzySetFactory.CreateFuzzySet(set.GetDomain(), memberships);
 }
Ejemplo n.º 23
0
 public static bool IsSymmetric(IFuzzySet relation)
 {
     foreach (DomainElement element1 in relation.GetDomain())
     {
         if (relation.GetValueAt(DomainElement.Of(element1.GetComponentValue(0), element1.GetComponentValue(1))) != relation.GetValueAt(DomainElement.Of(element1.GetComponentValue(1), element1.GetComponentValue(0))))
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 24
0
 public static bool IsUtimesURelation(IFuzzySet relation)
 {
     if (relation.GetDomain().GetNumberOfComponents() == 2)
     {
         if (relation.GetDomain().GetComponent(0) == relation.GetDomain().GetComponent(1))
         {
             return(true);
         }
     }
     return(false);
 }
        public static IFuzzySet UnaryOperation(IFuzzySet set, IUnaryFunction function)
        {
            var newSet = new MutableFuzzySet(set.GetDomain());

            foreach (var element in newSet.GetDomain())
            {
                newSet.Set(element, function.ValueAt(set.GetValueAt(element)));
            }

            return(newSet);
        }
 public string Defuzzyfie(IFuzzySet set)
 {
     double sumNumerator = 0.0;
     double sumDenominator = 0.0;
     for (int i = 0; i < set.GetDomain().GetCardinality(); i++)
     {
         sumNumerator += (set.GetMembershipFor(set.GetDomain().ElementAt(i)) * (int)set.GetDomain().ElementAt(i)[0]);
         sumDenominator += set.GetMembershipFor(set.GetDomain().ElementAt(i));
     }
     return Convert.ToInt32(sumNumerator / sumDenominator).ToString();
 }
Ejemplo n.º 27
0
        public static IFuzzySet UnaryOperation(IFuzzySet set, UnaryFunction function)
        {
            var result = new MutableFuzzySet(set.GetDomain());

            foreach (var element in set.GetDomain())
            {
                result.Set(element, function(set.GetValueAt(element)));
            }

            return(result);
        }
Ejemplo n.º 28
0
        public IFuzzySet Calculate(IFuzzySet set)
        {
            IList <double> memberships = new List <double>();

            for (int i = 0; i < set.GetDomain().GetCardinality(); i++)
            {
                double value = set.GetMembershipFor(set.GetDomain().ElementAt(i));
                memberships.Add(1 - value);
            }
            return(FuzzySetFactory.CreateFuzzySet(set.GetDomain(), memberships));
        }
 public static void Print(IFuzzySet set, string headingText)    //metoda za ispis neizr skupa
 {
     if (headingText != null)
     {
         Console.WriteLine(headingText);
     }
     foreach (DomainElement e in set.GetDomain())
     {
         Console.WriteLine("D{0} = {1}", e, set.GetValueAt(e));
     }
     Console.WriteLine();
 }
        public string Defuzzyfie(IFuzzySet set)
        {
            double sumNumerator   = 0.0;
            double sumDenominator = 0.0;

            for (int i = 0; i < set.GetDomain().GetCardinality(); i++)
            {
                sumNumerator   += (set.GetMembershipFor(set.GetDomain().ElementAt(i)) * (int)set.GetDomain().ElementAt(i)[0]);
                sumDenominator += set.GetMembershipFor(set.GetDomain().ElementAt(i));
            }
            return(Convert.ToInt32(sumNumerator / sumDenominator).ToString());
        }
Ejemplo n.º 31
0
        private static void PrintFuzzySet(IFuzzySet set, string headingText = "")
        {
            if (!string.IsNullOrEmpty(headingText))
            {
                Console.WriteLine(headingText);
            }

            foreach (var de in set.GetDomain())
            {
                Console.WriteLine($"d({de}) = {set.GetValueAt(de):0.000000}");
            }
            Console.WriteLine();
        }
Ejemplo n.º 32
0
        public static IFuzzySet BinaryOperation(IFuzzySet set1, IFuzzySet set2, BinaryFunction function)
        {
            var result = new MutableFuzzySet(set1.GetDomain());

            foreach (var element in set1.GetDomain())
            {
                var x = set1.GetValueAt(element);
                var y = set2.GetValueAt(element);
                result.Set(element, function(x, y));
            }

            return(result);
        }
        /// <summary>
        /// Defuzzifie the value
        /// </summary>
        /// <param name="fuzzySets">FuzzySets matched rules</param>
        /// <returns>Crisp value</returns>
        public double Defuzzifier(List<IFuzzySet> fuzzySets)
        {
            var fuzzySet = this._connectiveElse(fuzzySets);
            this._lastResult = fuzzySet;

            var max = (from IFuzzyElement element in fuzzySet
                       select element.Value).Max();

            var med = (from IFuzzyElement element in fuzzySet
                       where element.Value == max
                       select element.X).Average();

            return med;
        }
Ejemplo n.º 34
0
 public IFuzzySet Calculate(IFuzzySet first, IFuzzySet second)
 {
     IList<double> memberships = new List<double>();
     IDomain domain = DomainFactory.CreateDomain(new IDomain[] { first.GetDomain(), second.GetDomain() });
     IFuzzySet firstCyl = first.CylindricalExtension(domain);
     IFuzzySet secondCyl = second.CylindricalExtension(domain);
     for (int i = 0; i < domain.GetCardinality(); i++)
     {
         double value1 = firstCyl.GetMembershipFor(domain.ElementAt(i));
         double value2 = secondCyl.GetMembershipFor(domain.ElementAt(i));
         memberships.Add(value1 * value2);
     }
     return FuzzySetFactory.CreateFuzzySet(domain, memberships);
 }
        /// <summary>
        /// Defuzzifie the value
        /// </summary>
        /// <param name="fuzzySets">FuzzySets matched rules</param>
        /// <returns>Crisp value</returns>
        public double Defuzzifier(List<IFuzzySet> fuzzySets)
        {
            if (fuzzySets.Count == 0)
            {
                return 0;
            }

            var fuzzySet = this._connectiveElse(fuzzySets);
            this._lastResult = fuzzySet;

            var upper = fuzzySet.Select(x => x.Value * x.X).Sum();
            var lower = fuzzySet.Select(x => x.Value).Sum();

            return upper / lower;
        }
Ejemplo n.º 36
0
 public IFuzzySet Calculate(IFuzzySet first, IFuzzySet second)
 {
     if (!first.GetDomain().Equals(second.GetDomain()))
     {
         throw new ApplicationException("Domains are not the same.");
     }
     IList<double> memberships = new List<double>();
     IDomain domain = first.GetDomain();
     for (int i = 0; i < first.GetDomain().GetCardinality(); i++)
     {
         double value1 = first.GetMembershipFor(domain.ElementAt(i));
         double value2 = second.GetMembershipFor(domain.ElementAt(i));
         memberships.Add(Math.Min(value1, value2));
     }
     return FuzzySetFactory.CreateFuzzySet(domain, memberships);
 }
        /// <summary>
        /// Defuzzifie the value
        /// </summary>
        /// <param name="fuzzySets">FuzzySets matched rules</param>
        /// <returns>Crisp value</returns>
        public double Defuzzifier(List<IFuzzySet> fuzzySets)
        {
            var fuzzySet = this._connectiveElse(fuzzySets);
            this._lastResult = fuzzySet;

            var keys = new List<double>();
            fuzzySets.ForEach(x => keys.AddRange(x.Elements.Keys.Select(y => y)));
            var distinctKeys = keys.Distinct().ToList();
            distinctKeys.Sort();

            var upper = distinctKeys.Select(
                x => x * fuzzySets.Where(
                    y => y.Elements.ContainsKey(x)).Select(z => z.Elements[x].Value).Sum()).Sum();

            var lower = distinctKeys.Select(
                x => fuzzySets.Where(
                    y => y.Elements.ContainsKey(x)).Select(z => z.Elements[x].Value).Sum()).Sum();

            return upper / lower;
        }
Ejemplo n.º 38
0
        public void AddSet(string name, IFuzzySet set)
        {
            if (_memberSets.ContainsKey(name))
            {
                _memberSets[name] = set;
            }
            else
            {
                _memberSets.Add(name, set);
            }

            if (_min > set.Min)
            {
                _min = set.Min;
            }
            if (_max < set.Max)
            {
                _max = set.Max;
            }
        }
Ejemplo n.º 39
0
        /// <summary>
        /// Get a Cartesian Product 
        /// </summary>
        /// <param name="fuzzySetA">
        /// FuzzySet A
        /// </param>
        /// <param name="fuzzySetB">
        /// FuzzySet B
        /// </param>
        /// <param name="function">
        /// Function to apply
        /// </param>
        /// <param name="rowBuilder">
        /// The row Builder.
        /// </param>
        /// <returns>
        /// The get cartesian product.
        /// </returns>
        public static List<IFuzzyRow> GetCartesianProduct(
            this IFuzzySet fuzzySetA,
            IFuzzySet fuzzySetB,
            Func<IFuzzyElement, IFuzzyElement, IFuzzyElement> function,
            Func<IFuzzyRow> rowBuilder)
        {
            var result = new List<IFuzzyRow>();

            foreach (var elementA in fuzzySetA)
            {
                var row = rowBuilder();
                row.X = elementA.X;
                foreach (var elementB in fuzzySetB)
                {
                    row.Add(function(elementB, elementA));
                }

                result.Add(row);
            }

            return result;
        }
Ejemplo n.º 40
0
 public IFuzzySet Implication(IFuzzySet other, IImplication implication)
 {
     return implication.Calculate(this, other);
 }
Ejemplo n.º 41
0
 /// <summary>
 /// Add a fuzzy value
 /// </summary>
 /// <param name="name">Linguistic meaning of the value</param>
 /// <param name="fuzzySet">FuzzySet of the value</param>
 public void AddFuzzyValue(string name, IFuzzySet fuzzySet)
 {
     this._values.Add(name, fuzzySet);
 }
Ejemplo n.º 42
0
 public IFuzzySet TNorm(IFuzzySet other, ITNorm tNorm)
 {
     return tNorm.Calculate(this, other);
 }
Ejemplo n.º 43
0
 public IFuzzySet Composition(IFuzzySet other, IComposition composition)
 {
     return composition.Calculate(this, other);
 }
Ejemplo n.º 44
0
 public IFuzzySet SNorm(IFuzzySet other, ISNorm sNorm)
 {
     return sNorm.Calculate(this, other);
 }
Ejemplo n.º 45
0
 public FuzzyFairly(IFuzzySet set)
 {
     this._set = set;
 }
Ejemplo n.º 46
0
 public IFuzzySet Calculate(IFuzzySet first, IFuzzySet second)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 47
0
        /// <summary>
        /// Degree of fulfillment
        /// </summary>
        /// <param name="fuzzySet">FuzzySet</param>
        /// <param name="fuzzyElement">FuzzyElement</param>
        /// <returns>FuzzySet</returns>
        private static IFuzzySet DegreeOfFulfillment(IFuzzySet fuzzySet, IFuzzyElement fuzzyElement)
        {
            var result = fuzzySet.GetNewEmpty();

            foreach (var element in fuzzySet)
            {
                result.AddElement(element.Min(fuzzyElement));
            }

            return result;
        }
Ejemplo n.º 48
0
 public FuzzyVery(IFuzzySet set)
 {
     this._set = set;
 }