Ejemplo n.º 1
0
 /// <summary>
 /// Generates fuzzy set with specified membership function.
 /// </summary>
 /// <param name="cFunction">The membership function.</param>
 /// <param name="dFrom">The begin of interval.</param>
 /// <param name="dTo">The end of interval.</param>
 /// <param name="dStep">The step.</param>
 /// <returns>Builded fuzzy set.</returns>
 public FuzzySet Generate(SetMembershipFunction cFunction, double dFrom, double dTo, double dStep)
 {
     var cSet = new FuzzySet();
     for (double dIndex = dFrom; dIndex <= dTo; dIndex += dStep)
         cSet.Add(new FuzzyElement(dIndex, cFunction(dIndex)));
     return cSet;
 }
Ejemplo n.º 2
0
		public void create_classifier()
		{
			a = new FuzzySet();
			a["low"] = new Triangle(0.0, 0.0, 0.5);
			a["mid"] = new Triangle(0.0, 0.5, 1.0);
			a["high"]= new Triangle(0.5, 1.0, 1.0);			
		}
Ejemplo n.º 3
0
        public LinguisticVariable LinguisticVitesse()
        {
            LinguisticVariable lV           = new LinguisticVariable("Vitesse", 0, 200);
            FuzzySet           fsLente      = new FuzzySet("Lente", new TrapezoidalFunction(20, 30, 200, 0, TrapezoidalFunction.EdgeType.Right));
            FuzzySet           fsPeuRapide  = new FuzzySet("PeuRapide", new TrapezoidalFunction(20, 30, 70, 80));
            FuzzySet           fsRapide     = new FuzzySet("Rapide", new TrapezoidalFunction(70, 80, 90, 110));
            FuzzySet           fsTresRapide = new FuzzySet("TresRapide", new TrapezoidalFunction(90, 110, 200, 0, TrapezoidalFunction.EdgeType.Left));

            lV.AddLabel(fsLente);
            lV.AddLabel(fsPeuRapide);
            lV.AddLabel(fsRapide);
            lV.AddLabel(fsTresRapide);

            return(lV);
        }
Ejemplo n.º 4
0
        private LinguisticVariable GetSeismicityVariable(string seismicityType)
        {
            FuzzySet lowEnv    = new FuzzySet("Low", new TrapezoidalFunction(1, 2.5f, 2.5f, 4.2f));
            FuzzySet mediumEnv = new FuzzySet("Medium", new TrapezoidalFunction(3.8f, 4.5f, 4.5f, 5.2f));
            FuzzySet strongEnv = new FuzzySet("Strong", new TrapezoidalFunction(4.8f, 6.5f, 6.5f, 9.2f));
            FuzzySet greatEnv  = new FuzzySet("Great", new TrapezoidalFunction(8.8f, 10.5f, 12, 12));

            LinguisticVariable lvSeismicEnv = new LinguisticVariable(seismicityType, 1, 12);

            lvSeismicEnv.AddLabel(lowEnv);
            lvSeismicEnv.AddLabel(mediumEnv);
            lvSeismicEnv.AddLabel(strongEnv);
            lvSeismicEnv.AddLabel(greatEnv);

            return(lvSeismicEnv);
        }
Ejemplo n.º 5
0
        private LinguisticVariable GetDepthVariable(string depthType)
        {
            FuzzySet shallowDepth  = new FuzzySet("Shallow", new TrapezoidalFunction(0, 2, 8, 10.5f));
            FuzzySet fairlyDepth   = new FuzzySet("Fairly", new TrapezoidalFunction(9.5f, 12, 18, 20.5f));
            FuzzySet deepDepth     = new FuzzySet("Deep", new TrapezoidalFunction(19.5f, 25, 35, 40.5f));
            FuzzySet veryDeepDepth = new FuzzySet("VeryDeep", new TrapezoidalFunction(35, 40, float.MaxValue, float.MaxValue));

            LinguisticVariable lvDepth = new LinguisticVariable(depthType, 0, float.MaxValue);

            lvDepth.AddLabel(shallowDepth);
            lvDepth.AddLabel(fairlyDepth);
            lvDepth.AddLabel(deepDepth);
            lvDepth.AddLabel(veryDeepDepth);

            return(lvDepth);
        }
Ejemplo n.º 6
0
        public double Solve()
        {
            // Aplicación de las reglas y cálculo del fuzzy set resultante
            FuzzySet res = new FuzzySet(Output.MinValue, Output.MaxValue);

            res.Add(Output.MinValue, 0);
            res.Add(Output.MaxValue, 0);

            foreach (FuzzyRule rule in Rules)
            {
                // Cálculo
                res = res | rule.Apply(Problem);
            }

            // Defuzzificación
            return(res.Centroid());
        }
Ejemplo n.º 7
0
    public double Solve()
    {
        // Application des règles et calcul du fuzzy set résultant
        FuzzySet res = new FuzzySet(Output.MinValue, Output.MaxValue);

        res.Add(Output.MinValue, 0);
        res.Add(Output.MaxValue, 0);

        foreach (FuzzyRule rule in Rules)
        {
            // Calcul
            res = res | rule.Apply(Problem);
        }

        // Defuzzification
        return(res.Centroid());
    }
Ejemplo n.º 8
0
    public static float CalculateEmotionLevels(Data[] p_data, float p_value)
    {
        c = new FLC(configure);
        double   healthCurrentCrisp = p_data[0].health;
        FuzzySet fuzzy_health       = new FuzzySet(c.Fuzzification(healthCurrentCrisp, health), health.Name);

        List <FuzzySet> input_sets = new List <FuzzySet>();

        input_sets.Add(fuzzy_health);

        engine = new InferEngine(configure, rules, input_sets);
        List <FuzzySet> fuzzy_out = engine.evaluateRules();

        float crisp_mood = (float)c.DeFuzzification(fuzzy_out, mood);

        return(crisp_mood);
    }
Ejemplo n.º 9
0
        public void SetFuzzyValues(float f1_1, float f2_1, float f1_X, float f2_X, float f3_X, float f4_X, float f1_2, float f2_2)
        {
            _lvlProbabilidad.ClearLabels();

            _fsUno   = new FuzzySet("UNO", new TrapezoidalFunction(f1_1, f2_1, TrapezoidalFunction.EdgeType.Left));
            _fsEquis = new FuzzySet("EQUIS", new TrapezoidalFunction(f1_X, f2_X, f3_X, f4_X));
            _fsDos   = new FuzzySet("DOS", new TrapezoidalFunction(f1_2, f2_2, TrapezoidalFunction.EdgeType.Right));

            Log.Info($"Setting Function for '2' with values 0 - {f1_2} - {f2_2}");
            Log.Info($"Setting Function for 'X' with values {f1_X} - {f2_X} - {f3_X} - {f4_X}");
            Log.Info($"Setting Function for '1' with values {f1_1} - {f2_1} - 100");

            _lvlProbabilidad.AddLabel(_fsUno);
            _lvlProbabilidad.AddLabel(_fsDos);
            _lvlProbabilidad.AddLabel(_fsEquis);

            IsSet = true;
        }
Ejemplo n.º 10
0
        private void UpdateChart()
        {
            try
            {
                _dimension = new ContinuousDimension(FuzzyName, Description, Unit, (decimal)Min, (decimal)Max);

                _fuzzySet = new QuadraticSet(_dimension, FuzzyName, LeftTop, RightTop, LeftBot, RightBot, LeftMid, RightMid);
                //_fuzzySet = new RightQuadraticSet(_dimension, FuzzyName, Top, Mid,Bot);
                var           chart    = (PictureBox)Wfh.Child;
                RelationImage imgBuyIt = new RelationImage(_fuzzySet);
                Bitmap        bmpBuyIt = new Bitmap(chart.Width, chart.Height);
                imgBuyIt.DrawImage(Graphics.FromImage(bmpBuyIt));
                chart.Image = bmpBuyIt;
            }
            catch
            {
            }
        }
        private InferenceSystem SetupInferenceSystem(byte minLuma, byte maxLuma, byte meanLuma)
        {
            var lumaIn  = new LinguisticVariable("LumaIn", minLuma, maxLuma);
            var lumaOut = new LinguisticVariable("LumaOut", 0, 255);

            var darkFunction = new TrapezoidalFunction(minLuma, meanLuma, TrapezoidalFunction.EdgeType.Right);
            var darkSet      = new FuzzySet("Dark", darkFunction);

            var mediumFunction = new TrapezoidalFunction(minLuma, meanLuma, maxLuma);
            var mediumSet      = new FuzzySet("Medium", mediumFunction);

            var lightFunction = new TrapezoidalFunction(meanLuma, maxLuma, TrapezoidalFunction.EdgeType.Left);
            var lightSet      = new FuzzySet("Light", lightFunction);

            lumaIn.AddLabel(darkSet);
            lumaIn.AddLabel(mediumSet);
            lumaIn.AddLabel(lightSet);

            var whiteFunction = new SingletonFunction(255);
            var whiteSet      = new FuzzySet("White", whiteFunction);

            var blackFunction = new SingletonFunction(0);
            var blackSet      = new FuzzySet("Black", blackFunction);

            var grayFunction = new SingletonFunction(128);
            var graySet      = new FuzzySet("Gray", grayFunction);

            lumaOut.AddLabel(blackSet);
            lumaOut.AddLabel(graySet);
            lumaOut.AddLabel(whiteSet);

            var database = new Database();

            database.AddVariable(lumaIn);
            database.AddVariable(lumaOut);

            var inferenceSystem = new InferenceSystem(database, new CogDefuzzifier());

            inferenceSystem.NewRule("Rule 1", "IF LumaIn IS Dark THEN LumaOut is Black");
            inferenceSystem.NewRule("Rule 2", "IF LumaIn IS Medium THEN LumaOut is Gray");
            inferenceSystem.NewRule("Rule 3", "IF LumaIn IS Light THEN LumaOut is White");

            return(inferenceSystem);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string Label = null;
            double A     = double.NaN;
            double B     = double.NaN;
            double C     = double.NaN;

            if (!DA.GetData(0, ref Label))
            {
                return;
            }
            if (!DA.GetData(1, ref A))
            {
                return;
            }
            if (!DA.GetData(2, ref B))
            {
                return;
            }
            if (!DA.GetData(3, ref C))
            {
                return;
            }

            if (!Rhino.RhinoMath.IsValidDouble(A))
            {
                return;
            }
            if (!Rhino.RhinoMath.IsValidDouble(B))
            {
                return;
            }
            if (!Rhino.RhinoMath.IsValidDouble(C))
            {
                return;
            }

            FuzzySet fSet = new FuzzySet(Label, new TrapezoidalFunction(
                                             (float)A, (float)B, (float)C));

            DA.SetData(0, fSet);
        }
Ejemplo n.º 13
0
        public void UpdateChart()
        {
            if (!ShallUpdateChart)
            {
                return;
            }
            if (_min >= _max)
            {
                return;
            }
            //_dimension = new ContinuousDimension(FuzzyName, Description, Unit, (decimal)_min, (decimal)_max);
            if (IsLinear)
            {
                if (IsLeft)
                {
                    _fuzzySet = new LeftLinearSet(Dimension, FuzzyName, (decimal)_bot, (decimal)_top);
                }
                else
                {
                    _fuzzySet = new RightLinearSet(Dimension, FuzzyName, (decimal)_top, (decimal)_bot);
                }
            }
            else
            {
                if (IsLeft)
                {
                    _fuzzySet = new LeftQuadraticSet(Dimension, FuzzyName, (decimal)_bot, (decimal)_mid, (decimal)_top);
                }
                else
                {
                    _fuzzySet = new RightQuadraticSet(Dimension, FuzzyName, (decimal)_top, (decimal)_mid, (decimal)_bot);
                }
            }
            //_fuzzySet = new RightQuadraticSet(_dimension, FuzzyName, Top, Mid,Bot);
            var chart    = (PictureBox)Wfh.Child;
            var imgBuyIt = new RelationImage(_fuzzySet);
            var bmpBuyIt = new Bitmap(chart.Width, chart.Height);

            imgBuyIt.DrawImage(Graphics.FromImage(bmpBuyIt));
            chart.Image = bmpBuyIt;
        }
Ejemplo n.º 14
0
        public LingVar(int number, string name, float min, float max, Scope[] scopes, int[] d)
        {
            this.min = min;
            this.max = max;
            range    = Math.Abs(max - min);

            terms = new FuzzySet[d.Length];
            lv    = new LinguisticVariable(name, min, max);

            for (int i = 0; i < terms.Length; i++)
            {
                terms[i] = new FuzzySet(name + d[i].ToString(),
                                        new TrapezoidalFunction(
                                            (float)scopes[d[i]].min[number],
                                            (float)scopes[d[i]].center[number],
                                            (float)scopes[d[i]].max[number])
                                        );

                lv.AddLabel(terms[i]);
            }
        }
Ejemplo n.º 15
0
        public float Defuzze(FuzzySet <T> outputVariableSet, FuzzyValueSet fuzzyValues)
        {
            float             sumRepValConf = 0.0f;
            float             sumConf       = 0.0f;
            FuzzyVariable <T> fuzzyVar      = null;
            FuzzyValue <T>    value;

            for (int i = 0; i < this.outputEnumValues.Length; i++)
            {
                T linguisticVar = this.outputEnumValues[i];
                value = fuzzyValues.Get(linguisticVar);
                if (value.Confidence <= 0.0f)
                {
                    continue;
                }
                fuzzyVar       = outputVariableSet.Get(linguisticVar);
                sumRepValConf += (fuzzyVar.MembershipFunction.RepresentativeValue * value.Confidence);
                sumConf       += value.Confidence;
            }
            return(sumRepValConf / sumConf);
        }
Ejemplo n.º 16
0
        private LinguisticVariable GetConcentrationVariable(string period, DateTime dateFrom, DateTime dateTo)
        {
            var   offset        = dateTo - dateFrom;
            int   days          = offset.Days;
            float bigPercent    = 0.04f;
            float mediumPercent = 0.02f;
            float smallPercent  = 0.01f;


            FuzzySet smallConcentration  = new FuzzySet("Small", new TrapezoidalFunction(0, 0, smallPercent * days, mediumPercent * days));
            FuzzySet mediumConcentration = new FuzzySet("Medium", new TrapezoidalFunction(smallPercent * days, mediumPercent * days, bigPercent * days));
            FuzzySet bigConcentration    = new FuzzySet("Big", new TrapezoidalFunction(mediumPercent * days, bigPercent * days, TrapezoidalFunction.EdgeType.Left));

            LinguisticVariable lvConcentration = new LinguisticVariable(period, 0, float.MaxValue);

            lvConcentration.AddLabel(smallConcentration);
            lvConcentration.AddLabel(mediumConcentration);
            lvConcentration.AddLabel(bigConcentration);

            return(lvConcentration);
        }
Ejemplo n.º 17
0
        public List <FuzzySet> evaluateRules()
        {
            List <FuzzySet> OutSets = new List <FuzzySet>();

            for (int i = 0; i < _rules.Count; i++)
            {
                List <RuleItem> outrules       = _rules[i].OutputRules;
                double          firingStrength = getRuleValue(_rules[i]);
                if (firingStrength > 0)
                {
                    firedRules.Add(i + 1);
                    for (int j = 0; j < outrules.Count; j++)
                    {
                        String Var = outrules[j].Variable;
                        if (OutSets.Exists(delegate(FuzzySet f) { return(f.Variable == Var); }))
                        {
                            int    index = OutSets.FindIndex(delegate(FuzzySet f) { return(f.Variable == Var); });
                            String Mem   = outrules[j].MemberShipValue;
                            if (OutSets[index].Set.Exists(delegate(FuzzyNumber n) { return(n.MemberShipName == Mem); }))
                            {
                                int index2 = OutSets[index].Set.FindIndex(delegate(FuzzyNumber n) { return(n.MemberShipName == Mem); });
                                OutSets[index].Set[index2].FuzzyValue = Implication(OutSets[index].Set[index2].FuzzyValue, firingStrength);
                            }
                            else
                            {
                                FuzzyNumber num = new FuzzyNumber(Mem, firingStrength);
                                OutSets[index].Set.Add(num);
                            }
                        }
                        else
                        {
                            FuzzySet newset = new FuzzySet(Var);
                            newset.Set.Add(new FuzzyNumber(outrules[j].MemberShipValue, firingStrength));
                            OutSets.Add(newset);
                        }
                    }
                }
            }
            return(OutSets);
        }
Ejemplo n.º 18
0
        private LinguisticVariable GetMagnitudeVariable(string magType)
        {
            FuzzySet microMagnitude    = new FuzzySet("Micro", new TrapezoidalFunction(0, 1, 1, 2.2f));
            FuzzySet minorMagnitude    = new FuzzySet("Minor", new TrapezoidalFunction(1.8f, 3, 3, 4.2f));
            FuzzySet lightMagnitude    = new FuzzySet("Light", new TrapezoidalFunction(3.8f, 4.5f, 4.5f, 5.2f));
            FuzzySet moderateMagnitude = new FuzzySet("Moderate", new TrapezoidalFunction(4.8f, 5.5f, 5.5f, 6.2f));
            FuzzySet strongMagnitude   = new FuzzySet("Strong", new TrapezoidalFunction(5.8f, 6.5f, 6.5f, 7.2f));
            FuzzySet majorMagnitude    = new FuzzySet("Major", new TrapezoidalFunction(6.8f, 7.5f, 7.5f, 8.2f));
            FuzzySet greatMagnitude    = new FuzzySet("Great", new TrapezoidalFunction(7.8f, 8, 12, 12));

            LinguisticVariable lvMagnitude = new LinguisticVariable(magType, 0, 12);

            lvMagnitude.AddLabel(microMagnitude);
            lvMagnitude.AddLabel(minorMagnitude);
            lvMagnitude.AddLabel(lightMagnitude);
            lvMagnitude.AddLabel(moderateMagnitude);
            lvMagnitude.AddLabel(strongMagnitude);
            lvMagnitude.AddLabel(majorMagnitude);
            lvMagnitude.AddLabel(greatMagnitude);

            return(lvMagnitude);
        }
Ejemplo n.º 19
0
        private void SetFuzySet() //ustawia wartość przedziałów
        {
            //ustawia wartości przedziałów dla temperatury zewnętrzej
            TrapezoidalFunction function = new TrapezoidalFunction(-10, 30, TrapezoidalFunction.EdgeType.Right);

            tmpColdOut = new FuzzySet("ColdOut", function);
            function   = new TrapezoidalFunction(-10, 30, TrapezoidalFunction.EdgeType.Left);
            tmpHotOut  = new FuzzySet("HotOut", function);

            //ustawia wartości przedziałów dla temperatury
            function    = new TrapezoidalFunction(1, 10, TrapezoidalFunction.EdgeType.Right);
            tmpVeryCold = new FuzzySet("VeryCold", function);
            function    = new TrapezoidalFunction(5, 10, 13, 16);
            tmpCold     = new FuzzySet("Cold", function);
            function    = new TrapezoidalFunction(13, 16, 21, 26);
            tmpMedium   = new FuzzySet("Medium", function);
            function    = new TrapezoidalFunction(21, 25, 30, 35);
            tmpHot      = new FuzzySet("Hot", function);
            function    = new TrapezoidalFunction(30, 35, TrapezoidalFunction.EdgeType.Left);
            tmpVeryHot  = new FuzzySet("VeryHot", function);
            //ustawia wartości przedziałów dla wilgotności
            function      = new TrapezoidalFunction(0, 40, TrapezoidalFunction.EdgeType.Right);
            smallHumidity = new FuzzySet("Small", function);
            function      = new TrapezoidalFunction(20, 40, 60, 80);
            goodHumidity  = new FuzzySet("Good", function);
            function      = new TrapezoidalFunction(60, 100, TrapezoidalFunction.EdgeType.Left);
            bigHumidity   = new FuzzySet("Big", function);
            //ustawia wartość przedziału przedział siły wentylatora (od zera do 100)
            function          = new TrapezoidalFunction(20, 30, TrapezoidalFunction.EdgeType.Right);
            veryLowStrenght   = new FuzzySet("VeryLow", function);
            function          = new TrapezoidalFunction(20, 30, 40, 50);
            lowStrenght       = new FuzzySet("Low", function);
            function          = new TrapezoidalFunction(40, 50, 60, 70);
            mediumStrenght    = new FuzzySet("Medium", function);
            function          = new TrapezoidalFunction(60, 70, 80, 90);
            hightStrenght     = new FuzzySet("Hight", function);
            function          = new TrapezoidalFunction(80, 90, TrapezoidalFunction.EdgeType.Left);
            veryHightStrenght = new FuzzySet("VeryHight", function);
        }
        internal void Defuzzify_WithTriangle_ReturnsExpectedResult()
        {
            // Arrange
            var fuzzySet = new FuzzySet("centre", TriangularFunction.Create(-1, 0, 1));

            var fuzzyOutput = new List <FuzzyOutput>
            {
                new FuzzyOutput(
                    Label.Create("Balance"),
                    fuzzySet,
                    UnitInterval.Create(0.5))
            };

            var centroidDefuzzifier = new CentroidDefuzzifier();

            // Act
            var result = centroidDefuzzifier.Defuzzify(fuzzyOutput);

            // Assert
            Assert.Equal("Balance", result.Subject.Value);
            Assert.Equal(0, result.Value);
        }
        internal void Defuzzify_WhenSubjectsUnrelated_Throws()
        {
            // Arrange
            var fuzzySet = new FuzzySet("centre", TriangularFunction.Create(-1, 0, 1));

            var fuzzyOutput = new List <FuzzyOutput>
            {
                new FuzzyOutput(
                    Label.Create("Subject1"),
                    fuzzySet,
                    UnitInterval.One()),
                new FuzzyOutput(
                    Label.Create("Subject2"),
                    fuzzySet,
                    UnitInterval.One())
            };

            var centroidDefuzzifier = new CentroidDefuzzifier();

            // Act
            // Assert
            Assert.Throws <InvalidOperationException>(() => centroidDefuzzifier.Defuzzify(fuzzyOutput));
        }
Ejemplo n.º 22
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string Label = null;
            double A     = double.NaN;

            if (!DA.GetData(0, ref Label))
            {
                return;
            }
            if (!DA.GetData(1, ref A))
            {
                return;
            }

            if (!Rhino.RhinoMath.IsValidDouble(A))
            {
                return;
            }

            FuzzySet fSet = new FuzzySet(Label, new SingletonFunction(
                                             (float)A));

            DA.SetData(0, fSet);
        }
Ejemplo n.º 23
0
        public Variable(VariableConfig config, Chart chart)
        {
            _chart      = chart;
            _range      = config.Range;
            Name        = config.Name;
            Type        = config.Type;
            _sets       = new List <FuzzySet>();
            ResultValue = null;

            foreach (SetConfig setConfig in config.sets)
            {
                IMembershipFunction membershipFunction = null;
                switch (setConfig.Type)
                {
                case SetType.TrapezoidalFunctionCenter:
                    membershipFunction = new TrapezoidalFunction(setConfig.Values[0], setConfig.Values[1], setConfig.Values[2], setConfig.Values[3]);
                    break;

                case SetType.TrapezoidalFunctionLeft:
                    membershipFunction = new TrapezoidalFunction(setConfig.Values[0], setConfig.Values[1], TrapezoidalFunction.EdgeType.Right);
                    break;

                case SetType.TrapezoidalFunctionRight:
                    membershipFunction = new TrapezoidalFunction(setConfig.Values[0], setConfig.Values[1], TrapezoidalFunction.EdgeType.Left);
                    break;

                default:
                    break;
                }

                FuzzySet newSet = new FuzzySet(setConfig.Name, membershipFunction);
                _sets.Add(newSet);
            }

            Initialize();
        }
Ejemplo n.º 24
0
 protected void Train(double[,] trainingData)
 {
     conf  = new double[xList.Count, fiList.Count];
     rules = new FuzzySet[xList.Count, fiList.Count];
     for (int i = 0; i < trainingData.GetLength(0); i++) //для каждой тройки тренировочных данных
     {
         double currX    = trainingData[i, 0];
         double currFi   = trainingData[i, 1];
         double currTeta = trainingData[i, 2];
         for (int a1 = 0; a1 < xList.Count; a1++)
         {
             for (int a2 = 0; a2 < fiList.Count; a2++) //для всех пар нечётких множеств
             {
                 //найдём такое множество из teta, для которого значение функции принадлежности максимально
                 double   maxConfidence = 0;
                 FuzzySet maxConfSet    = null;
                 foreach (FuzzySet set in tetaList) //для каждого выходного нечёткого множества
                 {
                     double currConf = set.GetConfidence(currTeta);
                     if (currConf > maxConfidence)
                     {
                         maxConfidence = currConf;
                         maxConfSet    = set;
                     }
                 }
                 //степень истинности правила
                 maxConfidence *= xList[a1].GetConfidence(currX) * fiList[a2].GetConfidence(currFi);
                 if (conf[a1, a2] < maxConfidence)  //если степень истинности больше текущей
                 {
                     conf[a1, a2]  = maxConfidence; //обновим степень принадлежности
                     rules[a1, a2] = maxConfSet;    //обновим правило
                 }
             }
         }
     }
 }
Ejemplo n.º 25
0
 ///<summary>
 ///constructor
 ///</summary>
 ///<param name="fs"></param>
 public FzSet(FuzzySet fs)
 {
     _set = fs;
 }
Ejemplo n.º 26
0
    void InitFuzzyEngine()
    {
        //Sunciones de Pertenencia
        //Alturas
        FuzzySet fsBaja  = new FuzzySet("Baja", new TrapezoidalFunction(-1f, 0f, TrapezoidalFunction.EdgeType.Right));
        FuzzySet fsMedia = new FuzzySet("Media", new TrapezoidalFunction(-1f, -0.1f, 0.1f, 1f));
        FuzzySet fsAlta  = new FuzzySet("Alta", new TrapezoidalFunction(0f, 1f, TrapezoidalFunction.EdgeType.Left));
        //Velocidades
        FuzzySet fsMn   = new FuzzySet("Negativa", new TrapezoidalFunction(-1f, -0.5f, TrapezoidalFunction.EdgeType.Right));
        FuzzySet fsZero = new FuzzySet("Media", new TrapezoidalFunction(-1f, -0.5f, 0.5f, 1f));
        FuzzySet fsMp   = new FuzzySet("Positiva", new TrapezoidalFunction(0.5f, 1f, TrapezoidalFunction.EdgeType.Left));
        //Fuerzas
        FuzzySet fsZf = new FuzzySet("PocaFuerza", new TrapezoidalFunction(0f, 1f, TrapezoidalFunction.EdgeType.Right));
        FuzzySet fsPf = new FuzzySet("ZeroFuerza", new TrapezoidalFunction(0.5f, 1f, 9f, 10f));
        FuzzySet fsMf = new FuzzySet("MuchaFuerza", new TrapezoidalFunction(9.5f, 16f, TrapezoidalFunction.EdgeType.Left));


        //Entradas
        //Altura
        LinguisticVariable lvAltura = new LinguisticVariable("Altura", -15, 15);

        lvAltura.AddLabel(fsBaja);
        lvAltura.AddLabel(fsMedia);
        lvAltura.AddLabel(fsAlta);
        //Velocidades
        LinguisticVariable lvVelocidad = new LinguisticVariable("Velocidad", -25, 25);

        lvVelocidad.AddLabel(fsMn);
        lvVelocidad.AddLabel(fsZero);
        lvVelocidad.AddLabel(fsMp);
        //Fuerzas
        LinguisticVariable lvFuerza = new LinguisticVariable("Fuerza", 0, 16);

        lvFuerza.AddLabel(fsPf);
        lvFuerza.AddLabel(fsZf);
        lvFuerza.AddLabel(fsMf);

        //La base de datos
        Database fuzzyDb = new Database();

        fuzzyDb.AddVariable(lvAltura);
        fuzzyDb.AddVariable(lvFuerza);
        fuzzyDb.AddVariable(lvVelocidad);

        //Sistema de interferencia


        ISL = new InferenceSystem(fuzzyDb, new CentroidDefuzzifier(1000));

        ISL.NewRule("Rule 1", "IF Altura IS Baja AND Velocidad IS Negativa THEN Fuerza IS MuchaFuerza");
        ISL.NewRule("Rule 2", "IF Altura IS Baja AND Velocidad IS Media THEN Fuerza IS MuchaFuerza");
        ISL.NewRule("Rule 3", "IF Altura IS Baja AND Velocidad IS Positiva THEN Fuerza IS MuchaFuerza");

        ISL.NewRule("Rule 4", "IF Altura IS Media AND Velocidad IS Negativa THEN Fuerza IS MuchaFuerza");
        ISL.NewRule("Rule 5", "IF Altura IS Media AND Velocidad IS Media THEN Fuerza IS ZeroFuerza");
        ISL.NewRule("Rule 6", "IF Altura IS Media AND Velocidad IS Positiva THEN Fuerza IS ZeroFuerza");

        ISL.NewRule("Rule 7", "IF Altura IS Alta AND Velocidad IS Negativa THEN Fuerza IS ZeroFuerza");
        ISL.NewRule("Rule 8", "IF Altura IS Alta AND Velocidad IS Media THEN Fuerza IS ZeroFuerza");
        ISL.NewRule("Rule 9", "IF Altura IS Alta AND Velocidad IS Positiva THEN Fuerza IS ZeroFuerza");
    }
Ejemplo n.º 27
0
 private FzFairly(FzFairly inst)
 {
     m_Set = inst.m_Set;
 }
Ejemplo n.º 28
0
 public FzFairly(FzSet ft)
 {
     m_Set = ft.m_Set.clone();
 }
        private void bunifuImageButton9_Click(object sender, EventArgs e)
        {
            // Kecepatan (0-120)
            FuzzySet fsLambat = new FuzzySet("Lambat", new TrapezoidalFunction(30, 50, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsSedang = new FuzzySet("Sedang", new TrapezoidalFunction(40, 60, 80));
            FuzzySet fsCepat  = new FuzzySet("Cepat", new TrapezoidalFunction(70, 80, TrapezoidalFunction.EdgeType.Left));
            // Linguistik Kecepatan
            LinguisticVariable lvKecepatan = new LinguisticVariable("Kecepatan", 0, 120);

            lvKecepatan.AddLabel(fsLambat);
            lvKecepatan.AddLabel(fsSedang);
            lvKecepatan.AddLabel(fsCepat);

            // Jarak (0-10)
            FuzzySet fsDekat      = new FuzzySet("Dekat", new TrapezoidalFunction(1, 2, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsJauh       = new FuzzySet("Jauh", new TrapezoidalFunction(1, 4, 5));
            FuzzySet fsSangatJauh = new FuzzySet("SangatJauh", new TrapezoidalFunction(4, 7, TrapezoidalFunction.EdgeType.Left));
            // Linguistik Jarak
            LinguisticVariable lvJarak = new LinguisticVariable("Jarak", 0, 10);

            lvJarak.AddLabel(fsDekat);
            lvJarak.AddLabel(fsJauh);
            lvJarak.AddLabel(fsSangatJauh);

            // Kemiringan Jalan ((-90)-90)
            FuzzySet fsTurun = new FuzzySet("Turun", new TrapezoidalFunction(-40, -20, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsDatar = new FuzzySet("Datar", new TrapezoidalFunction(-25, 0, 25));
            FuzzySet fsNaik  = new FuzzySet("Naik", new TrapezoidalFunction(20, 40, TrapezoidalFunction.EdgeType.Left));
            // Linguistik Kemiringan Jalan
            LinguisticVariable lvKemiringan = new LinguisticVariable("Kemiringan", -90, 90);

            lvKemiringan.AddLabel(fsTurun);
            lvKemiringan.AddLabel(fsDatar);
            lvKemiringan.AddLabel(fsNaik);

            // OUTPUT

            // Tingkat Pengereman (0-10)
            FuzzySet fsLemah  = new FuzzySet("Lemah", new TrapezoidalFunction(3, 4, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsMedium = new FuzzySet("Sedang", new TrapezoidalFunction(3, 4, 6, 7));
            FuzzySet fsKuat   = new FuzzySet("Kuat", new TrapezoidalFunction(6, 7, TrapezoidalFunction.EdgeType.Left));
            // Linguistik Kecepatan
            LinguisticVariable lvTingkatPengereman = new LinguisticVariable("TingkatPengereman", 0, 10);

            lvTingkatPengereman.AddLabel(fsLemah);
            lvTingkatPengereman.AddLabel(fsMedium);
            lvTingkatPengereman.AddLabel(fsKuat);

            // Database
            Database fuzzyDB = new Database();

            fuzzyDB.AddVariable(lvJarak);
            fuzzyDB.AddVariable(lvKemiringan);
            fuzzyDB.AddVariable(lvKecepatan);
            fuzzyDB.AddVariable(lvTingkatPengereman);

            // Inferensi System Engine
            InferenceSystem IS = new InferenceSystem(fuzzyDB, new CentroidDefuzzifier(1000));

            // Rules
            IS.NewRule("Rule 1", "IF Kecepatan IS Lambat AND Jarak IS Dekat AND Kemiringan IS Turun THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 2", "IF Kecepatan IS Lambat AND Jarak IS Dekat AND Kemiringan IS Naik THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 3", "IF Kecepatan IS Lambat AND Jarak IS Dekat AND Kemiringan IS Datar THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 4", "IF Kecepatan IS Lambat AND Jarak IS Jauh AND Kemiringan IS Datar THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 5", "IF Kecepatan IS Lambat AND Jarak IS Jauh AND Kemiringan IS Naik THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 6", "IF Kecepatan IS Lambat AND Jarak IS Jauh AND Kemiringan IS Turun THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 7", "IF Kecepatan IS Lambat AND Jarak IS SangatJauh AND Kemiringan IS Datar THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 8", "IF Kecepatan IS Lambat AND Jarak IS SangatJauh AND Kemiringan IS Naik THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 9", "IF Kecepatan IS Lambat AND Jarak IS SangatJauh AND Kemiringan IS Turun THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 10", "IF Kecepatan IS Sedang AND Jarak IS Dekat AND Kemiringan IS Datar THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 11", "IF Kecepatan IS Sedang AND Jarak IS Dekat AND Kemiringan IS Naik THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 12", "IF Kecepatan IS Sedang AND Jarak IS Dekat AND Kemiringan IS Turun THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 13", "IF Kecepatan IS Sedang AND Jarak IS Jauh AND Kemiringan IS Datar THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 14", "IF Kecepatan IS Sedang AND Jarak IS Jauh AND Kemiringan IS Naik THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 15", "IF Kecepatan IS Sedang AND Jarak IS Jauh AND Kemiringan IS Turun THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 16", "IF Kecepatan IS Sedang AND Jarak IS SangatJauh AND Kemiringan IS Datar THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 17", "IF Kecepatan IS Sedang AND Jarak IS SangatJauh AND Kemiringan IS Naik THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 18", "IF Kecepatan IS Sedang AND Jarak IS SangatJauh AND Kemiringan IS Turun THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 19", "IF Kecepatan IS Cepat AND Jarak IS Dekat AND Kemiringan IS Datar THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 20", "IF Kecepatan IS Cepat AND Jarak IS Dekat AND Kemiringan IS Naik THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 21", "IF Kecepatan IS Cepat AND Jarak IS Dekat AND Kemiringan IS Turun THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 22", "IF Kecepatan IS Cepat AND Jarak IS Jauh AND Kemiringan IS Datar THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 23", "IF Kecepatan IS Cepat AND Jarak IS Jauh AND Kemiringan IS Naik THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 24", "IF Kecepatan IS Cepat AND Jarak IS Jauh AND Kemiringan IS Turun THEN TingkatPengereman IS Kuat");
            IS.NewRule("Rule 25", "IF Kecepatan IS Cepat AND Jarak IS SangatJauh AND Kemiringan IS Datar THEN TingkatPengereman IS Sedang");
            IS.NewRule("Rule 26", "IF Kecepatan IS Cepat AND Jarak IS SangatJauh AND Kemiringan IS Naik THEN TingkatPengereman IS Lemah");
            IS.NewRule("Rule 27", "IF Kecepatan IS Cepat AND Jarak IS SangatJauh AND Kemiringan IS Turun THEN TingkatPengereman IS Kuat");

            // Set Input

            IS.SetInput("Kecepatan", (float)Convert.ToDouble(TB_Speed.Value));
            IS.SetInput("Jarak", (float)Convert.ToDouble(TB_Distance.Value));
            if (TB_AngleMin.Value != 0)
            {
                IS.SetInput("Kemiringan", (float)Convert.ToDouble(TB_AngleMin.Value));
            }
            IS.SetInput("Kemiringan", (float)Convert.ToDouble(TB_AnglePlus.Value));

            // Get output
            double BrakeLevel = IS.Evaluate("TingkatPengereman");

            if (TB_Speed.Value == 0 && TB_Distance.Value == 0 && TB_AngleMin.Value == 0 && TB_AnglePlus.Value == 0)
            {
                BrakeLevel         = 0;
                Gauge_Break.Value  = Convert.ToInt32(BrakeLevel * 10);
                lblvalueBrake.Text = Convert.ToString(Math.Ceiling(BrakeLevel));
            }
            else
            {
                Gauge_Break.Value = Convert.ToInt32(BrakeLevel * 10);
            }
            lblvalueBrake.Text = Convert.ToString(Math.Ceiling(BrakeLevel));
        }
    //Definición del sistema de lógica difusa
    void InitFuzzyEngine()
    {
        //Funciones de Pertenencia
        //Demanda
        FuzzySet fsBaja  = new FuzzySet("Baja", new TrapezoidalFunction(2f, 4f, TrapezoidalFunction.EdgeType.Right));
        FuzzySet fsMedia = new FuzzySet("Media", new TrapezoidalFunction(3f, 5f, 7f));
        FuzzySet fsAlta  = new FuzzySet("Alta", new TrapezoidalFunction(6f, 8f, TrapezoidalFunction.EdgeType.Left));
        //Disponible
        FuzzySet fsPoco   = new FuzzySet("Poco", new TrapezoidalFunction(4f, 8f, TrapezoidalFunction.EdgeType.Right));
        FuzzySet fsNormal = new FuzzySet("Normal", new TrapezoidalFunction(6f, 10f, 14f));
        FuzzySet fsMucho  = new FuzzySet("Mucho", new TrapezoidalFunction(12f, 16f, TrapezoidalFunction.EdgeType.Left));
        //Fuerzas
        FuzzySet fsPbaja  = new FuzzySet("Pbaja", new TrapezoidalFunction(0.1f, 0.2f, TrapezoidalFunction.EdgeType.Right));
        FuzzySet fsPmedia = new FuzzySet("Pmedia", new TrapezoidalFunction(0.3f, 0.5f, 0.7f));
        FuzzySet fsPalta  = new FuzzySet("Palta", new TrapezoidalFunction(0.6f, 0.8f, TrapezoidalFunction.EdgeType.Left));


        //Entradas
        //Altura
        LinguisticVariable lvDemanda = new LinguisticVariable("Demanda", 0, 10);

        lvDemanda.AddLabel(fsBaja);
        lvDemanda.AddLabel(fsMedia);
        lvDemanda.AddLabel(fsAlta);
        //Velocidades
        LinguisticVariable lvDisponible = new LinguisticVariable("Disponible", 0, 20);

        lvDisponible.AddLabel(fsPoco);
        lvDisponible.AddLabel(fsNormal);
        lvDisponible.AddLabel(fsMucho);
        //Fuerzas
        LinguisticVariable lvFuerza = new LinguisticVariable("Prioridad", 0, 1);

        lvFuerza.AddLabel(fsPbaja);
        lvFuerza.AddLabel(fsPmedia);
        lvFuerza.AddLabel(fsPalta);

        //La base de datos
        Database fuzzyDb = new Database();

        fuzzyDb.AddVariable(lvDemanda);
        fuzzyDb.AddVariable(lvFuerza);
        fuzzyDb.AddVariable(lvDisponible);

        //Sistema de interferencia


        ISL = new InferenceSystem(fuzzyDb, new CentroidDefuzzifier(800));

        //Definicion de reglas

        ISL.NewRule("Rule 1", "IF Demanda IS Baja AND Disponible IS Poco THEN Prioridad IS Pmedia");
        ISL.NewRule("Rule 2", "IF Demanda IS Baja AND Disponible IS Normal THEN Prioridad IS Pbaja");
        ISL.NewRule("Rule 3", "IF Demanda IS Baja AND Disponible IS Mucho THEN Prioridad IS Pbaja");

        ISL.NewRule("Rule 4", "IF Demanda IS Media AND Disponible IS Poco THEN Prioridad IS Palta");
        ISL.NewRule("Rule 5", "IF Demanda IS Media AND Disponible IS Normal THEN Prioridad IS Pbaja");
        ISL.NewRule("Rule 6", "IF Demanda IS Media AND Disponible IS Mucho THEN Prioridad IS Pbaja");

        ISL.NewRule("Rule 7", "IF Demanda IS Alta AND Disponible IS Poco THEN Prioridad IS Palta");
        ISL.NewRule("Rule 8", "IF Demanda IS Alta AND Disponible IS Normal THEN Prioridad IS Pmedia");
        ISL.NewRule("Rule 9", "IF Demanda IS Alta AND Disponible IS Mucho THEN Prioridad IS Pbaja");
    }
Ejemplo n.º 31
0
        private void InitFuzzyEngineFor8Person()
        {
            //Superficie Captacion SC
            FuzzySet scChico = new FuzzySet("Chico", new TrapezoidalFunction(300, 400, TrapezoidalFunction.EdgeType.Right));
            FuzzySet scMediano = new FuzzySet("Mediano", new TrapezoidalFunction(300, 500, 700));
            FuzzySet scGrande = new FuzzySet("Grande", new TrapezoidalFunction(500, 700, 900));
            FuzzySet scMuyGrande = new FuzzySet("MuyGrande", new TrapezoidalFunction(800, 1000, TrapezoidalFunction.EdgeType.Left));

            LinguisticVariable lvSuperficieCaptacion = new LinguisticVariable("SC", 0, 1200);
            lvSuperficieCaptacion.AddLabel(scChico);
            lvSuperficieCaptacion.AddLabel(scMediano);
            lvSuperficieCaptacion.AddLabel(scGrande);
            lvSuperficieCaptacion.AddLabel(scMuyGrande);

            //volumen del sistema de almacenamiento VA
            FuzzySet vaPequenio = new FuzzySet("Pequenio", new TrapezoidalFunction(30, 40, TrapezoidalFunction.EdgeType.Right));
            FuzzySet vaIntermedio = new FuzzySet("Intermedio", new TrapezoidalFunction(30, 50, 70));
            FuzzySet vaConsiderable = new FuzzySet("Considerable", new TrapezoidalFunction(60, 70, TrapezoidalFunction.EdgeType.Left));

            LinguisticVariable lvVolumenAlmacenamiento = new LinguisticVariable("VA", 0, 100);
            lvVolumenAlmacenamiento.AddLabel(vaPequenio);
            lvVolumenAlmacenamiento.AddLabel(vaIntermedio);
            lvVolumenAlmacenamiento.AddLabel(vaConsiderable);

            //precipitaciones pluviales PP
            FuzzySet ppMuyBaja = new FuzzySet("MuyBaja", new TrapezoidalFunction(20, 40, TrapezoidalFunction.EdgeType.Right));
            FuzzySet ppBaja = new FuzzySet("Baja", new TrapezoidalFunction(20, 40, 60));
            FuzzySet ppMedia = new FuzzySet("Media", new TrapezoidalFunction(40, 70, 100));
            FuzzySet ppAlta = new FuzzySet("Alta", new TrapezoidalFunction(80, 130, 180));
            FuzzySet ppMuyAlta = new FuzzySet("MuyAlta", new TrapezoidalFunction(150, 180, TrapezoidalFunction.EdgeType.Left));

            LinguisticVariable lvPrecipitacionesPluviales = new LinguisticVariable("PP", 0, 300);
            lvPrecipitacionesPluviales.AddLabel(ppMuyBaja);
            lvPrecipitacionesPluviales.AddLabel(ppBaja);
            lvPrecipitacionesPluviales.AddLabel(ppMedia);
            lvPrecipitacionesPluviales.AddLabel(ppAlta);
            lvPrecipitacionesPluviales.AddLabel(ppMuyAlta);

            //consumo C (OUTPUT)
            FuzzySet cBajo = new FuzzySet("Bajo", new TrapezoidalFunction(4000, 4400, TrapezoidalFunction.EdgeType.Right));
            FuzzySet cPromedio = new FuzzySet("Promedio", new TrapezoidalFunction(4000, 4400, 5000));
            FuzzySet dAlto = new FuzzySet("Alto", new TrapezoidalFunction(4600, 5000, TrapezoidalFunction.EdgeType.Left));

            LinguisticVariable lvConsumo = new LinguisticVariable("C", 0, 6000);
            lvConsumo.AddLabel(cBajo);
            lvConsumo.AddLabel(cPromedio);
            lvConsumo.AddLabel(dAlto);

            Database fuzzyDB = new Database();
            fuzzyDB.AddVariable(lvSuperficieCaptacion);
            fuzzyDB.AddVariable(lvVolumenAlmacenamiento);
            fuzzyDB.AddVariable(lvPrecipitacionesPluviales);
            fuzzyDB.AddVariable(lvConsumo);

            CentroidDefuzzifier centroide = new CentroidDefuzzifier(1000);
            SetInferenceSystemAndRules(GetInferenceSystemIndex(8), fuzzyDB, centroide);
        }
Ejemplo n.º 32
0
        // initialization of the Fuzzy Inference System
        public static void InitFuzzyEngine()
        {
            // linguistic labels (fuzzy sets) that compose the distances
            FuzzySet fsNear = new FuzzySet("Near", new TrapezoidalFunction(
                15, 50, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsMedium = new FuzzySet("Medium", new TrapezoidalFunction(
                15, 50, 60, 100));
            FuzzySet fsFar = new FuzzySet("Far", new TrapezoidalFunction(
                60, 100, TrapezoidalFunction.EdgeType.Left));

            // right Distance (Input)
            LinguisticVariable lvRight = new LinguisticVariable("RightDistance", 0, 120);
            lvRight.AddLabel(fsNear);
            lvRight.AddLabel(fsMedium);
            lvRight.AddLabel(fsFar);

            // left Distance (Input)
            LinguisticVariable lvLeft = new LinguisticVariable("LeftDistance", 0, 120);
            lvLeft.AddLabel(fsNear);
            lvLeft.AddLabel(fsMedium);
            lvLeft.AddLabel(fsFar);

            // front Distance (Input)
            LinguisticVariable lvFront = new LinguisticVariable("FrontalDistance", 0, 120);
            lvFront.AddLabel(fsNear);
            lvFront.AddLabel(fsMedium);
            lvFront.AddLabel(fsFar);

            // linguistic labels (fuzzy sets) that compose the angle
            FuzzySet fsVN = new FuzzySet("VeryNegative", new TrapezoidalFunction(
                -40, -35, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsN = new FuzzySet("Negative", new TrapezoidalFunction(
                -40, -35, -25, -20));
            FuzzySet fsLN = new FuzzySet("LittleNegative", new TrapezoidalFunction(
                -25, -20, -10, -5));
            FuzzySet fsZero = new FuzzySet("Zero", new TrapezoidalFunction(
                -10, 5, 5, 10));
            FuzzySet fsLP = new FuzzySet("LittlePositive", new TrapezoidalFunction(
                5, 10, 20, 25));
            FuzzySet fsP = new FuzzySet("Positive", new TrapezoidalFunction(
                20, 25, 35, 40));
            FuzzySet fsVP = new FuzzySet("VeryPositive", new TrapezoidalFunction(
                35, 40, TrapezoidalFunction.EdgeType.Left));

            // angle
            LinguisticVariable lvAngle = new LinguisticVariable("Angle", -50, 50);
            lvAngle.AddLabel(fsVN);
            lvAngle.AddLabel(fsN);
            lvAngle.AddLabel(fsLN);
            lvAngle.AddLabel(fsZero);
            lvAngle.AddLabel(fsLP);
            lvAngle.AddLabel(fsP);
            lvAngle.AddLabel(fsVP);

            // the database
            Database fuzzyDB = new Database();
            fuzzyDB.AddVariable(lvFront);
            fuzzyDB.AddVariable(lvLeft);
            fuzzyDB.AddVariable(lvRight);
            fuzzyDB.AddVariable(lvAngle);

            // creating the inference system
            IS = new InferenceSystem(fuzzyDB, new CentroidDefuzzifier(1000));

            // going Straight
            IS.NewRule("Rule 1", "IF FrontalDistance IS Far THEN Angle IS Zero");
            // going Straight (if can go anywhere)
            IS.NewRule("Rule 2", "IF FrontalDistance IS Far AND RightDistance IS Far AND " +
                "LeftDistance IS Far THEN Angle IS Zero");
            // near right wall
            IS.NewRule("Rule 3", "IF RightDistance IS Near AND LeftDistance IS Medium " +
                "THEN Angle IS LittleNegative");
            // near left wall
            IS.NewRule("Rule 4", "IF RightDistance IS Medium AND LeftDistance IS Near " +
                "THEN Angle IS LittlePositive");
            // near front wall - room at right
            IS.NewRule("Rule 5", "IF RightDistance IS Far AND FrontalDistance IS Near " +
                "THEN Angle IS Positive");
            // near front wall - room at left
            IS.NewRule("Rule 6", "IF LeftDistance IS Far AND FrontalDistance IS Near " +
                "THEN Angle IS Negative");
            // near front wall - room at both sides - go right
            IS.NewRule("Rule 7", "IF RightDistance IS Far AND LeftDistance IS Far AND " +
                "FrontalDistance IS Near THEN Angle IS Positive");
        }
Ejemplo n.º 33
0
        private static InferenceSystem CreateInferenceSystem()
        {
            var objectiveVariable      = new LinguisticVariable("OBJECTIVE", 0, 1);
            var subjectiveVariable     = new LinguisticVariable("SUBJECTIVE", 0, 1);
            var algorithmScoreVariable = new LinguisticVariable("ALGORITHM_SCORE", 0, 1);


            var objectiveLow    = new ZTypeMembership(0, 0.5);
            var objectiveMedium = new PITypeMembership(0, 0.5, 0.75);
            var objectiveHigh   = new STypeMembership(0.25, 1);

            var subjectiveLow    = new ZTypeMembership(0, 0.5);
            var subjectiveMedium = new PITypeMembership(0.25, 0.5, 0.75);
            var subjectiveHigh   = new STypeMembership(0.5, 1);

            var algorithmScoreVeryLow  = new VeryHedge(new ZTypeMembership(0, 0.5));
            var algorithmScoreLow      = new ZTypeMembership(0, 0.5);
            var algorithmScoreMedium   = new PITypeMembership(0.25, 0.5, 0.75);
            var algorithmScoreHigh     = new STypeMembership(0.5, 1);
            var algorithmScoreVeryHigh = new VeryHedge(new STypeMembership(0.5, 1));


            var objectiveLowSet    = new FuzzySet("LOW", objectiveLow);
            var objectiveMediumSet = new FuzzySet("MEDIUM", objectiveMedium);
            var objectiveHighSet   = new FuzzySet("HIGH", objectiveHigh);

            var subjectiveLowSet    = new FuzzySet("LOW", subjectiveLow);
            var subjectiveMediumSet = new FuzzySet("MEDIUM", subjectiveMedium);
            var subjectiveHighSet   = new FuzzySet("HIGH", subjectiveHigh);

            var resultVeryLowSet  = new FuzzySet("VERY_LOW", algorithmScoreVeryLow);
            var resultLowSet      = new FuzzySet("LOW", algorithmScoreLow);
            var resultMediumSet   = new FuzzySet("MEDIUM", algorithmScoreMedium);
            var resultHighSet     = new FuzzySet("HIGH", algorithmScoreHigh);
            var resultVeryHighSet = new FuzzySet("VERY_HIGH", algorithmScoreVeryHigh);


            objectiveVariable.AddLabel(objectiveLowSet);
            objectiveVariable.AddLabel(objectiveMediumSet);
            objectiveVariable.AddLabel(objectiveHighSet);
            subjectiveVariable.AddLabel(subjectiveLowSet);
            subjectiveVariable.AddLabel(subjectiveMediumSet);
            subjectiveVariable.AddLabel(subjectiveHighSet);
            algorithmScoreVariable.AddLabel(resultVeryLowSet);
            algorithmScoreVariable.AddLabel(resultLowSet);
            algorithmScoreVariable.AddLabel(resultMediumSet);
            algorithmScoreVariable.AddLabel(resultHighSet);
            algorithmScoreVariable.AddLabel(resultVeryHighSet);

            var rulebase = new Database();

            rulebase.AddVariable(objectiveVariable);
            rulebase.AddVariable(subjectiveVariable);
            rulebase.AddVariable(algorithmScoreVariable);

            var inferenceSystem = new InferenceSystem(rulebase, new CentroidDefuzzifier(30));

            inferenceSystem.NewRule("Rule1", "if OBJECTIVE is LOW and SUBJECTIVE is LOW then ALGORITHM_SCORE is VERY_LOW ");
            inferenceSystem.NewRule("Rule2", "if OBJECTIVE is LOW and SUBJECTIVE is MEDIUM then ALGORITHM_SCORE is LOW");
            inferenceSystem.NewRule("Rule3", "if OBJECTIVE is LOW and SUBJECTIVE is HIGH then ALGORITHM_SCORE is MEDIUM");
            inferenceSystem.NewRule("Rule4", "if OBJECTIVE is MEDIUM and SUBJECTIVE is LOW then ALGORITHM_SCORE is LOW");
            inferenceSystem.NewRule("Rule5", "if OBJECTIVE is MEDIUM and SUBJECTIVE is MEDIUM then ALGORITHM_SCORE is MEDIUM");
            inferenceSystem.NewRule("Rule6", "if OBJECTIVE is MEDIUM and SUBJECTIVE is HIGH then ALGORITHM_SCORE is HIGH");
            inferenceSystem.NewRule("Rule7", "if OBJECTIVE is HIGH and SUBJECTIVE is LOW then ALGORITHM_SCORE is MEDIUM");
            inferenceSystem.NewRule("Rule8", "if OBJECTIVE is HIGH and SUBJECTIVE is MEDIUM then ALGORITHM_SCORE is HIGH");
            inferenceSystem.NewRule("Rule9", "if OBJECTIVE is HIGH and SUBJECTIVE is HIGH then ALGORITHM_SCORE is VERY_HIGH");

            return(inferenceSystem);
        }
Ejemplo n.º 34
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Clause"/> class.
 /// </summary>
 /// 
 /// <param name="variable">Linguistic variable of the clause. </param>
 /// 
 /// <param name="label">Label of the linguistic variable, a fuzzy set used as label into the linguistic variable.</param>
 /// 
 /// <exception cref="KeyNotFoundException">The label indicated was not found in the linguistic variable.</exception>
 /// 
 public Clause( LinguisticVariable variable, FuzzySet label )
 {
     // check if label belongs to var.
     variable.GetLabel( label.Name );
     
     // initializing attributes
     this.label    = label;
     this.variable = variable;
 }
Ejemplo n.º 35
0
 ///<summary>
 ///copy
 ///</summary>
 ///<param name="src"></param>
 private FzVery(FzVery src)
 {
     _set = src.Set;
 }
Ejemplo n.º 36
0
 ///<summary>
 ///constructor
 ///</summary>
 ///<param name="ft"></param>
 public FzVery(FzSet ft)
 {
     _set = ft.Set;
 }
Ejemplo n.º 37
0
 public SimpleRule(FuzzySet x, FuzzySet fi, FuzzySet teta)
 {
     this.teta = teta;
     premise   = x.CartesianProduct(fi, OperationType.MinMax);
 }
Ejemplo n.º 38
0
        public static void InitFuzzyEngineDiagnosis2()
        {
            FuzzySet fsCommon0 = new FuzzySet("Common0", new TrapezoidalFunction(-50, -25, 0, 5));
            FuzzySet fsCommon = new FuzzySet("Common", new TrapezoidalFunction(0, 35, 70, 100));

            //IF PAD IS Common AND OS IS Common AND G IS Common AND SHVG IS Common AND VGBHYVG IS Common AND GBPDKH IS Common
            //AND NK IS Common AND US IS Common AND GBVZO IS Common AND GBVO IS Common AND GBVI IS Common AND MMPG IS Common
            //AND NRRSRKH IS Common
            //THEN Diagnosis IS Diagnosis1

            // right Distance (Input)
            LinguisticVariable SN = new LinguisticVariable("SN", -50, 100);
            SN.AddLabel(fsCommon0);
            SN.AddLabel(fsCommon);
            LinguisticVariable PAD = new LinguisticVariable("PAD", -50, 100);
            PAD.AddLabel(fsCommon0);
            PAD.AddLabel(fsCommon);
            LinguisticVariable OS = new LinguisticVariable("OS", -50, 100);
            OS.AddLabel(fsCommon0);
            OS.AddLabel(fsCommon);
            LinguisticVariable G = new LinguisticVariable("G", -50, 100);
            G.AddLabel(fsCommon0);
            G.AddLabel(fsCommon);
            LinguisticVariable SHVG = new LinguisticVariable("SHVG", -50, 100);
            SHVG.AddLabel(fsCommon0);
            SHVG.AddLabel(fsCommon);
            LinguisticVariable VGBHYVG = new LinguisticVariable("VGBHYVG", -50, 100);
            VGBHYVG.AddLabel(fsCommon0);
            VGBHYVG.AddLabel(fsCommon);
            LinguisticVariable GBPDKH = new LinguisticVariable("GBPDKH", -50, 100);
            GBPDKH.AddLabel(fsCommon0);
            GBPDKH.AddLabel(fsCommon);
            LinguisticVariable NK = new LinguisticVariable("NK", -50, 100);
            NK.AddLabel(fsCommon0);
            NK.AddLabel(fsCommon);
            LinguisticVariable US = new LinguisticVariable("US", -50, 100);
            US.AddLabel(fsCommon0);
            US.AddLabel(fsCommon);
            LinguisticVariable GBVZO = new LinguisticVariable("GBVZO", -50, 100);
            GBVZO.AddLabel(fsCommon0);
            GBVZO.AddLabel(fsCommon);
            LinguisticVariable GBVO = new LinguisticVariable("GBVO", -50, 100);
            GBVO.AddLabel(fsCommon0);
            GBVO.AddLabel(fsCommon);
            LinguisticVariable GBVI = new LinguisticVariable("GBVI", -50, 100);
            GBVI.AddLabel(fsCommon0);
            GBVI.AddLabel(fsCommon);
            LinguisticVariable MMPG = new LinguisticVariable("MMPG", -50, 100);
            MMPG.AddLabel(fsCommon0);
            MMPG.AddLabel(fsCommon);
            LinguisticVariable NRRSRKH = new LinguisticVariable("NRRSRKH", -50, 100);
            NRRSRKH.AddLabel(fsCommon0);
            NRRSRKH.AddLabel(fsCommon);

            // linguistic labels (fuzzy sets) that compose the angle
            FuzzySet fsVN = new FuzzySet("Diagnosis1", new TrapezoidalFunction(0, 50, 50, 100));
            // linguistic labels (fuzzy sets) that compose the angle
            FuzzySet fsVN2 = new FuzzySet("Diagnosis2", new TrapezoidalFunction(100, 150, 150, 200));
            // angle
            LinguisticVariable diagnosis = new LinguisticVariable("Diagnosis", 0, 200);
            diagnosis.AddLabel(fsVN);
            diagnosis.AddLabel(fsVN2);

            // the database
            Database fuzzyDB = new Database();
            fuzzyDB.AddVariable(SN);
            fuzzyDB.AddVariable(PAD);
            fuzzyDB.AddVariable(OS);
            fuzzyDB.AddVariable(G);
            fuzzyDB.AddVariable(SHVG);
            fuzzyDB.AddVariable(VGBHYVG);
            fuzzyDB.AddVariable(GBPDKH);
            fuzzyDB.AddVariable(NK);
            fuzzyDB.AddVariable(US);
            fuzzyDB.AddVariable(GBVZO);
            fuzzyDB.AddVariable(GBVO);
            fuzzyDB.AddVariable(GBVI);
            fuzzyDB.AddVariable(MMPG);
            fuzzyDB.AddVariable(NRRSRKH);
            fuzzyDB.AddVariable(diagnosis);

            // creating the inference system
            IS = new InferenceSystem(fuzzyDB, new CentroidDefuzzifier(1000));

            //// going Straight
            //IS.NewRule("Rule 1", @"IF PAD IS Common AND OS IS Common
            //THEN Diagnosis IS Diagnosis1");
            //IS.NewRule("Rule 2", @"IF SN IS Common
            //THEN Diagnosis IS Diagnosis2");

            // going Straight
            IS.NewRule("Rule 1", @"IF PAD IS Common AND OS IS Common AND G IS Common AND SHVG IS Common
                AND VGBHYVG IS Common AND GBPDKH IS Common AND NK IS Common AND US IS Common
                AND GBVZO IS Common AND GBVO IS Common AND GBVI IS Common AND MMPG IS Common AND NRRSRKH IS Common
                THEN Diagnosis IS Diagnosis1");
            IS.NewRule("Rule 2", @"IF VGBHYVG IS Common AND GBPDKH IS Common AND GBVZO IS Common AND GBVO IS Common AND SN IS Common
                THEN Diagnosis IS Diagnosis2");

            //// going Straight
            //IS.NewRule("Rule 1", "IF FrontalDistance IS Far THEN Angle IS Zero");
            //// going Straight (if can go anywhere)
            //IS.NewRule("Rule 2", "IF FrontalDistance IS Far AND RightDistance IS Far AND " +
            //    "LeftDistance IS Far THEN Angle IS Zero");
            //// near right wall
            //IS.NewRule("Rule 3", "IF RightDistance IS Near AND LeftDistance IS Medium " +
            //    "THEN Angle IS LittleNegative");
            //// near left wall
            //IS.NewRule("Rule 4", "IF RightDistance IS Medium AND LeftDistance IS Near " +
            //    "THEN Angle IS LittlePositive");
            //// near front wall - room at right
            //IS.NewRule("Rule 5", "IF RightDistance IS Far AND FrontalDistance IS Near " +
            //    "THEN Angle IS Positive");
            //// near front wall - room at left
            //IS.NewRule("Rule 6", "IF LeftDistance IS Far AND FrontalDistance IS Near " +
            //    "THEN Angle IS Negative");
            //// near front wall - room at both sides - go right
            //IS.NewRule("Rule 7", "IF RightDistance IS Far AND LeftDistance IS Far AND " +
            //    "FrontalDistance IS Near THEN Angle IS Positive");
        }
Ejemplo n.º 39
0
        // Hardcode initializing the Fuzzy Inference System
        void InitFuzzyEngine( )
        {
            // Linguistic labels (fuzzy sets) that compose the distances
            FuzzySet fsNear   = new FuzzySet("Near", new TrapezoidalFunction(15, 50, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsMedium = new FuzzySet("Medium", new TrapezoidalFunction(15, 50, 60, 100));
            FuzzySet fsFar    = new FuzzySet("Far", new TrapezoidalFunction(60, 100, TrapezoidalFunction.EdgeType.Left));

            // Right Distance (Input)
            LinguisticVariable lvRight = new LinguisticVariable("RightDistance", 0, 120);

            lvRight.AddLabel(fsNear);
            lvRight.AddLabel(fsMedium);
            lvRight.AddLabel(fsFar);

            // Left Distance (Input)
            LinguisticVariable lvLeft = new LinguisticVariable("LeftDistance", 0, 120);

            lvLeft.AddLabel(fsNear);
            lvLeft.AddLabel(fsMedium);
            lvLeft.AddLabel(fsFar);

            // Front Distance (Input)
            LinguisticVariable lvFront = new LinguisticVariable("FrontalDistance", 0, 120);

            lvFront.AddLabel(fsNear);
            lvFront.AddLabel(fsMedium);
            lvFront.AddLabel(fsFar);

            // Linguistic labels (fuzzy sets) that compose the angle
            FuzzySet fsVN   = new FuzzySet("VeryNegative", new TrapezoidalFunction(-40, -35, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsN    = new FuzzySet("Negative", new TrapezoidalFunction(-40, -35, -25, -20));
            FuzzySet fsLN   = new FuzzySet("LittleNegative", new TrapezoidalFunction(-25, -20, -10, -5));
            FuzzySet fsZero = new FuzzySet("Zero", new TrapezoidalFunction(-10, 5, 5, 10));
            FuzzySet fsLP   = new FuzzySet("LittlePositive", new TrapezoidalFunction(5, 10, 20, 25));
            FuzzySet fsP    = new FuzzySet("Positive", new TrapezoidalFunction(20, 25, 35, 40));
            FuzzySet fsVP   = new FuzzySet("VeryPositive", new TrapezoidalFunction(35, 40, TrapezoidalFunction.EdgeType.Left));

            // Angle
            LinguisticVariable lvAngle = new LinguisticVariable("Angle", -50, 50);

            lvAngle.AddLabel(fsVN);
            lvAngle.AddLabel(fsN);
            lvAngle.AddLabel(fsLN);
            lvAngle.AddLabel(fsZero);
            lvAngle.AddLabel(fsLP);
            lvAngle.AddLabel(fsP);
            lvAngle.AddLabel(fsVP);

            // The database
            Database fuzzyDB = new Database( );

            fuzzyDB.AddVariable(lvFront);
            fuzzyDB.AddVariable(lvLeft);
            fuzzyDB.AddVariable(lvRight);
            fuzzyDB.AddVariable(lvAngle);

            // Creating the inference system
            IS = new InferenceSystem(fuzzyDB, new CentroidDefuzzifier(1000));

            // Going Straight
            IS.NewRule("Rule 1", "IF FrontalDistance IS Far THEN Angle IS Zero");
            // Going Straight (if can go anywhere)
            IS.NewRule("Rule 2", "IF FrontalDistance IS Far AND RightDistance IS Far AND LeftDistance IS Far THEN Angle IS Zero");
            // Near right wall
            IS.NewRule("Rule 3", "IF RightDistance IS Near AND LeftDistance IS Not Near THEN Angle IS LittleNegative");
            // Near left wall
            IS.NewRule("Rule 4", "IF RightDistance IS Not Near AND LeftDistance IS Near THEN Angle IS LittlePositive");
            // Near front wall - room at right
            IS.NewRule("Rule 5", "IF RightDistance IS Far AND FrontalDistance IS Near THEN Angle IS Positive");
            // Near front wall - room at left
            IS.NewRule("Rule 6", "IF LeftDistance IS Far AND FrontalDistance IS Near THEN Angle IS Negative");
            // Near front wall - room at both sides - go right
            IS.NewRule("Rule 7", "IF RightDistance IS Far AND LeftDistance IS Far AND FrontalDistance IS Near THEN Angle IS Positive");
        }
Ejemplo n.º 40
0
        /// <summary>
        /// Adds a linguistic label to the variable. 
        /// </summary>
        /// 
        /// <param name="label">A <see cref="FuzzySet"/> that will be a linguistic label of the linguistic variable.</param>
        /// 
        /// <remarks>Linguistic labels are fuzzy sets (<see cref="FuzzySet"/>). Each
        /// label of the variable must have a unique name. The range of the label 
        /// (left and right limits) cannot be greater than 
        /// the linguistic variable range (start/end).</remarks>
        /// 
        /// <exception cref="NullReferenceException">The fuzzy set was not initialized.</exception>
        /// <exception cref="ArgumentException">The linguistic label name already exists in the linguistic variable.</exception>
        /// <exception cref="ArgumentException">The left limit of the fuzzy set can not be lower than the linguistic variable's starting point.</exception>
        /// <exception cref="ArgumentException">"The right limit of the fuzzy set can not be greater than the linguistic variable's ending point."</exception>
        /// 
        public void AddLabel( FuzzySet label )
        {
            // checking for existing name
            if ( this.labels.ContainsKey( label.Name ) )
                throw new ArgumentException( "The linguistic label name already exists in the linguistic variable." );

            // checking ranges
            if ( label.LeftLimit < this.start )
                throw new ArgumentException( "The left limit of the fuzzy set can not be lower than the linguistic variable's starting point." );
            if ( label.RightLimit > this.end )
                throw new ArgumentException( "The right limit of the fuzzy set can not be greater than the linguistic variable's ending point." );

            // adding label
            this.labels.Add( label.Name, label );
        }