Пример #1
0
        private static void Main()
        {
            var d = Domain.IntRange(0, 11); // {0,1,...,10}

            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);

            Console.WriteLine("Set 1:");
            Console.WriteLine(set1);
            Console.WriteLine();

            var       d2   = Domain.IntRange(-5, 6); // {-5,-4,...,4,5}
            IFuzzySet set2 = new CalculatedFuzzySet(
                d2,
                StandardFuzzySets.LambdaFunction(
                    d2.IndexOfElement(DomainElement.Of(-4)),
                    d2.IndexOfElement(DomainElement.Of(0)),
                    d2.IndexOfElement(DomainElement.Of(4))
                    )
                );

            Console.WriteLine("Set 2:");
            Console.WriteLine(set2);
            Console.WriteLine();

            Console.ReadKey();
        }
        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);
        }
Пример #3
0
        static void Primjer12()
        {
            IDomain d = Domain.IntRange(0, 11); // {0,1,...,10}
            //Debug1.Print(d, "Elementi domene d1:");

            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:");

            IDomain   d2   = Domain.IntRange(-5, 6); // {-5,-4,...,4,5}
            IFuzzySet set2 = new CalculatedFuzzySet(
                d2,
                StandardFuzzySets.LambdaFunction(
                    d2.IndexOfElement(DomainElement.Of(-4)),
                    d2.IndexOfElement(DomainElement.Of(0)),
                    d2.IndexOfElement(DomainElement.Of(4))
                    )
                );

            Debug1.Print(set2, "Set2:");
        }
Пример #4
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:");
        }
Пример #5
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:");
        }
        public static IFuzzySet MakeFuzzyRuleAntecedent(IIntUnaryFunction function)       //primjerice, posaljemo lambda( u2.IndexOfElement(DomainElement.Of(250, 31, 21, ...), ..., ...)
        {
            IFuzzySet antec = new CalculatedFuzzySet(
                u,
                function
                );

            return(antec);
        }
        public static IFuzzySet MakeFuzzyRuleConsequensKor(IIntUnaryFunction function)       //primjerice, posaljemo lambda( u2.IndexOfElement(DomainElement.Of(250, 31, 21, ...), ..., ...)
        {
            IDomain ukor = Domain.IntRange(-90, 90);

            IFuzzySet conseq = new CalculatedFuzzySet(
                ukor,
                function
                );

            return(conseq);
        }
Пример #8
0
        public AkcelFuzzySystem(Defuzzifier defuzzifier)
        {
            this.defuzzifier = defuzzifier;

            IDomain acceleration = Domain.IntRange(-5, 6);
            IDomain direction    = Domain.IntRange(0, 2);
            IDomain distance     = Domain.IntRange(0, 1301);
            IDomain velocity     = Domain.IntRange(0, 100);

            MutableFuzzySet Id = new MutableFuzzySet(distance);
            MutableFuzzySet Iv = new MutableFuzzySet(velocity);

            foreach (var element in distance)
            {
                Id.Set(element, 1);
            }
            foreach (var element in velocity)
            {
                Iv.Set(element, 1);
            }

            IFuzzySet Slow   = new CalculatedFuzzySet(velocity, StandardFuzzySets.LFunction(0, 40));
            IFuzzySet Medium = new CalculatedFuzzySet(velocity, StandardFuzzySets.LambdaFunction(37, 45, 55));
            IFuzzySet Fast   = new CalculatedFuzzySet(velocity, StandardFuzzySets.GammaFunction(48, 60));

            IFuzzySet CriticalClose = new CalculatedFuzzySet(distance, StandardFuzzySets.LFunction(10, 30));
            IFuzzySet Close         = new CalculatedFuzzySet(distance, StandardFuzzySets.LFunction(25, 50));
            IFuzzySet Far           = new CalculatedFuzzySet(distance, StandardFuzzySets.GammaFunction(70, 100));

            IFuzzySet Backward = new MutableFuzzySet(direction).Set(DomainElement.Of(0), 1);
            IFuzzySet Forward  = new MutableFuzzySet(direction).Set(DomainElement.Of(1), 1);

            IFuzzySet SpeedUp = new MutableFuzzySet(acceleration)
                                .Set(DomainElement.Of(5), 1)
                                .Set(DomainElement.Of(4), 0.6)
                                .Set(DomainElement.Of(3), 0.3);
            IFuzzySet Neutral  = new MutableFuzzySet(acceleration).Set(DomainElement.Of(0), 1);
            IFuzzySet SlowDown = new MutableFuzzySet(acceleration)
                                 .Set(DomainElement.Of(-5), 1)
                                 .Set(DomainElement.Of(-4), 0.6)
                                 .Set(DomainElement.Of(-3), 0.3);

            // L, D, LK, RK, V, S
            rules = new List <Rule>();
            rules.Add(new Rule(new[] { Id, Id, CriticalClose, Id, Iv, Forward }, Neutral, tNorm, implication));
            rules.Add(new Rule(new[] { Id, Id, Id, CriticalClose, Iv, Forward }, Neutral, tNorm, implication));
            rules.Add(new Rule(new[] { Id, Id, CriticalClose, Id, Iv, Backward }, Neutral, tNorm, implication));
            rules.Add(new Rule(new[] { Id, Id, Id, CriticalClose, Iv, Backward }, Neutral, tNorm, implication));

            rules.Add(new Rule(new[] { Id, Id, Id, Id, Fast, Forward }, SlowDown, tNorm, implication));
            rules.Add(new Rule(new[] { Id, Id, Id, Id, Medium, Forward }, Neutral, tNorm, implication));
            rules.Add(new Rule(new[] { Id, Id, Id, Id, Slow, Forward }, SpeedUp, tNorm, implication));
        }
        public override int ZakljuciProd(int L, int D, int LK, int DK, int V, int S)      //TODO bude li trebala diferencijacija, svaki zakljuci u svoju klasu
        {
            IFuzzySet union = new CalculatedFuzzySet(                                     //mjere pripadnosti su na minimumu mj.pripadnosti antecedenata
                Domain.IntRange(-90, 90),
                StandardFuzzySets.EmptyFunction()
                );

            foreach (Rule rule in KormiloRules)
            {
                union = Operations.Operations.BinaryOperation(
                    union, rule.SingleRuleConclusionProduct(L, D, LK, DK, V, S), Operations.Operations.ZadehOr());     //TODO IMPORTANT postoji li efikasniji nacin nego doslovno unija svega?
                //Print(union, "union foreach:");
            }

            return(def.Defuzzyfy(union));
        }
Пример #10
0
        public static void Test31()
        {
            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:");
        }
        public override void ZakljuciPrint(int L, int D, int LK, int DK, int V, int S, Rule rule) //TODO bude li trebala diferencijacija, svaki zakljuci u svoju klasu
        {
            IFuzzySet union = new CalculatedFuzzySet(                                             //mjere pripadnosti su na minimumu mj.pripadnosti antecedenata
                Domain.IntRange(-100, 100),
                StandardFuzzySets.EmptyFunction()
                );


            union = Operations.Operations.BinaryOperation(
                union, rule.SingleRuleConclusion(L, D, LK, DK, V, S), Operations.Operations.ZadehOr());     //TODO IMPORTANT postoji li efikasniji nacin nego doslovno unija svega?
            KormiloFuzzySystemMin.Print(union, "Zakljucak:");

            int rez = def.Defuzzyfy(union);

            Console.WriteLine("Dekodirana vrijednost: {0}", rez);
            return;
        }
Пример #12
0
        private static void Main(string[] args)
        {
            SimpleDomain sd = new SimpleDomain(-4, 5);

            PrintDomain(sd, "sd: ");

            IDomain cd = IDomain.Combine(sd, sd);

            PrintDomain(cd, "cd: ");

            IDomain   d    = IDomain.IntRange(0, 11);
            IFuzzySet set1 = new MutableFuzzySet(d).Set(DomainElement.Of(0), 1.0);

            PrintFuzzySet(set1, "set1: ");

            IDomain   d2   = IDomain.IntRange(-5, 6);
            IFuzzySet set2 = new CalculatedFuzzySet(d2,
                                                    StandardFuzzySets.LambdaFunction(d2.IndexOfElement(DomainElement.Of(-4)),
                                                                                     d2.IndexOfElement(DomainElement.Of(0)),
                                                                                     d2.IndexOfElement(DomainElement.Of(4))));

            PrintFuzzySet(set2, "set2: ");


            IDomain d7 = IDomain.IntRange(0, 11);

            IFuzzySet set3 = new MutableFuzzySet(d7).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(set3, "set3: ");

            IFuzzySet notSet3 = Operations.UnaryOperation(set3, Operations.ZadehNot());

            PrintFuzzySet(notSet3, "notSet3: ");

            IFuzzySet union = Operations.BinaryOperation(set3, notSet3, Operations.ZadehOr());

            PrintFuzzySet(union, "Set3 U notSet3: ");

            IFuzzySet hinters = Operations.BinaryOperation(set3, notSet3, Operations.HamacherTNorm(1.0));

            PrintFuzzySet(hinters, "Set3 Intersection with notSet3 using parameterised Hamacher T norm with parameter 1.0: ");
        }
Пример #13
0
        private static void PrintExample2()
        {
            Console.WriteLine("EXAMPLE 2");
            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: ");

            IDomain   d2   = IDomain.IntRange(-5, 6);
            IFuzzySet set2 = new CalculatedFuzzySet(d2,
                                                    StandardFuzzySets.LambdaFunction(d2.IndexOfElement(DomainElement.Of(-4)),
                                                                                     d2.IndexOfElement(DomainElement.Of(0)),
                                                                                     d2.IndexOfElement(DomainElement.Of(4))));

            PrintFuzzySet(set2, "Set2: ");
            Console.WriteLine("---------------------------------------");
            Console.WriteLine();
        }
Пример #14
0
        public KormiloFuzzySystem(Defuzzifier defuzzifier)
        {
            this.defuzzifier = defuzzifier;

            IDomain angle     = Domain.IntRange(-90, 91);
            IDomain direction = Domain.IntRange(0, 2);
            IDomain distance  = Domain.IntRange(0, 1301);
            IDomain velocity  = Domain.IntRange(0, 100);

            MutableFuzzySet Id = new MutableFuzzySet(distance);
            MutableFuzzySet Iv = new MutableFuzzySet(velocity);

            foreach (var element in distance)
            {
                Id.Set(element, 1);
            }
            foreach (var element in velocity)
            {
                Iv.Set(element, 1);
            }

            //IFuzzySet CriticalClose = new CalculatedFuzzySet(distance, StandardFuzzySets.LFunction(20, 40));
            IFuzzySet Close   = new CalculatedFuzzySet(distance, StandardFuzzySets.LFunction(40, 90));
            IFuzzySet Far     = new CalculatedFuzzySet(distance, StandardFuzzySets.GammaFunction(100, 200));
            IFuzzySet VeryFar = new CalculatedFuzzySet(distance, StandardFuzzySets.GammaFunction(300, 400));
            //IFuzzySet NotFar = Operations.UnaryOperation(Far, Operations.ZadehNot());

            IFuzzySet Backward = new MutableFuzzySet(direction).Set(DomainElement.Of(0), 1);
            IFuzzySet Forward  = new MutableFuzzySet(direction).Set(DomainElement.Of(1), 1);

            IFuzzySet Left = new MutableFuzzySet(angle).Set(DomainElement.Of(90), 1);
            //IFuzzySet Left = new CalculatedFuzzySet(angle, StandardFuzzySets.LambdaFunction(0, 30, 50));
            //IFuzzySet FullLeft = new CalculatedFuzzySet(angle, StandardFuzzySets.LambdaFunction(55, 70, 80));

            IFuzzySet Neutral = new CalculatedFuzzySet(angle, StandardFuzzySets.LambdaFunction(-10, 0, 10));

            //IFuzzySet Right = new CalculatedFuzzySet(angle, StandardFuzzySets.LambdaFunction(-50, -30, 0));
            IFuzzySet Right = new MutableFuzzySet(angle).Set(DomainElement.Of(-90), 1);

            //IFuzzySet FullRight = new CalculatedFuzzySet(angle, StandardFuzzySets.LambdaFunction(-80, -70, -55));


            // L, D, LK, RK, V, S
            rules = new List <Rule>();
            rules.Add(new Rule(new[] { Id, Close, Id, Id, Iv, Forward }, Left, tNorm, implication));
            rules.Add(new Rule(new[] { Close, Id, Id, Id, Iv, Forward }, Right, tNorm, implication));

            rules.Add(new Rule(new[] { Id, Id, Id, Close, Iv, Forward }, Left, tNorm, implication));
            rules.Add(new Rule(new[] { Id, Id, Close, Id, Iv, Forward }, Right, tNorm, implication));

            rules.Add(new Rule(new[] { VeryFar, Id, Id, Id, Iv, Backward }, Left, tNorm, implication));
            rules.Add(new Rule(new[] { Id, VeryFar, Id, Id, Iv, Backward }, Right, tNorm, implication));


            //rules.Add(new Rule(new[] { Far, Close, Id, Id, Iv, Forward }, Left, tNorm, implication));
            //rules.Add(new Rule(new[] { Id, Close, Id, CriticalClose, Iv, Forward }, FullLeft));
            //rules.Add(new Rule(new[] { Far, Close, Id, Id, Iv, Backward }, Left, tNorm, implication));

            //rules.Add(new Rule(new[] { Far, Far, Id, Id, Iv, Forward }, Neutral));

            //rules.Add(new Rule(new[] { Close, Far, Id, Id, Iv, Forward }, Right, tNorm, implication));
            //rules.Add(new Rule(new[] { Close, Id, CriticalClose, Id, Iv, Forward }, FullRight));
            //rules.Add(new Rule(new[] { Close, Far, Id, Id, Iv, Backward }, Right, tNorm, implication));


            //rules.Add(new Rule(new[] { Far, Id, Close, Close, Iv, Forward }, Left, tNorm, implication));
            //rules.Add(new Rule(new[] { Id, Far, Close, Close, Iv, Forward }, Right, tNorm, implication));
            //rules.Add(new Rule(new[] { VeryFar, VeryFar, Close, Close, Iv, Forward }, Right, tNorm, implication));

            //rules.Add(new Rule(new[] { Far, Id, Close, Close, Iv, Backward }, Right, tNorm, implication));
            ////rules.Add(new Rule(new[] { Id, Far, Close, Close, Iv, Backward }, Left, tNorm, implication));


            //rules.Add(new Rule(new[] { Close, Close, Id, Close, Iv, Forward }, Left, tNorm, implication));
            //rules.Add(new Rule(new[] { Close, Close, Close, Id, Iv, Forward }, Right, tNorm, implication));

            //rules.Add(new Rule(new[] { Id, Id, Id, Id, Iv, Backward }, Right, tNorm, implication));

            //rules.Add(new Rule(new[] { VeryFar, Id, Close, Close, Iv, Forward }, Right, tNorm, implication));
            //rules.Add(new Rule(new[] { Id, VeryFar, Close, Close, Iv, Forward }, Left, tNorm, implication));
        }