Пример #1
0
        /// <summary>
        /// Инициализирует новый экземпляр класса <see cref="FuzzyCartesianProduct"/>.
        /// </summary>
        /// <param name="left">Первое множество.</param>
        /// <param name="right">Второе множество.</param>
        /// <param name="type">Тип операции.</param>
        public FuzzyCartesianProduct(NFuzzySet left, NFuzzySet right, OperationType type = OperationType.MinMax)
        {
            this.left  = left;
            this.right = right;
            this.xmax  = UnionMaximum();
            this.xmin  = UnionMinimum();
            switch (type)
            {
            case (OperationType.MinMax):
                function = (x) =>
                {
                    var args = SplitArgs(x);
                    return(Math.Min(left.GetConfidence(args.Item1), right.GetConfidence(args.Item2)));
                };
                break;

            case (OperationType.MinMaxAlternative):
                function = (x) =>
                {
                    var args = SplitArgs(x);
                    return(Math.Max(left.GetConfidence(args.Item1), right.GetConfidence(args.Item2)));
                };
                break;

            default:
                function = (x) =>
                {
                    var args = SplitArgs(x);
                    return(Math.Max(left.GetConfidence(args.Item1), right.GetConfidence(args.Item2)));
                };
                break;
            }
        }
Пример #2
0
        /// <summary>
        /// Возвращает пересечение нечётких множеств.
        /// </summary>
        /// <param name="set">Второе множество.</param>
        /// <param name="type">Тип операции пересечения.</param>
        /// <returns>Возвращает пересечение нечётких множеств.</returns>
        public NFuzzySet Intersection(NFuzzySet set, OperationType type = OperationType.MinMax)
        {
            double[]  newXMin = Minimum(set);
            double[]  newXMax = Maximum(set);
            NFunction func;

            switch (type)
            {
            case (OperationType.MinMax):
                func = (x) => Math.Min(this.GetConfidence(x), set.GetConfidence(x));
                break;

            case (OperationType.Algebraic):
                func = (x) => this.GetConfidence(x) * set.GetConfidence(x);
                break;

            case (OperationType.Conditional):
                func = (x) =>
                {
                    double y1 = this.GetConfidence(x);
                    double y2 = set.GetConfidence(x);
                    if (y2 == 1)
                    {
                        return(y1);
                    }
                    else if (y1 == 1)
                    {
                        return(y2);
                    }
                    else
                    {
                        return(0);
                    }
                };
                break;

            case (OperationType.MinMaxAlternative):
                func = (x) => Math.Max(0, this.GetConfidence(x) + set.GetConfidence(x) - 1);
                break;

            case (OperationType.Exponential):
                func = (x) => 1 - Math.Min(1, Math.Pow(Math.Pow(1 - this.GetConfidence(x), 2) +
                                                       Math.Pow(1 - set.GetConfidence(x), 2), 1.0 / 2));
                break;

            default:
                func = (x) => 0;
                break;
            }
            return(new NFuzzySet(func, newXMin, newXMax));
        }