Exemplo n.º 1
0
        private void GetAngle(object sender, EventArgs e)
        {
            g.ResetTransform();
            g = picture.CreateGraphics();
            g.SmoothingMode = SmoothingMode.HighQuality;
            drawingState.X  = (double)Xnum.Value;
            drawingState.Fi = (double)FInum.Value;
            drawingState.Y  = (double)YNum.Value;
            DefuzzificationMethod method = DefuzzificationMethod.GravityCentre;

            if (methodComboBox.SelectedIndex >= 0)
            {
                method = (DefuzzificationMethod)Enum.Parse(typeof(DefuzzificationMethod),
                                                           methodComboBox.SelectedItem.ToString());
            }
            Stopwatch sw = new Stopwatch();

            sw.Start();
            double teta = task.GetAngle(drawingState.X, drawingState.Fi, method);

            Tetanum.Value     = double.IsNaN(teta)? 0: (decimal)teta;
            drawingState.Teta = (double)Tetanum.Value;
            sw.Stop();
            label7.Text = sw.ElapsedMilliseconds.ToString();
            g.Clear(Color.White);
            drawingState.Draw(g);
        }
Exemplo n.º 2
0
        public double Defuzzificate(double xv, double fiv, DefuzzificationMethod method =
                                    DefuzzificationMethod.GravityCentre)
        {
            double[] args   = { xv, fiv };
            double   min    = premise.GetConfidence(args);
            FuzzySet result = new FuzzySet((x) => Math.Min(teta.GetConfidence(x), min),
                                           teta.XMin[0], teta.XMax[0]);

            return(result.Defuzzification(method));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new Fuzzy <see cref="InferenceSystem"/>.
        /// </summary>
        ///
        /// <param name="defuzzifier">A defuzzyfier method used to evaluate the numeric otput
        /// of the system.</param>
        /// <param name="normOperator">A <see cref="INorm"/> operator used to evaluate the norms
        /// in the <see cref="InferenceSystem"/>. For more information of the norm evaluation see <see cref="Rule"/>.</param>
        /// <param name="conormOperator">A <see cref="ICoNorm"/> operator used to evaluate the
        /// conorms in the <see cref="InferenceSystem"/>. For more information of the conorm evaluation see <see cref="Rule"/>.</param>
        ///
        public InferenceSystem(DefuzzificationMethod defuzzificationMethod, INorm normOperator, ICoNorm conormOperator)
        {
            this.defuzzificationMethod = defuzzificationMethod;
            this.normOperator          = normOperator;
            this.conormOperator        = conormOperator;

            this.database        = new Database();
            this.rulebase        = new Rulebase();
            this.inputVariables  = new HashSet <string>();
            this.outputVariables = new HashSet <string>();
        }
 /// <summary>
 /// Construct instance of a defuzzification wrapper which wrappes a fuzzy relation to deffuzify.
 /// </summary>
 /// <param name="relation">Fuzzy Relation to defuzzify</param>
 /// <param name="inputs">Set of specified values for particular dimensions. There must be exactly one dimesion missing. This dimension will be used as the output dimension.</param>
 /// <param name="method">Deffuzification method to apply</param>
 /// <returns></returns>
 public static Defuzzification GetDefuzzification(FuzzyRelation relation, Dictionary<IDimension, System.Decimal> inputs, DefuzzificationMethod method)
 {
     switch (method)
     {
         case DefuzzificationMethod.CenterOfGravity:
             return new CenterOfGravity(relation, inputs);
         case DefuzzificationMethod.CenterOfMaximum:
             return new CenterOfMaximum(relation, inputs);
         case DefuzzificationMethod.LeftOfMaximum:
             return new LeftOfMaximum(relation, inputs);
         case DefuzzificationMethod.RightOfMaximum:
             return new RightOfMaximum(relation, inputs);
         case DefuzzificationMethod.MeanOfMaximum:
             return new MeanOfMaximum(relation, inputs);
         default:
             throw new NotImplementedException("Unknown defuuzification method.");
     }
 }
Exemplo n.º 5
0
        public double Defuzzification(DefuzzificationMethod type = DefuzzificationMethod.GravityCentre)
        {
            switch (type)
            {
            case (DefuzzificationMethod.GravityCentre):
            {
                Func <double, double> func  = this.GetConfidence;
                Func <double, double> func1 = (x) => x *func(x);

                double fIntegral = func.PIntegral1(xmin[0], xmax[0], 1E-1);
                if (fIntegral == 0)
                {
                    return(0);
                }
                return(func1.PIntegral1(xmin[0], xmax[0], 1E-1) / fIntegral);
            }

            case (DefuzzificationMethod.MeanOfMaximus):
            {
                double eps    = (xmax[0] - xmin[0]) / 5000;
                double max    = Max(eps);
                double result = 0;
                int    count  = 0;
                for (double x = xmin[0]; x <= xmax[0]; x += eps)
                {
                    double v = GetConfidence(x);
                    if (v == max)
                    {
                        result += x;
                        count++;
                    }
                }
                return(result / count);
            }

            case (DefuzzificationMethod.Median):
            {
                Func <double, double>         f        = GetConfidence;
                Func <double, double, double> integral = (a, b) => f.PIntegral1(a, b, 1E-1);
                return(Solve((x) => integral(xmin[0], x) - integral(x, xmax[0])));
            }
            }
            return(0);
        }
Exemplo n.º 6
0
        public double GetAngle(double x, double fi, DefuzzificationMethod method =
                               DefuzzificationMethod.GravityCentre)
        {
            //дефаззификация по методу среднего центра
            double num = 0;
            double div = 0;

            foreach (var rule in buildedRules)
            {
                double actLevel = rule.Item1.GetConfidence(x) * rule.Item2.GetConfidence(fi);
                if (actLevel > 0)
                {
                    double deff = rule.Item3.Defuzzificate(x, fi, method);
                    num += actLevel * deff;
                    div += actLevel;
                }
            }
            return(num / div);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Construct instance of a defuzzification wrapper which wrappes a fuzzy relation to deffuzify.
        /// </summary>
        /// <param name="relation">Fuzzy Relation to defuzzify</param>
        /// <param name="inputs">Set of specified values for particular dimensions. There must be exactly one dimesion missing. This dimension will be used as the output dimension.</param>
        /// <param name="method">Deffuzification method to apply</param>
        /// <returns></returns>
        public static Defuzzification GetDefuzzification(FuzzyRelation relation, Dictionary <IDimension, System.Decimal> inputs, DefuzzificationMethod method)
        {
            switch (method)
            {
            case DefuzzificationMethod.CenterOfGravity:
                return(new CenterOfGravity(relation, inputs));

            case DefuzzificationMethod.CenterOfMaximum:
                return(new CenterOfMaximum(relation, inputs));

            case DefuzzificationMethod.LeftOfMaximum:
                return(new LeftOfMaximum(relation, inputs));

            case DefuzzificationMethod.RightOfMaximum:
                return(new RightOfMaximum(relation, inputs));

            case DefuzzificationMethod.MeanOfMaximum:
                return(new MeanOfMaximum(relation, inputs));

            default:
                throw new NotImplementedException("Unknown defuuzification method.");
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Initializes a new Fuzzy <see cref="InferenceSystem"/>.
 /// </summary>
 ///
 /// <param name="defuzzifier">A defuzzyfier method used to evaluate the numeric uotput of the system.</param>
 ///
 public InferenceSystem(DefuzzificationMethod defuzzificationMethod)
     : this(defuzzificationMethod, new ProductNorm(), new MaximumCoNorm())
 {
 }