AForge.Fuzzy.LinguisticVariable.AddLabel C# (CSharp) Method

AddLabel() public method

Adds a linguistic label to the variable.
Linguistic labels are fuzzy sets (FuzzySet). Each label of the variable must have a unique name. The range of the label (left and right limits) cannot be greater than the linguistic variable range (start/end).
The fuzzy set was not initialized. The linguistic label name already exists in the linguistic variable. The left limit of the fuzzy set can not be lower than the linguistic variable's starting point. "The right limit of the fuzzy set can not be greater than the linguistic variable's ending point."
public AddLabel ( AForge.Fuzzy.FuzzySet label ) : void
label AForge.Fuzzy.FuzzySet A that will be a linguistic label of the linguistic variable.
return void
        public void AddLabel( FuzzySet label )
        {
            // checking for existing name
            if ( this.labels.ContainsKey( label.Name ) )
                throw new ArgumentException( "The linguistic label name already exists in the linguistic variable." );

            // checking ranges
            if ( label.LeftLimit < this.start )
                throw new ArgumentException( "The left limit of the fuzzy set can not be lower than the linguistic variable's starting point." );
            if ( label.RightLimit > this.end )
                throw new ArgumentException( "The right limit of the fuzzy set can not be greater than the linguistic variable's ending point." );

            // adding label
            this.labels.Add( label.Name, label );
        }

Usage Example

Ejemplo n.º 1
0
        public InferenceSystem SetupInferenceSystem(int width)
        {
            var mp = new TrapezoidalFunction(centerPoint - width/2, centerPoint, centerPoint + width/2);
            var mn = new TrapezoidalFunction(-centerPoint - width/2, -centerPoint, -centerPoint + width/2);
            var sp = new TrapezoidalFunction(-centerPoint/2 + width/4, (double) centerPoint/2, centerPoint/2 + width/3);
            var sn = new TrapezoidalFunction(-centerPoint/2 - width/3, (double) -centerPoint/2, centerPoint/2 - width/4);
            var ze = new TrapezoidalFunction(-(double)centerPoint / 4, 0, (double)centerPoint / 4);

            var mpSet = new FuzzySet("MP", mp);
            var mnSet = new FuzzySet("MN", mn);
            var spSet = new FuzzySet("SP", sp);
            var snSet = new FuzzySet("SN", sn);
            var zeSet = new FuzzySet("ZE", ze);

            var ruleDatabase = new Database();

            for (int i = 0; i < windowSize*windowSize - 1; i++)
            {
                var variable = new LinguisticVariable(String.Format("IN{0}", i), -255, 255);
                variable.AddLabel(mpSet);
                variable.AddLabel(mnSet);
                ruleDatabase.AddVariable(variable);
            }

            var outVariable = new LinguisticVariable("OUT", -centerPoint - width/2, centerPoint + width/2);
            outVariable.AddLabel(spSet);
            outVariable.AddLabel(snSet);
            outVariable.AddLabel(zeSet);
            ruleDatabase.AddVariable(outVariable);
            var inferenceSystem = new InferenceSystem(ruleDatabase, new CentroidDefuzzifier(100));
            string rule1 = "IF ";
            string rule2 = "IF ";
            string rule3 = "IF ";
            for (int i = 0; i < windowSize*windowSize - 1; i++)
            {
                rule1 += String.Format("IN{0} is MP and ", i);
                rule2 += String.Format("IN{0} is MN and ", i);
                rule3 += String.Format("IN{0} is not MP and IN{0} is not MN AND ", i);
            }

            rule1 = rule1.Remove(rule1.Length - 4, 4);
            rule2 = rule2.Remove(rule2.Length - 4, 4);
            rule3 = "IF NOT (" + rule1.Replace("IF", "") + ") AND NOT(" + rule2.Replace("IF", "") + ")";

            rule1 += " then OUT is SN";
            rule2 += " then OUT is SP";
            rule3 += " then OUT is ZE";

            inferenceSystem.NewRule("Rule1", rule1);
            inferenceSystem.NewRule("Rule2", rule2);
            inferenceSystem.NewRule("Rule3", rule3);

            return inferenceSystem;
        }
All Usage Examples Of AForge.Fuzzy.LinguisticVariable::AddLabel