internal Interval(IntervalSet parent, System.Decimal lowerBoundary, System.Decimal upperBoundary, decimal[] coefficients)
 {
     _parent = parent;
     _lowerBound = lowerBoundary;
     _upperBound = upperBoundary;
     _coefficients = coefficients;
 }
Exemple #2
0
        internal override void Operate(BinaryInterval operands, ref IntervalSet output)
        {
            Polynomial poly1 = Interval.GetPolynomial(operands.Coefficients1);
            Polynomial poly2 = Interval.GetPolynomial(operands.Coefficients2);
            Polynomial result = poly1 + poly2 - (poly1 * poly2);

            output.AddInterval(new Interval(output, operands.LowerBound, operands.UpperBound, result));
        }
 /// <summary>
 /// Constructor do define a linear interval μ = ax + b
 /// </summary>
 /// <param name="lowerBoundary">lower boundary of the interval</param>
 /// <param name="upperBoundary">upper boundary of the interval</param>
 /// /// <param name="a">a</param>
 /// <param name="b">b</param>
 internal Interval(IntervalSet parent, System.Decimal lowerBoundary, System.Decimal upperBoundary, System.Decimal a, System.Decimal b)
 {
     _parent = parent;
     _lowerBound = lowerBoundary;
     _upperBound = upperBoundary;
     _coefficients = new System.Decimal[] { b, a };
     if (_upperBound < _lowerBound) throw new ArgumentOutOfRangeException("Lower boundary cannot be higher than upper boundary.");
 }
Exemple #4
0
        internal override void Operate(BinaryInterval operands, ref IntervalSet output)
        {
            Polynomial poly1 = Interval.GetPolynomial(operands.Coefficients1);
            Polynomial poly2 = Interval.GetPolynomial(operands.Coefficients2);
            Polynomial sum = poly1 + poly2;

            BinaryInterval temp = new BinaryInterval(operands.LowerBound, operands.UpperBound, sum.Coefficients, (new Polynomial(1)).Coefficients);
            GetMinMax(temp, ref output, true);
        }
        public IntervalSet Operate(IntervalSet operand1)
        {
            //Calculate resulting function for each interval
            IntervalSet output = new IntervalSet(operand1.Dimension);

            foreach (Interval operand in operand1.Intervals)
            {
                Operate(operand, ref output);
            }

            return output;
        }
        public IntervalSet Operate( IntervalSet operand1, IntervalSet operand2 )
        {
            if (operand1.Dimension != operand2.Dimension) throw new ApplicationException("Dimensions don't match");

            //Find all boundaries for both interval sets
            decimal[] boundaries = IntervalSet.GetAllBoundaries(operand1, operand2);

            List<BinaryInterval> semiproduct = BuildBinaryInterval(operand1, operand2);

            //Calculate resulting function for each interval

            IntervalSet output = new IntervalSet(operand1.Dimension);

            foreach (BinaryInterval operands in semiproduct)
            {
                Operate(operands, ref output );
            }

            return output;
        }
Exemple #7
0
        internal override void Operate(BinaryInterval operands, ref IntervalSet output)
        {
            Polynomial poly1 = Interval.GetPolynomial(operands.Coefficients1);
            Polynomial poly2 = Interval.GetPolynomial(operands.Coefficients2);

            Polynomial multipl = (Operand1Power ? poly1^2 : poly1) + (Operand2Power ? poly2^2 : poly2);

            if (this.FinalDivision)
                multipl = multipl / RssDescendantCount;

            output.AddInterval(new Interval(output, operands.LowerBound, operands.UpperBound, multipl));
        }
 /// <summary>
 /// Constructor to define a singleton - fixed membership degree in a single point
 /// </summary>
 /// <param name="memberValue">x</param>
 /// <param name="membershipDegree">μ</param>
 internal Interval(IntervalSet parent, System.Decimal memberValue, double membershipDegree)
 {
     _parent       = parent;
     _lowerBound   = _upperBound = memberValue;
     _coefficients = new System.Decimal[] { (System.Decimal)membershipDegree };
 }
Exemple #9
0
 internal override void Operate(BinaryInterval operands, ref IntervalSet output)
 {
     GetMinMax(operands, ref output, true);
 }
 public DiscreteSet(IDiscreteDimension dimension, IntervalSet intervals)
     : base(dimension)
 {
     _intervals = intervals;
 }
Exemple #11
0
 /// <summary>
 /// Creates fuzzy set for the specified dimension and explicit set of memebership function, each one for a distinct interval.
 /// </summary>
 /// <param name="dimension">Dimenstion of the fuzzy set</param>
 /// <param name="intervals">Explicit set of memebership function, each one for a distinct interval.</param>
 public FuzzySet(IDimension dimension, IntervalSet intervals)
 {
     _dimension = dimension;
     _intervals = intervals;
 }
Exemple #12
0
        internal override IntervalSet GetFunction(Dictionary<IDimension, System.Decimal> inputs, IDimension variableInput)
        {
            if (variableInput == this._dimension)
                return _intervals;    //we will built the function for this dimension as a variable
            else
            {
                if (variableInput is IContinuousDimension)
                {
                    IntervalSet result = new IntervalSet(variableInput);
                    result.AddInterval( new Interval(result, ((IContinuousDimension)variableInput).MinValue, ((IContinuousDimension)variableInput).MaxValue, this.IsMember(inputs[_dimension])) );
                    return result;
                }
                else
                {
                    IDiscreteDimension dim = (IDiscreteDimension)variableInput;

                    IntervalSet result = new IntervalSet(dim);

                    for (uint i = 1; i <= dim.MemberCount; i++)
                        result.AddInterval( new Interval(result, i, i, this.IsMember(inputs[_dimension])));

                    return result;
                }
            }
        }
 public ContinuousSet(IContinuousDimension dimension, IntervalSet intervals)
     : base(dimension, intervals)
 {
 }
 public ContinuousSet(IContinuousDimension dimension, string caption)
     : base(dimension, caption)
 {
     _intervals = new IntervalSet(dimension);
 }
Exemple #15
0
        internal Interval(IntervalSet parent, System.Decimal lowerBoundary, System.Decimal upperBoundary, Polynomial polynomial)
        {
            Complex[] cs = polynomial.Coefficients;

            List<decimal> r = new List<decimal>();

            foreach(Complex c in cs)
                if (c.IsReal()) r.Add((decimal)c.Re);

            _parent = parent;
            _lowerBound = lowerBoundary;
            _upperBound = upperBoundary;
            _coefficients = r.ToArray();
        }
        /// <summary>
        /// Builds minimum/maximum function for the given interval. The method is used directly in AndM and OrM, and as a part of calculation in other operators.
        /// </summary>
        /// <param name="operands"></param>
        /// <param name="output"></param>
        /// <param name="minimum"></param>
        internal static void GetMinMax(BinaryInterval operands, ref IntervalSet output, bool minimum)
        {
            //Find all points where operand1 = operand2 for the given interval

            Polynomial poly1 = Interval.GetPolynomial(operands.Coefficients1);
            Polynomial poly2 = Interval.GetPolynomial(operands.Coefficients2);

            Polynomial difference = poly1 - poly2;

            if (Interval.IsEmpty(difference)) //both opearands are equal
                output.AddInterval(new Interval(output, operands.LowerBound, operands.UpperBound, poly1));
            else
            {

                decimal[] roots = Interval.RealRoots(difference, operands.LowerBound, operands.UpperBound);

                if (roots.Length == 0)
                {   //just find out which function is higher for the whole interval
                    double r1 = poly1.Evaluate(new Complex((double)operands.LowerBound)).Re;
                    double r2 = poly2.Evaluate(new Complex((double)operands.LowerBound)).Re;

                    if ((minimum && r1 <= r2) || (!minimum && r1 > r2))
                        output.AddInterval(new Interval(output, operands.LowerBound, operands.UpperBound, poly1));
                    else
                        output.AddInterval(new Interval(output, operands.LowerBound, operands.UpperBound, poly2));
                }
                else
                {
                    List<decimal> crossPoints = new List<decimal>();
                    crossPoints.AddRange(roots);
                    if (! crossPoints.Contains(operands.LowerBound))
                        crossPoints.Add(operands.LowerBound);
                    if (!crossPoints.Contains(operands.UpperBound))
                        crossPoints.Add(operands.UpperBound);
                    crossPoints.Sort();

                    //Declares that value of operand1 is higher than the value of operand2 for the given range;

                    for (int i = 0; i < crossPoints.Count() - 1; i++)
                    {
                        bool firstIsPreffered;

                        if (roots.Contains(crossPoints[i]))
                        {
                            double deriv1 = poly1.Differentiate(new Complex((double)crossPoints[i])).Re;
                            double deriv2 = poly2.Differentiate(new Complex((double)crossPoints[i])).Re;
                            firstIsPreffered = (minimum && deriv1 < deriv2) || (!minimum && deriv1 > deriv2);
                        }
                        else
                        { //it must be the second one, then
                            double deriv1 = poly1.Differentiate(new Complex((double)crossPoints[i + 1])).Re;
                            double deriv2 = poly2.Differentiate(new Complex((double)crossPoints[i + 1])).Re;
                            firstIsPreffered = (minimum && deriv2 < deriv1) || (!minimum && deriv2 > deriv1);
                        }

                        output.AddInterval(new Interval(output, crossPoints[i], crossPoints[i + 1], firstIsPreffered ? poly1 : poly2));

                    }
                }
            }
        }
 internal virtual void Operate(BinaryInterval operands, ref IntervalSet output )
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// True if these intervals includes the intervals to compare. I.e. if they share a common dimension and μthis(x) &lt;= μsetToCompare(x) for each x in &lt;dimension.minValue, dimension.MaxValue&gt;.
        /// Note that equalty is a special case of inclusion. To check for proper inclusion, you woud have to evaluate if this.Includes(setToCompare) && ! this.Equals(setToCompare).
        /// </summary>
        /// <param name="relationToCompare">Set to compare</param>
        /// <returns>True if this set is a subset of setToCompare.</returns>
        public bool Includes(IntervalSet setToCompare)
        {
            IntervalSet isSetToCompare = setToCompare;

            if (this.Dimension != isSetToCompare.Dimension) return false;

            List<BinaryInterval> binaryInterval = BinaryOperator.BuildBinaryInterval(this, isSetToCompare);

            foreach (BinaryInterval operands in binaryInterval)
            {
                IntervalSet minimum = new IntervalSet(this.Dimension);
                BinaryOperator.GetMinMax(operands, ref minimum, true);

                //Does the minimum equals operands.Operand2? That is the question
                IntervalSet included = new IntervalSet(this.Dimension);
                included.AddInterval( new Interval( included, operands.LowerBound, operands.UpperBound, operands.Coefficients2) );

                if (this.Dimension is IContinuousDimension)
                {
                    //add empty intervals just to pass the check() method
                    decimal minVal = ((IContinuousDimension)this.Dimension).MinValue;
                    decimal maxVal = ((IContinuousDimension)this.Dimension).MaxValue;
                    if (minVal < operands.LowerBound)
                    {
                        minimum.AddInterval(new Interval(minimum, minVal, operands.LowerBound, 0));
                        included.AddInterval(new Interval(included, minVal, operands.LowerBound, 0));
                    }
                    if (maxVal > operands.UpperBound)
                    {
                        minimum.AddInterval(new Interval(minimum, operands.UpperBound, maxVal, 0));
                        included.AddInterval(new Interval(included, operands.UpperBound, maxVal, 0));
                    }

                }

                if (!minimum.Equals( included ) )
                    return false;
            }

            return true;
        }
        /// <summary>
        /// Creates common set of intervals for both operands
        /// </summary>
        /// <param name="operand1"></param>
        /// <param name="operand2"></param>
        /// <returns></returns>
        internal static List<BinaryInterval> BuildBinaryInterval(IntervalSet operand1, IntervalSet operand2)
        {
            decimal[] boundaries = IntervalSet.GetAllBoundaries(operand1, operand2);

            List<BinaryInterval> semiproduct = new List<BinaryInterval>();

            for (uint i = 0; i < boundaries.Length; i++)
            {
                decimal boundary = boundaries[i];

                //singleton [boundary, boundary]
                Interval? singleton1 = operand1.GetExactInterval(boundary, boundary);
                Interval? singleton2 = operand2.GetExactInterval(boundary, boundary);

                if (singleton1.HasValue && singleton2.HasValue)
                    semiproduct.Add(new BinaryInterval(boundary, boundary, singleton1.Value.Coefficients, singleton2.Value.Coefficients));
                else if (singleton1.HasValue && i < (boundaries.Length - 1))
                {
                    Interval? range2 = operand2.GetSubinterval(boundary, boundaries[i + 1]);
                    if (range2.HasValue)
                        semiproduct.Add(new BinaryInterval(boundary, boundary, singleton1.Value.Coefficients, range2.Value.Coefficients));
                }
                else if (singleton2.HasValue && i < (boundaries.Length - 1))
                {
                    Interval? range1 = (operand1.GetSubinterval(boundary, boundaries[i + 1]));
                    semiproduct.Add(new BinaryInterval(boundary, boundary, range1.Value.Coefficients, singleton2.Value.Coefficients));
                }
                else if (singleton1.HasValue)
                {
                    Interval? range2 = operand2.GetSubinterval(boundary, boundary);
                    semiproduct.Add(new BinaryInterval(boundary, boundary, singleton1.Value.Coefficients, range2.Value.Coefficients));
                }
                else if (singleton2.HasValue)
                {
                    Interval? range1 = operand1.GetSubinterval(boundary, boundary);
                    semiproduct.Add(new BinaryInterval(boundary, boundary, range1.Value.Coefficients, singleton2.Value.Coefficients));
                }
                ////

                //range [boundary, boundaries[i+1] ]
                if (i < (boundaries.Length - 1))
                {
                    decimal boundary2 = boundaries[i + 1];
                    Interval? range1 = operand1.GetSubinterval(boundary, boundaries[i + 1]);
                    Interval? range2 = operand2.GetSubinterval(boundary, boundaries[i + 1]);

                    if (range1.HasValue && range2.HasValue)
                    {
                        semiproduct.Add(new BinaryInterval(boundary, boundary2, range1.Value.Coefficients, range2.Value.Coefficients));
                    }
                    else if (range1.HasValue)
                    {
                        semiproduct.Add(new BinaryInterval(boundary, boundary2, range1.Value.Coefficients, new decimal[] { 0 }));
                    }
                    else if (range2.HasValue)
                    {
                        semiproduct.Add(new BinaryInterval(boundary, boundary2, new decimal[] { 0 }, range2.Value.Coefficients));
                    }

                }
                ////

            }
            return semiproduct;
        }
        internal override void Operate(Interval operand1, ref IntervalSet output)
        {
            Polynomial result = (operand1.Polynomial^2);

            output.AddInterval( new Interval(output, operand1.LowerBound, operand1.UpperBound, result) );
        }
 public DiscreteSet(IDiscreteDimension dimension, string caption)
     : base(dimension, caption)
 {
     _intervals = new IntervalSet(dimension);
 }
Exemple #22
0
 /// <summary>
 /// Constructor to define a singleton - fixed membership degree in a single point
 /// </summary>
 /// <param name="memberValue">x</param>
 /// <param name="membershipDegree">μ</param>
 internal Interval(IntervalSet parent, System.Decimal memberValue, double membershipDegree)
 {
     _parent = parent;
     _lowerBound = _upperBound = memberValue;
     _coefficients = new System.Decimal[] { (System.Decimal) membershipDegree };
 }