Fuzzy logic

Our application will have two simple buttons, one for running the fuzzy set test and the other for running the linguistic variable test. Here is a quick snapshot of what our example application will look like:

The code to create this sample is relatively small and simple. Here is what it looks like when we click on the Run Fuzzy Set Test button. We will create two fuzzy sets (one for Cool and one for Warm), add some membership data values for each, and then plot them:

TrapezoidalFunction function1 = new TrapezoidalFunction( 13, 18, 23, 28 );
FuzzySet fsCool = new FuzzySet( "Cool", function1 );
TrapezoidalFunction function2 = new TrapezoidalFunction( 23, 28, 33, 38 );
FuzzySet fsWarm = new FuzzySet( "Warm", function2 );

double[,] coolValues = new double[20, 2];
for ( int i = 10; i < 30; i++ )
{
coolValues[i - 10, 0] = i;
coolValues[i - 10, 1] = fsCool.GetMembership( i );
}

double[,] warmValues = new double[20, 2];
for ( int i = 20; i < 40; i++ )
{
warmValues[i - 20, 0] = i;
warmValues[i - 20, 1] = fsWarm.GetMembership( i );
}

chart?.UpdateDataSeries( "COOL", coolValues );
chart?.UpdateDataSeries( "WARM", warmValues );

The code for running the linguistic variable test is as follows. Again, we create fuzzy sets, but this time we create four instead of two. As with our first test, we add membership data and then plot:

LinguisticVariable lvTemperature = new LinguisticVariable( "Temperature", 0, 80 );
TrapezoidalFunction function1 = new TrapezoidalFunction( 10, 15, TrapezoidalFunction.EdgeType.Right );
FuzzySet fsCold = new FuzzySet( "Cold", function1 );
TrapezoidalFunction function2 = new TrapezoidalFunction( 10, 15, 20, 25 );
FuzzySet fsCool = new FuzzySet( "Cool", function2 );
TrapezoidalFunction function3 = new TrapezoidalFunction( 20, 25, 30, 35 );
FuzzySet fsWarm = new FuzzySet( "Warm", function3 );
TrapezoidalFunction function4 = new TrapezoidalFunction( 30, 35, TrapezoidalFunction.EdgeType.Left );
FuzzySet fsHot = new FuzzySet( "Hot", function4 );

lvTemperature.AddLabel( fsCold );
lvTemperature.AddLabel( fsCool );
lvTemperature.AddLabel( fsWarm );
lvTemperature.AddLabel( fsHot );

double[][,] chartValues = new double[4][,];
for ( int i = 0; i < 4; i++ )
chartValues[i] = new double[160, 2];

And finally we chart the values:

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;
}

chart.UpdateDataSeries( "COLD", chartValues[0] );
chart.UpdateDataSeries( "COOL", chartValues[1] );
chart.UpdateDataSeries( "WARM", chartValues[2] );
chart.UpdateDataSeries( "HOT", chartValues[3] );

Linguistic variable shape:

As you can see, we were able to easily show the exact visual definition and clarity that the Wikipedia definition presented.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.189.178.237