Accord.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 ( FuzzySet label ) : void
label 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

Esempio n. 1
0
        // Testing basic functionality of linguistic variables
        private void runLingVarTestButton_Click(object sender, EventArgs e)
        {
            ClearDataSeries();

            // create a linguistic variable to represent temperature
            LinguisticVariable lvTemperature = new LinguisticVariable("Temperature", 0, 80);

            // create the linguistic labels (fuzzy sets) that compose the temperature 
            FuzzySet fsCold = new FuzzySet("Cold", new TrapezoidalFunction(10, 15, TrapezoidalFunction.EdgeType.Right));
            FuzzySet fsCool = new FuzzySet("Cool", new TrapezoidalFunction(10, 15, 20, 25));
            FuzzySet fsWarm = new FuzzySet("Warm", new TrapezoidalFunction(20, 25, 30, 35));
            FuzzySet fsHot = new FuzzySet("Hot", new TrapezoidalFunction(30, 35, TrapezoidalFunction.EdgeType.Left));

            // adding labels to the variable
            lvTemperature.AddLabel(fsCold);
            lvTemperature.AddLabel(fsCool);
            lvTemperature.AddLabel(fsWarm);
            lvTemperature.AddLabel(fsHot);

            // get membership of some points to the cool fuzzy set
            double[][,] chartValues = new double[4][,];
            for (int i = 0; i < 4; i++)
                chartValues[i] = new double[160, 2];

            // showing the shape of the linguistic variable - the shape of its labels memberships from start to end
            int j = 0;
            for (float x = 0; x < 80; x += 0.5f, j++)
            {
                double y1 = lvTemperature.GetLabelMembership("Cold", x);
                double y2 = lvTemperature.GetLabelMembership("Cool", x);
                double y3 = lvTemperature.GetLabelMembership("Warm", x);
                double y4 = lvTemperature.GetLabelMembership("Hot", x);

                chartValues[0][j, 0] = x;
                chartValues[0][j, 1] = y1;
                chartValues[1][j, 0] = x;
                chartValues[1][j, 1] = y2;
                chartValues[2][j, 0] = x;
                chartValues[2][j, 1] = y3;
                chartValues[3][j, 0] = x;
                chartValues[3][j, 1] = y4;
            }

            // plot membership to a chart
            chart.UpdateDataSeries("COLD", chartValues[0]);
            chart.UpdateDataSeries("COOL", chartValues[1]);
            chart.UpdateDataSeries("WARM", chartValues[2]);
            chart.UpdateDataSeries("HOT", chartValues[3]);
        }
All Usage Examples Of Accord.Fuzzy.LinguisticVariable::AddLabel