Example #1
0
        protected void buildActionSets()
        {
            action = new ContinuousDimension("Action", "-10 Cool ... 0 Do nothing ... +10 heat", "", -10, +10);

            heat      = new SingletonSet(action, "Heat", 10);
            cool      = new SingletonSet(action, "Cool", -10);
            doNothing = new SingletonSet(action, "Do nothing", 0);

            #region Show it graphically
            RelationImage imgHeat      = new RelationImage(heat);
            RelationImage imgCool      = new RelationImage(cool);
            RelationImage imgDoNothing = new RelationImage(doNothing);

            Bitmap bmpHeat      = new Bitmap(pictureBoxHeat.Width, pictureBoxHeat.Height);
            Bitmap bmpCool      = new Bitmap(pictureBoxCool.Width, pictureBoxCool.Height);
            Bitmap bmpDoNothing = new Bitmap(pictureBoxDoNothing.Width, pictureBoxDoNothing.Height);

            imgHeat.DrawImage(Graphics.FromImage(bmpHeat));
            imgCool.DrawImage(Graphics.FromImage(bmpCool));
            imgDoNothing.DrawImage(Graphics.FromImage(bmpDoNothing));

            pictureBoxHeat.Image      = bmpHeat;
            pictureBoxCool.Image      = bmpCool;
            pictureBoxDoNothing.Image = bmpDoNothing;
            #endregion
        }
Example #2
0
        internal void AddInterval(Interval interval)
        {
            if (this._dimension is IContinuousDimension)
            {
                IContinuousDimension ordDim = (IContinuousDimension)this._dimension;

                if (interval.LowerBound < ordDim.MinValue)
                {
                    throw new ArgumentOutOfRangeException("interval.LowerBound", "Interval out of scope of the universe.");
                }
                if (interval.LowerBound < ordDim.MinValue)
                {
                    throw new ArgumentOutOfRangeException("interval.UpperBound", "Interval out of scope of the universe.");
                }
                _checked = false;
            }
            else if (this._dimension is IDiscreteDimension)
            {
                if (interval.LowerBound != interval.UpperBound || (interval.LowerBound % 1) != 0)
                {
                    new ArgumentOutOfRangeException("interval.LowerBound, interval.UpperBound", "Identical intergers expected for nominal dimension.");
                }
                _checked = false;
            }

            _intervals.Add(interval);
        }
Example #3
0
        protected void buildBuyItSet()
        {
            action = new ContinuousDimension("Action", "-10 surely don't buy ... +10 surely buy", "", -10, +10);

            if (trackBarBuyItKernel.Value < -8)
            {
                trackBarBuyItKernel.Value = -8;
            }
            if (trackBarBuyItCrossover.Value < -9)
            {
                trackBarBuyItCrossover.Value = -9;
            }

            if (trackBarBuyItCrossover.Value > trackBarBuyItKernel.Value - 1)
            {
                trackBarBuyItCrossover.Value = trackBarBuyItKernel.Value - 1;
            }

            if (trackBarBuyItSupport.Value > trackBarBuyItCrossover.Value - 1)
            {
                trackBarBuyItSupport.Value = trackBarBuyItCrossover.Value - 1;
            }

            buyIt = new LeftQuadraticSet(action, "Buy it!", trackBarBuyItSupport.Value, trackBarBuyItCrossover.Value, trackBarBuyItKernel.Value);

            RelationImage imgBuyIt = new RelationImage(buyIt);
            Bitmap        bmpBuyIt = new Bitmap(pictureBoxBuyIt.Width, pictureBoxBuyIt.Height);

            imgBuyIt.DrawImage(Graphics.FromImage(bmpBuyIt));
            pictureBoxBuyIt.Image = bmpBuyIt;
        }
Example #4
0
        protected void buildTemperatureSets()
        {
            temperature = new ContinuousDimension("t", "Temperature detected by sensor", "°C", -30, +40);

            lowTemperature     = new RightQuadraticSet(temperature, "Low temperature", 10, 15, 20);
            highTemperature    = new LeftQuadraticSet(temperature, "High temperature", 20, 25, 30);
            correctTemperature = new BellSet(temperature, "Correct temperature", 20, 5, 10);

            #region Show it graphically
            RelationImage imgLowTemp     = new RelationImage(lowTemperature);
            RelationImage imgHighTemp    = new RelationImage(highTemperature);
            RelationImage imgCorrectTemp = new RelationImage(correctTemperature);

            Bitmap bmpLowTemp     = new Bitmap(pictureBoxLowTemp.Width, pictureBoxLowTemp.Height);
            Bitmap bmpHighTemp    = new Bitmap(pictureBoxHighTemp.Width, pictureBoxHighTemp.Height);
            Bitmap bmpCorrectTemp = new Bitmap(pictureBoxCorrectTemp.Width, pictureBoxCorrectTemp.Height);

            imgLowTemp.DrawImage(Graphics.FromImage(bmpLowTemp));
            imgHighTemp.DrawImage(Graphics.FromImage(bmpHighTemp));
            imgCorrectTemp.DrawImage(Graphics.FromImage(bmpCorrectTemp));

            pictureBoxLowTemp.Image     = bmpLowTemp;
            pictureBoxHighTemp.Image    = bmpHighTemp;
            pictureBoxCorrectTemp.Image = bmpCorrectTemp;
            #endregion
        }
Example #5
0
        protected void buildDeltaTemperatureSets()
        {
            deltaTemperature = new ContinuousDimension("∆t", "Change of temperature detected by temperature sensor in time period", "°C/min", -5, +5);

            fallingTemperature  = new RightQuadraticSet(deltaTemperature, "Falling temperature", -3, -1, 0);
            risingTemperature   = new LeftQuadraticSet(deltaTemperature, "Rising temperature", 0, 1, 3);
            constantTemperature = new BellSet(deltaTemperature, "Constant temperature", 0, 1, 3);

            #region Show it graphically
            RelationImage imgFallingTemp  = new RelationImage(fallingTemperature);
            RelationImage imgRisingTemp   = new RelationImage(risingTemperature);
            RelationImage imgConstantTemp = new RelationImage(constantTemperature);

            Bitmap bmpFallingTemp  = new Bitmap(pictureBoxFallingTemp.Width, pictureBoxFallingTemp.Height);
            Bitmap bmpRisingTemp   = new Bitmap(pictureBoxRisingTemp.Width, pictureBoxRisingTemp.Height);
            Bitmap bmpConstantTemp = new Bitmap(pictureBoxConstantTemp.Width, pictureBoxConstantTemp.Height);

            imgFallingTemp.DrawImage(Graphics.FromImage(bmpFallingTemp));
            imgRisingTemp.DrawImage(Graphics.FromImage(bmpRisingTemp));
            imgConstantTemp.DrawImage(Graphics.FromImage(bmpConstantTemp));

            pictureBoxFallingTemp.Image  = bmpFallingTemp;
            pictureBoxRisingTemp.Image   = bmpRisingTemp;
            pictureBoxConstantTemp.Image = bmpConstantTemp;
            #endregion
        }
Example #6
0
 public RightQuadraticSet(IContinuousDimension dimension, string caption, System.Decimal kernelBound, System.Decimal crossover, System.Decimal supportBound)
     : base(dimension, caption, dimension.MinValue, kernelBound, dimension.MinValue, supportBound, dimension.MinValue, crossover)
 {
     if (kernelBound > supportBound)
     {
         throw new ArgumentOutOfRangeException("kernelBound", "kernelBound must be lower than supportBound");
     }
 }
Example #7
0
 public LeftLinearSet(IContinuousDimension dimension, string caption, System.Decimal supportBound, System.Decimal kernelBound)
     : base(dimension, caption, kernelBound, dimension.MaxValue, supportBound, dimension.MaxValue)
 {
     if (kernelBound < supportBound)
     {
         throw new ArgumentOutOfRangeException("kernelBound", "kernelBound must be higher than supportBound");
     }
 }
Example #8
0
        public BellSet(IContinuousDimension dimension, string caption, System.Decimal peakValue, System.Decimal distanceToCrossover, System.Decimal distanceToSupportBound)
            : base(dimension, caption, peakValue, peakValue, peakValue - distanceToSupportBound, peakValue + distanceToSupportBound, peakValue - distanceToCrossover, peakValue + distanceToCrossover)
        {
            if (distanceToCrossover <= 0) throw new ArgumentOutOfRangeException("distanceToCrossover", "Positive number expected to define a distance.");
            if (distanceToSupportBound <= 0) throw new ArgumentOutOfRangeException("distanceToSupportBound", "Positive number expected to define a distance.");
            if (distanceToSupportBound <= distanceToCrossover) throw new ArgumentOutOfRangeException("distanceToSupportBound", "distanceToSupportBound must be higher than distanceToCrossover.");

            _distanceToCrossover = distanceToCrossover;
            _distanceToSupportBound = distanceToSupportBound;
            _peakValue = peakValue;
        }
        private void buildIntervals(decimal value)
        {
            IContinuousDimension dimension = (IContinuousDimension)_dimension;

            if (dimension.MinValue < value)
            {
                _intervals.AddInterval(new Interval(_intervals, dimension.MinValue, value, 0));
            }

            _intervals.AddInterval(new Interval(_intervals, value, value, 1));

            if (dimension.MaxValue > value)
            {
                _intervals.AddInterval(new Interval(_intervals, value, dimension.MaxValue, 0));
            }
        }
Example #10
0
        protected void buildCheapSet()
        {
            price = new ContinuousDimension("Price", "Price we are about to pay for an offer", "$", 0, 1000);

            if (trackBarCheapSupport.Value < trackBarCheapKernel.Value)
            {
                trackBarCheapSupport.Value = trackBarCheapKernel.Value;
            }

            cheap = new RightLinearSet(price, "Cheap", trackBarCheapKernel.Value, trackBarCheapSupport.Value);

            RelationImage imgCheap = new RelationImage(cheap);
            Bitmap        bmpCheap = new Bitmap(pictureBoxCheap.Width, pictureBoxCheap.Height);

            imgCheap.DrawImage(Graphics.FromImage(bmpCheap));
            pictureBoxCheap.Image = bmpCheap;
        }
Example #11
0
        public BellSet(IContinuousDimension dimension, string caption, System.Decimal peakValue, System.Decimal distanceToCrossover, System.Decimal distanceToSupportBound)
            : base(dimension, caption, peakValue, peakValue, peakValue - distanceToSupportBound, peakValue + distanceToSupportBound, peakValue - distanceToCrossover, peakValue + distanceToCrossover)
        {
            if (distanceToCrossover <= 0)
            {
                throw new ArgumentOutOfRangeException("distanceToCrossover", "Positive number expected to define a distance.");
            }
            if (distanceToSupportBound <= 0)
            {
                throw new ArgumentOutOfRangeException("distanceToSupportBound", "Positive number expected to define a distance.");
            }
            if (distanceToSupportBound <= distanceToCrossover)
            {
                throw new ArgumentOutOfRangeException("distanceToSupportBound", "distanceToSupportBound must be higher than distanceToCrossover.");
            }

            _distanceToCrossover    = distanceToCrossover;
            _distanceToSupportBound = distanceToSupportBound;
            _peakValue = peakValue;
        }
Example #12
0
        void treeView_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if (_pictureBox != null && _label != null)
            {
                //Find nearest relation upper in the hierarchy
                TreeNode tn = e.Node;
                while (tn.Tag == null && !(tn.Tag is FuzzyRelation) && !(tn.Tag is Defuzzification.Defuzzification))
                {
                    if (tn.Parent == null)
                    {   //We are at the top
                        _label.Text       = "";
                        _pictureBox.Image = null;
                        tn = null;
                        break;
                    }
                    tn = tn.Parent;
                }

                if (tn != null)
                {
                    if (tn.Tag is Defuzzification.Defuzzification)
                    {
                        Defuzzification.Defuzzification deffuz = (Defuzzification.Defuzzification)tn.Tag;

                        if (allInputDimensionsAvailable(deffuz.Relation))
                        {
                            Dictionary <IDimension, System.Decimal> inputsCopy = new Dictionary <IDimension, System.Decimal>(_inputs);
                            if (!inputsCopy.ContainsKey(deffuz.OutputDimension))
                            {
                                inputsCopy.Add(deffuz.OutputDimension, deffuz.CrispValue);
                            }
                            else
                            {
                                inputsCopy[deffuz.OutputDimension] = deffuz.CrispValue;
                            }

                            RelationImage img = new RelationImage(deffuz.Relation, inputsCopy, deffuz.OutputDimension);
                            img.SupportOnly = _supportOnly;
                            Bitmap bmp = new Bitmap(_pictureBox.Width, _pictureBox.Height);
                            img.DrawImage(System.Drawing.Graphics.FromImage(bmp));
                            _pictureBox.Image = bmp;

                            _label.Text = String.Format("{0} deffuzification yields {1}={2:F5} {3}",
                                                        deffuz.GetType().Name,
                                                        deffuz.OutputDimension.Name,
                                                        deffuz.CrispValue,
                                                        deffuz.OutputDimension is IContinuousDimension ? ((IContinuousDimension)deffuz.OutputDimension).Unit : ""
                                                        );
                        }
                        else
                        {
                            reportTooManyDimensions();
                        }
                    }
                    else
                    {
                        FuzzyRelation relation = (FuzzyRelation)tn.Tag;
                        if (allInputDimensionsAvailable(relation))
                        {
                            RelationImage img = null;
                            if (relation.Dimensions.Count() == 1)
                            {
                                img = new RelationImage(relation, _inputs, relation.Dimensions[0]);
                            }
                            else if (_variableDimension != null)
                            {
                                img = new RelationImage(relation, _inputs, _variableDimension);
                            }

                            if (img == null)
                            {
                                _label.Text       = "";
                                _pictureBox.Image = null;
                            }
                            else
                            {
                                string lblText = "";
                                img.SupportOnly = _supportOnly;
                                Bitmap bmp = new Bitmap(_pictureBox.Width, _pictureBox.Height);
                                img.DrawImage(System.Drawing.Graphics.FromImage(bmp));
                                _pictureBox.Image = bmp;
                                IDimension realVariableDimension;
                                if (relation.Dimensions.Count() == 1)
                                {
                                    lblText = String.Format("Fuzzy set for dimension {0}.", relation.Dimensions[0].Name);
                                    realVariableDimension = relation.Dimensions[0];
                                }
                                else
                                {
                                    StringBuilder sb = new StringBuilder();
                                    foreach (IDimension dim in relation.Dimensions)
                                    {
                                        if (sb.Length != 0)
                                        {
                                            sb.Append(" x ");
                                        }
                                        sb.Append(dim.Name);
                                    }
                                    lblText = String.Format("Fuzzy relation for dimensions ({0}) where {1} is variable.", sb.ToString(), _variableDimension.Name);
                                    realVariableDimension = _variableDimension;
                                }

                                if (_inputs.ContainsKey(realVariableDimension))
                                {
                                    string value;
                                    if (realVariableDimension is IContinuousDimension)
                                    {
                                        IContinuousDimension dim = (IContinuousDimension)realVariableDimension;
                                        value = _inputs[realVariableDimension].ToString("F5");
                                        if (!String.IsNullOrEmpty(dim.Unit))
                                        {
                                            value += " " + dim.Unit;
                                        }
                                    }
                                    else
                                    {
                                        IDiscreteDimension dim = (IDiscreteDimension)realVariableDimension;
                                        if (dim.DefaultSet != null)
                                        {
                                            value = dim.DefaultSet.GetMember(_inputs[realVariableDimension]).Caption;
                                        }
                                        else
                                        {
                                            value = "#" + _inputs[realVariableDimension].ToString("F0");
                                        }
                                    }

                                    lblText += String.Format("\r\nµ{1}(x)={0:F2} for x={2}.",
                                                             relation.IsMember(_inputs),
                                                             realVariableDimension.Name,
                                                             value
                                                             );
                                }
                                _label.Text = lblText;
                            }
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Creates a triangular fuzzy number characterized by its peak value (where membership degree is 1), lower and upper support bound (where membership degree > 0)
 /// </summary>
 /// <param name="peakValue">peak value where membership degree is 1</param>
 /// <param name="supportMin">Lower bound of the support set. Here starts the rising edge</param>
 /// <param name="supportMax">Upper bound of the support set. Here ends the declining edge</param>
 public TriangularSet(IContinuousDimension dimension, string caption, System.Decimal peakValue, System.Decimal supportMin, System.Decimal supportMax)
     : base(dimension, caption, peakValue, peakValue, supportMin, supportMax)
 {
 }
 /// <summary>
 /// Creates new instance of singleton based on specified decimal representation of the member.
 /// </summary>
 /// <param name="dimension">Dimension</param>
 /// <param name="caption">Caption</param>
 /// <param name="value">decimal representation of the member</param>
 public SingletonSet(IContinuousDimension dimension, string caption, decimal value)
     : base(dimension, caption)
 {
     buildIntervals(value);
 }
Example #15
0
 /// <summary>
 /// Creates new instance of singleton based on specified decimal representation of the member.
 /// </summary>
 /// <param name="dimension">Dimension</param>
 /// <param name="caption">Caption</param>
 /// <param name="value">decimal representation of the member</param>
 public SingletonSet(IContinuousDimension dimension, string caption, decimal value)
     : base(dimension, caption)
 {
     buildIntervals(value);
 }
 public ContinuousSet(IContinuousDimension dimension, IntervalSet intervals)
     : base(dimension, intervals)
 {
 }
Example #17
0
 public ContinuousSet(IContinuousDimension dimension, IntervalSet intervals)
     : base(dimension, intervals)
 {
 }
 public UniverseSet(IContinuousDimension dimension, string caption)
     : base(dimension, caption)
 {
     _intervals.AddInterval(new Interval(_intervals, dimension.MinValue, dimension.MaxValue, 1));
 }
        public void DrawImage(System.Drawing.Graphics graphics)
        {
            float width  = graphics.VisibleClipBounds.Width;
            float height = graphics.VisibleClipBounds.Height;

            Pen penGrid = new Pen(ColorGrid, 1);



            graphics.FillRectangle(BrushBackground, 0, 0, width, height);

            #region Horizontal Grid
            for (int i = 0; i < 5; i++)
            {
                float y = (height - MarginTop - MarginBottom) / 4 * i + MarginTop;
                graphics.DrawLine(penGrid, MarginLeft, y, width - MarginRight, y);

                string t = "";

                switch (4 - i)
                {
                case 0: t = "0"; break;

                case 1: t = "¼"; break;

                case 2: t = "½"; break;

                case 3: t = "¾"; break;

                case 4: t = "1"; break;
                }

                graphics.DrawString(t, FontGrid, new SolidBrush(ColorGrid), MarginLeft / 2, y - 4);
            }

            graphics.DrawString("µ", FontGrid, new SolidBrush(ColorGrid), MarginLeft / 8, MarginTop - 4);

            #endregion

            #region Vertical grid


            if (_variableDimension is IContinuousDimension)
            {
                IContinuousDimension dim = (IContinuousDimension)_variableDimension;

                if (dim.Unit != "")
                {
                    SizeF size = graphics.MeasureString(dim.Unit, FontGrid);
                    graphics.DrawString(dim.Unit, FontGrid, new SolidBrush(ColorGrid), width - MarginRight - size.Width, height - MarginBottom + (float)(size.Height * 1.25));
                }
            }


            decimal minValue;
            decimal maxValue;

            List <decimal> significantValues = _variableDimension.SignificantValues.ToList <decimal>();

            if (this.SupportOnly)
            {
                if (_variableDimension is IContinuousDimension)
                {
                    IContinuousDimension dim = (IContinuousDimension)_variableDimension;
                    decimal ls       = _relation.GetLowerSupportBound(inputsWithoutVariableInput);
                    decimal us       = _relation.GetUpperSupportBound(inputsWithoutVariableInput);
                    decimal distance = us - ls;

                    ls = ls - (distance * (decimal)(SupportSurroundings / 100));
                    us = us + (distance * (decimal)(SupportSurroundings / 100));
                    if (ls < dim.MinValue)
                    {
                        ls = dim.MinValue;
                    }
                    if (us > dim.MaxValue)
                    {
                        us = dim.MaxValue;
                    }

                    //If there is too little left, though, use at least two.
                    while (significantValues.Count > 2)
                    {
                        if (significantValues[1] < ls)
                        {
                            significantValues.RemoveAt(0);
                        }
                        else if (significantValues[significantValues.Count - 2] > us)
                        {
                            significantValues.RemoveAt(significantValues.Count - 1);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                else
                {
                    int valuesLeft = significantValues.Count;
                    for (int i = significantValues.Count - 1; i >= 0; i--)
                    {
                        if (isMember(significantValues[i]) == 0)
                        {
                            significantValues.Remove(significantValues[i]);
                            valuesLeft--;
                            if (valuesLeft <= 3)
                            {
                                break;
                            }
                        }
                    }
                }
            }


            if (_variableDimension is IContinuousDimension)
            {
                minValue = significantValues[0];
                maxValue = significantValues[significantValues.Count - 1];
            }
            else
            {
                minValue = 0;
                maxValue = significantValues.Count - 1;
            }

            bool toggledMode = MaxValueCountInSingleRow < significantValues.Count;
            bool oddCount    = ((significantValues.Count % 2) == 1);



            uint c = 0;
            foreach (decimal gridValue in significantValues)
            {
                decimal value;
                c++;
                bool sub = (((c % 2) == 0) && oddCount) || (((c % 2) == 1) && !oddCount);

                string label;
                if (_variableDimension is IContinuousDimension)
                {
                    label = gridValue.ToString();
                    value = gridValue;
                }
                else
                {
                    IDiscreteDimension dim = (IDiscreteDimension)_variableDimension;
                    if (dim.DefaultSet != null)
                    {
                        label = dim.DefaultSet.GetMember(gridValue).Caption;
                    }
                    else
                    {
                        label = "#" + gridValue.ToString("F0");
                    }
                    value = c - 1;
                }

                float x = ((width - MarginLeft - MarginRight) / ((float)(maxValue - minValue))) * ((float)(value - minValue)) + MarginLeft;

                graphics.DrawLine(penGrid, x, MarginTop, x, height - MarginBottom);
                SizeF size = graphics.MeasureString(label, FontGrid);
                graphics.DrawString(label, FontGrid, new SolidBrush(ColorGrid), x - size.Width / 2, height - MarginBottom + size.Height / 4 + (sub ? size.Height : 0));


                #region Memberships for discrete set
                if (_variableDimension is IDiscreteDimension)
                {
                    graphics.DrawLine(PenLine, x, MarginTop + (height - MarginBottom - MarginTop) * (float)(1 - isMember(gridValue)), x, height - MarginBottom);

                    if (FullySpecified && gridValue == SpecifiedValue.Value)
                    {
                        graphics.DrawLine(PenValue, x, MarginTop + (height - MarginBottom - MarginTop) * (float)(1 - isMember(gridValue)), x, height - MarginBottom);
                        graphics.DrawLine(PenValue, MarginLeft, MarginTop + (height - MarginBottom - MarginTop) * (float)(1 - isMember(gridValue)), x, MarginTop + (height - MarginBottom - MarginTop) * (float)(1 - isMember(gridValue)));
                    }
                }
                #endregion
            }

            #endregion

            #region Line for continuous dimension

            if (_variableDimension is IContinuousDimension)
            {
                IntervalSet intervals = _relation.GetFunction(inputsWithoutVariableInput);

                foreach (Interval interval in intervals.Intervals)
                {
                    if
                    (
                        //(interval.LowerBound <= minValue && interval.UpperBound >= maxValue) ||
                        (interval.LowerBound >= minValue && interval.UpperBound <= maxValue) ||
                        (interval.LowerBound <= minValue && interval.UpperBound >= minValue) ||
                        (interval.LowerBound <= maxValue && interval.UpperBound >= maxValue)
                    )
                    {
                        decimal intervalMinValue = (interval.LowerBound < minValue ? minValue : interval.LowerBound);
                        decimal intervalMaxValue = (interval.UpperBound > maxValue ? maxValue : interval.UpperBound);

                        float intervalMinX = MarginLeft + ((width - MarginLeft - MarginRight) / (float)(maxValue - minValue)) * ((float)(intervalMinValue - minValue));
                        float intervalMaxX = MarginLeft + ((width - MarginLeft - MarginRight) / (float)(maxValue - minValue)) * ((float)(intervalMaxValue - minValue));

                        for (float x = intervalMinX; x <= intervalMaxX; x++)
                        {
                            decimal percentage;
                            if ((intervalMaxX - intervalMinX) == 0)
                            {
                                percentage = 0;
                            }
                            else
                            {
                                percentage = (decimal)((x - intervalMinX) / (intervalMaxX - intervalMinX));
                            }

                            decimal value = ((intervalMaxValue - intervalMinValue) * percentage) + intervalMinValue;

                            double membership = isMember(value);
                            //note that if y1 == y2 && x1 == x2, no point is plotted.
                            graphics.DrawLine(PenLine, x, MarginTop + (height - MarginBottom - MarginTop) * (float)(1 - membership), x, height - MarginBottom);
                        }
                    }
                }

                if (FullySpecified)
                {
                    decimal percentage;
                    if (SpecifiedValue.Value - minValue == 0)
                    {
                        percentage = 0;
                    }
                    else
                    {
                        percentage = (SpecifiedValue.Value - minValue) / (maxValue - minValue);
                    }
                    float x = (width - MarginLeft - MarginRight) * (float)percentage + MarginLeft;
                    float y = MarginTop + (height - MarginBottom - MarginTop) * (float)(1 - SpecifiedMembership.Value);

                    graphics.DrawLine(PenValue, x, y, x, height - MarginBottom);
                    graphics.DrawLine(PenValue, MarginLeft, y, x, y);
                    //graphics.DrawLine(PenValue, 0, 0, 100, 100);
                }
            }



            #endregion
        }
Example #20
0
        protected void buildSOSet()
        {
            SO = new ContinuousDimension("SO index", "SO index", "unit", 0, 100);

            lSO = new RightLinearSet(SO, "Low SO",0,20);
            hSO = new LeftLinearSet(SO, "High SO", 80, 100);
            mSO = new BellSet(SO, "Middle SO", 20, 5, 80);
        }
 /*
 /// <summary>
 /// Creates a triangular fuzzy number characterized by its peak value (where membership degree is 1), widths of the left and right segments of the support set (where membership degree > 0)
 /// </summary>
 /// <param name="peakValue">peak value where membership degree is 1</param>
 /// <param name="leftSupportSegmentWidth">width of the left segment within the support set</param>
 /// <param name="rightSupportSegmentWidth">width of the right segment within the support set</param>
 public TriangularSet(System.Decimal peakValue, System.Decimal leftSupportSegmentWidth, System.Decimal rightSupportSegmentWidth)
     : base(peakValue, peakValue, peakValue - leftSupportSegmentWidth, peakValue + rightSupportSegmentWidth)
 {
 }
 */
 /// <summary>
 /// Creates a symetric triangular fuzzy number specifed by the peak value and the with of the support area around. If peakValue = 8 and supportWidth=3, for example, the support set will be defined within the interval (6.5,8.5).
 /// </summary>
 /// <param name="peakValue">peak value where membership degree is 1</param>
 /// <param name="supportWidth">width of the support area around the peak.</param>
 public TriangularSet(IContinuousDimension dimension, string caption, System.Decimal peakValue, System.Decimal supportWidth)
     : base(dimension, caption, peakValue, peakValue, peakValue - (supportWidth/2), peakValue + (supportWidth/2))
 {
 }
Example #22
0
        protected void buildRSISet()
        {
            RSI = new ContinuousDimension("RSI index", "RSI index", "unit", 0, 100);

            lRSI = new RightLinearSet(RSI, "Low RSI", 0, 20);
            hRSI = new LeftLinearSet(RSI, "High RSI", 80, 100);
            mRSI = new BellSet(RSI, "Middle RSI", 20, 5, 80);
        }
Example #23
0
 protected void buildOBVSet( decimal baseline)
 {
     OBV = new ContinuousDimension("OBV index", "OBV index", "unit", 0, 100);
     //TriangularSet t = new TriangularSet(OBV, " MACD", 50, 50);
     lOBV = new RightLinearSet(OBV, "Low OBV", 0, baseline);
     hOBV = new LeftLinearSet(OBV, "High OBV", baseline, 100);
 }
Example #24
0
 protected void buildMACDSet(decimal baseline)
 {
     MACD = new ContinuousDimension("MACD index", "MACD index", "unit", 0, 100);
     //TriangularSet t = new TriangularSet(MACD, " MACD", 50, 50);
     lMACD = new RightLinearSet(MACD, "Low MACD", 0, baseline);
     hMACD = new LeftLinearSet(MACD, "High MACD", baseline, 100);
 }
Example #25
0
 protected void buildActionSet()
 {
     action = new ContinuousDimension("Action", "Action for stock", "action", 0, 100);
     buyIt = new RightQuadraticSet(action, "buy stock", 0, 50, 50);
     SellIt = new LeftQuadraticSet(action, "sell stock", 0, 50, 50);
     HoldIt = new BellSet(action, "hold stock", 0, 50, 50);
 }
 public LeftQuadraticSet(IContinuousDimension dimension, string caption, System.Decimal supportBound, System.Decimal crossover, System.Decimal kernelBound )
     : base(dimension, caption, kernelBound, dimension.MaxValue, supportBound, dimension.MaxValue, crossover, dimension.MaxValue)
 {
     if (kernelBound < supportBound) throw new ArgumentOutOfRangeException("kernelBound", "kernelBound must be higher than supportBound");
 }
Example #27
0
        /// <summary>
        /// Check if the universe properly covered by functions;
        /// </summary>
        private void check()
        {
            if (_checked)
            {
                return;
            }


            _intervals.Sort(
                delegate(Interval i1, Interval i2)
            {
                if (i1.LowerBound < i2.LowerBound)
                {
                    return(-1);
                }
                else if (i1.LowerBound > i2.LowerBound)
                {
                    return(1);
                }
                else if (i1.UpperBound < i2.UpperBound)
                {
                    return(-1);
                }
                else if (i1.UpperBound > i2.UpperBound)
                {
                    return(1);
                }
                else
                {
                    return(0);
                }
                //throw new ApplicationException("Inconsistent membership function specification.");
            }
                );

            if (this.Dimension is IDiscreteDimension)
            {
                _checked = true;
                return;
            }

            IContinuousDimension dim = (IContinuousDimension)this.Dimension;

            if (_intervals[0].LowerBound != dim.MinValue)
            {
                throw new ApplicationException("Membership function not specified for lower boundary of the universe.");
            }

            if (_intervals.Last().UpperBound != dim.MaxValue)
            {
                throw new ApplicationException("Membership function not specified for lower boundary of the universe.");
            }

            List <Interval> intsWithoutSingletons = _intervals.FindAll(t => !t.IsSingleton);

            for (int i = 0; i < intsWithoutSingletons.Count - 1; i++)
            {
                if (intsWithoutSingletons[i].UpperBound != intsWithoutSingletons[i + 1].LowerBound)
                {
                    throw new ApplicationException(String.Format("Membership function not specified for interval <{0},{1}).", intsWithoutSingletons[i].UpperBound, intsWithoutSingletons[i + 1].LowerBound));
                }
            }

            _checked = true;
        }
 public ContinuousMember(IContinuousDimension dimension, string caption, System.Decimal value)
 {
     _dimension = dimension;
     _caption = caption;
     _value = value;
 }
        public QuadraticSet(
            IContinuousDimension dimension,
            string caption,
            System.Decimal kernelMin,
            System.Decimal kernelMax,
            System.Decimal supportMin,
            System.Decimal supportMax,
            System.Decimal crossoverLower,
            System.Decimal crossoverUpper

            ) : base(dimension, caption)
        {
            if (kernelMin > kernelMax)
            {
                throw new ArgumentOutOfRangeException("kernelMin", "kernelMin must be lower than (or at least equal to) kernelMax");
            }
            if (supportMin >= supportMax)
            {
                throw new ArgumentOutOfRangeException("supportMin", "kernelMin must be lower than kernelMax");
            }
            if (supportMin > kernelMin)
            {
                throw new ArgumentOutOfRangeException("supportMin", "Support must be always broader than (or at least equal to) the kernel.");
            }
            if (supportMax < kernelMax)
            {
                throw new ArgumentOutOfRangeException("supportMax", "Support must be always broader than (or at least equal to) the kernel.");
            }

            if (crossoverLower < supportMin || crossoverLower > kernelMin)
            {
                throw new ArgumentOutOfRangeException("crossoverLower", "Lower crossover point must be between supportMin and kernelMin.");
            }
            if (crossoverUpper > supportMax || crossoverUpper < kernelMax)
            {
                throw new ArgumentOutOfRangeException("crossoverUpper", "Upper crossover point must be between kernelMax and supportMax.");
            }

            if (supportMin < dimension.MinValue)
            {
                throw new ArgumentOutOfRangeException("supportMin", "supportMin cannot be lower than dimension.MinValue");
            }

            if (supportMax > dimension.MaxValue)
            {
                throw new ArgumentOutOfRangeException("supportMax", "supportMax cannot be higher than dimension.MaxValue");
            }

            _kernelMin      = kernelMin;
            _kernelMax      = kernelMax;
            _supportMin     = supportMin;
            _supportMax     = supportMax;
            _crossoverLower = crossoverLower;
            _crossoverUpper = crossoverUpper;

            //internal implementation
            //Peak, bandwidth, see doc 6451_chap01.pdf, p. 21



            if (kernelMin > dimension.MinValue)
            //    _intervals.AddInterval(new Interval(_intervals, dimension.MinValue, kernelMax, 1));
            //else
            {
                System.Decimal k = (System.Decimal)(-1 / (2 * Math.Pow((double)(kernelMin - crossoverLower), 2)));
                System.Decimal m = 1 / (2 * ((System.Decimal)Math.Pow((double)(crossoverLower - supportMin), 2)));

                if (dimension.MinValue < supportMin)
                {
                    _intervals.AddInterval(new Interval(_intervals, dimension.MinValue, supportMin, 0));
                }
                //quadratic piece-wise rise
                _intervals.AddInterval(new Interval(_intervals, supportMin, crossoverLower, m, -2 * m * supportMin, m * supportMin * supportMin));
                _intervals.AddInterval(new Interval(_intervals, crossoverLower, kernelMin, k, -2 * k * kernelMin, k * kernelMin * kernelMin + 1));
            }

            //Flat rooftop?
            if (kernelMin < kernelMax)
            {
                _intervals.AddInterval(new Interval(_intervals, kernelMin, kernelMax, 1));
            }


            if (kernelMax < dimension.MaxValue)
            //    _intervals.AddInterval(new Interval(_intervals, kernelMax, dimension.MaxValue, 1));
            //else
            {
                //quadratic piece-wise fall
                System.Decimal l = (System.Decimal)(-1 / (2 * Math.Pow((double)(crossoverUpper - kernelMax), 2)));
                System.Decimal n = 1 / (2 * ((System.Decimal)Math.Pow((double)(crossoverUpper - supportMax), 2)));

                _intervals.AddInterval(new Interval(_intervals, kernelMax, crossoverUpper, l, -2 * l * kernelMax, l * kernelMax * kernelMax + 1));
                _intervals.AddInterval(new Interval(_intervals, crossoverUpper, supportMax, n, -2 * n * supportMax, n * supportMax * supportMax));
                if (supportMax < dimension.MaxValue)
                {
                    _intervals.AddInterval(new Interval(_intervals, supportMax, dimension.MaxValue, 0));
                }
            }
        }
 public ContinuousMember(IContinuousDimension dimension, string caption, System.Decimal value)
 {
     _dimension = dimension;
     _caption   = caption;
     _value     = value;
 }
Example #31
0
 public ContinuousSet(IContinuousDimension dimension, string caption)
     : base(dimension, caption)
 {
     _intervals = new IntervalSet(dimension);
 }
 /// <summary>
 /// Creates a triangular fuzzy number characterized by its peak value (where membership degree is 1), lower and upper support bound (where membership degree > 0)
 /// </summary>
 /// <param name="peakValue">peak value where membership degree is 1</param>
 /// <param name="supportMin">Lower bound of the support set. Here starts the rising edge</param>
 /// <param name="supportMax">Upper bound of the support set. Here ends the declining edge</param>
 public TriangularSet(IContinuousDimension dimension, string caption, System.Decimal peakValue, System.Decimal supportMin, System.Decimal supportMax)
     : base(dimension, caption, peakValue, peakValue, supportMin, supportMax)
 {
 }
        /// <summary>
        /// Creates new instance of trapezoidal fuzzy number. You can also create an asymetric left/right fuzzy number this way.
        /// To specify a left trapezoidal fuzzy number representing "large", for example, define both kernelMax and supportMax as System.Decimal.MaxValue.
        /// For a right number, both kernelMin and supportMin should be defined as System.Decimal.MinValue, respectively.
        /// </summary>
        /// <param name="kernelMin">Lower boundary of the kernel</param>
        /// <param name="kernelMax">Upper boundary of the kernel</</param>
        /// <param name="supportMin">Lower boundary of the support</param>
        /// <param name="suportMax">Upper boundary of the support</param>
        public TrapezoidalSet(IContinuousDimension dimension, string caption, System.Decimal kernelMin, System.Decimal kernelMax, System.Decimal supportMin, System.Decimal supportMax)
            : base(dimension, caption)
        {
            if (kernelMin > kernelMax)
            {
                throw new ArgumentOutOfRangeException("kernelMin", "kernelMin must be lower than (or at least equal to) kernelMax");
            }
            if (supportMin > supportMax)
            {
                throw new ArgumentOutOfRangeException("supportMin", "supportMin must be lower than supportMax");
            }
            if (supportMin > kernelMin)
            {
                throw new ArgumentOutOfRangeException("supportMin", "Support must be always broader than  (or at least equal to) the kernel.");
            }
            if (supportMax < kernelMax)
            {
                throw new ArgumentOutOfRangeException("supportMax", "Support must be always broader than  (or at least equal to) the kernel.");
            }

            if (supportMin < dimension.MinValue)
            {
                throw new ArgumentOutOfRangeException("supportMin", "supportMin cannot be lower than dimension.MinValue");
            }

            if (supportMax > dimension.MaxValue)
            {
                throw new ArgumentOutOfRangeException("supportMax", "supportMax cannot be higher than dimension.MaxValue");
            }

            _kernelMin  = kernelMin;
            _kernelMax  = kernelMax;
            _supportMin = supportMin;
            _supportMax = supportMax;

            //internal Implementaion

            if (dimension.MinValue < supportMin)
            {
                _intervals.AddInterval(new Interval(_intervals, dimension.MinValue, supportMin, 0));
            }

            if (supportMin < kernelMin)
            {
                _intervals.AddInterval(new Interval(_intervals, supportMin, kernelMin, 1 / (kernelMin - supportMin), -supportMin / (kernelMin - supportMin)));
            }

            if (kernelMin < kernelMax)
            {
                _intervals.AddInterval(new Interval(_intervals, kernelMin, kernelMax, 1));
            }

            if (kernelMax < supportMax)
            {
                _intervals.AddInterval(new Interval(_intervals, kernelMax, supportMax, 1 / (kernelMax - supportMax), -supportMax / (kernelMax - supportMax)));
            }

            if (dimension.MaxValue > supportMax)
            {
                _intervals.AddInterval(new Interval(_intervals, supportMax, dimension.MaxValue, 0));
            }
        }
Example #34
0
 public EmptySet(IContinuousDimension dimension, string caption)
     : base(dimension, caption)
 {
     _intervals.AddInterval( new Interval(_intervals, dimension.MinValue, dimension.MaxValue, 0));
 }
 public ContinuousMember(IContinuousDimension dimension, System.Decimal value)
 {
     _dimension = dimension;
     _caption = value.ToString("F3");
     _value = value;
 }
 public ContinuousSet(IContinuousDimension dimension, string caption)
     : base(dimension, caption)
 {
     _intervals = new IntervalSet(dimension);
 }
 public ContinuousMember(IContinuousDimension dimension, System.Decimal value)
 {
     _dimension = dimension;
     _caption   = value.ToString("F3");
     _value     = value;
 }
 public RightLinearSet(IContinuousDimension dimension, string caption, System.Decimal kernelBound, System.Decimal supportBound)
     : base(dimension, caption, dimension.MinValue, kernelBound, dimension.MinValue, supportBound)
 {
     if (kernelBound > supportBound) throw new ArgumentOutOfRangeException("kernelBound", "kernelBound must be lower than supportBound");
 }
        /*
         * /// <summary>
         * /// Creates a triangular fuzzy number characterized by its peak value (where membership degree is 1), widths of the left and right segments of the support set (where membership degree > 0)
         * /// </summary>
         * /// <param name="peakValue">peak value where membership degree is 1</param>
         * /// <param name="leftSupportSegmentWidth">width of the left segment within the support set</param>
         * /// <param name="rightSupportSegmentWidth">width of the right segment within the support set</param>
         * public TriangularSet(System.Decimal peakValue, System.Decimal leftSupportSegmentWidth, System.Decimal rightSupportSegmentWidth)
         *  : base(peakValue, peakValue, peakValue - leftSupportSegmentWidth, peakValue + rightSupportSegmentWidth)
         * {
         * }
         */

        /// <summary>
        /// Creates a symetric triangular fuzzy number specifed by the peak value and the with of the support area around. If peakValue = 8 and supportWidth=3, for example, the support set will be defined within the interval (6.5,8.5).
        /// </summary>
        /// <param name="peakValue">peak value where membership degree is 1</param>
        /// <param name="supportWidth">width of the support area around the peak.</param>
        public TriangularSet(IContinuousDimension dimension, string caption, System.Decimal peakValue, System.Decimal supportWidth)
            : base(dimension, caption, peakValue, peakValue, peakValue - (supportWidth / 2), peakValue + (supportWidth / 2))
        {
        }
Example #40
0
        public QuadraticSet(
            IContinuousDimension dimension,
            string caption,
            System.Decimal kernelMin,
            System.Decimal kernelMax,
            System.Decimal supportMin,
            System.Decimal supportMax,
            System.Decimal crossoverLower,
            System.Decimal crossoverUpper
            
            )
            : base(dimension, caption)
        {
            if (kernelMin > kernelMax) throw new ArgumentOutOfRangeException("kernelMin", "kernelMin must be lower than (or at least equal to) kernelMax");
            if (supportMin >= supportMax) throw new ArgumentOutOfRangeException("supportMin", "kernelMin must be lower than kernelMax");
            if (supportMin > kernelMin) throw new ArgumentOutOfRangeException("supportMin", "Support must be always broader than (or at least equal to) the kernel.");
            if (supportMax < kernelMax) throw new ArgumentOutOfRangeException("supportMax", "Support must be always broader than (or at least equal to) the kernel.");

            if (crossoverLower < supportMin || crossoverLower > kernelMin)  throw new ArgumentOutOfRangeException("crossoverLower", "Lower crossover point must be between supportMin and kernelMin.");
            if (crossoverUpper > supportMax || crossoverUpper < kernelMax)  throw new ArgumentOutOfRangeException("crossoverUpper", "Upper crossover point must be between kernelMax and supportMax.");

            if (supportMin < dimension.MinValue)
                throw new ArgumentOutOfRangeException("supportMin", "supportMin cannot be lower than dimension.MinValue");

            if (supportMax > dimension.MaxValue)
                throw new ArgumentOutOfRangeException("supportMax", "supportMax cannot be higher than dimension.MaxValue");

            _kernelMin = kernelMin;
            _kernelMax = kernelMax;
            _supportMin = supportMin;
            _supportMax = supportMax;
            _crossoverLower = crossoverLower;
            _crossoverUpper = crossoverUpper;

            //internal implementation
            //Peak, bandwidth, see doc 6451_chap01.pdf, p. 21

            if (kernelMin > dimension.MinValue)
            //    _intervals.AddInterval(new Interval(_intervals, dimension.MinValue, kernelMax, 1));
            //else
            {
                System.Decimal k = (System.Decimal)(-1 / (2 * Math.Pow((double)(kernelMin - crossoverLower), 2)));
                System.Decimal m = 1 / (2 * ((System.Decimal)Math.Pow((double)(crossoverLower - supportMin), 2)));

                if (dimension.MinValue < supportMin)
                    _intervals.AddInterval(new Interval(_intervals, dimension.MinValue, supportMin, 0));
                //quadratic piece-wise rise
                _intervals.AddInterval(new Interval(_intervals, supportMin, crossoverLower, m, -2 * m * supportMin, m * supportMin * supportMin));
                _intervals.AddInterval(new Interval(_intervals, crossoverLower, kernelMin, k, -2 * k * kernelMin, k * kernelMin * kernelMin + 1));
            }

            //Flat rooftop?
            if (kernelMin < kernelMax)
                _intervals.AddInterval(new Interval(_intervals, kernelMin, kernelMax, 1));

            if (kernelMax < dimension.MaxValue)
            //    _intervals.AddInterval(new Interval(_intervals, kernelMax, dimension.MaxValue, 1));
            //else
            {
                //quadratic piece-wise fall
                System.Decimal l = (System.Decimal)(-1 / (2 * Math.Pow((double)(crossoverUpper - kernelMax), 2)));
                System.Decimal n = 1 / (2 * ((System.Decimal)Math.Pow((double)(crossoverUpper - supportMax), 2)));

                _intervals.AddInterval(new Interval(_intervals, kernelMax, crossoverUpper, l, -2 * l * kernelMax, l * kernelMax * kernelMax + 1));
                _intervals.AddInterval(new Interval(_intervals, crossoverUpper, supportMax, n, -2 * n * supportMax, n * supportMax * supportMax));
                if (supportMax < dimension.MaxValue)
                    _intervals.AddInterval(new Interval(_intervals, supportMax, dimension.MaxValue, 0));

            }
        }