/// <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; } }
protected double[] Maximum(NFuzzySet set) { double[] max = new double[xmin.Length]; for (int i = 0; i < xmax.Length; i++) { max[i] = Math.Min(xmax[i], set.xmax[i]); } return(max); }
protected double[] Minimum(NFuzzySet set) { double[] min = new double[xmin.Length]; for (int i = 0; i < xmin.Length; i++) { min[i] = Math.Min(xmin[i], set.xmin[i]); } return(min); }
/// <summary> /// Возвращает объединение нечётких множеств. /// </summary> /// <param name="set">Второе множество.</param> /// <param name="type">Тип операции объединения.</param> /// <returns>Возвращает объединение нечётких множеств.</returns> public NFuzzySet Union(NFuzzySet set, OperationType type = OperationType.MinMax) { double[] newXMin = Minimum(set); double[] newXMax = Maximum(set); NFunction func; switch (type) { case (OperationType.MinMax): func = (x) => Math.Max(this.GetConfidence(x), set.GetConfidence(x)); break; case (OperationType.Algebraic): func = (x) => this.GetConfidence(x) + set.GetConfidence(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 == 0) { return(y1); } else if (y1 == 0) { return(y2); } else { return(1); } }; break; case (OperationType.MinMaxAlternative): func = (x) => Math.Min(1, this.GetConfidence(x) + set.GetConfidence(x)); break; case (OperationType.Exponential): func = (x) => Math.Min(1, Math.Pow(Math.Pow(this.GetConfidence(x), 2) + Math.Pow(set.GetConfidence(x), 2), 1.0 / 2)); break; default: func = (x) => 0; break; } return(new NFuzzySet(func, newXMin, newXMax)); }
/// <summary> /// Возвращает декартово произведение заданных множеств. /// </summary> /// <param name="set">Второе множество.</param> /// <param name="type">Тип операции.</param> /// <returns>Возвращает декартово произведение заданных множеств.</returns> public NFuzzySet CartesianProduct(NFuzzySet set, OperationType type = OperationType.MinMax) { return(new FuzzyCartesianProduct(this, set, type)); }