Fuzzy System Architecture and simple implementation-Use of the AForge. NET Framework (IV)

Source: Internet
Author: User

Let's first explain why the question is simple, because I have not provided a good example.

I used to integrate the fuzzy system in the project I used AForge.net into Neural Networks and vector machines. When I couldn't figure out the example, I used the oldest Automatic Vehicle example.

Fuzzy System Architecture

Let's take a look at the fuzzy system and fuzzy theory. Here is a summary.

The basic architecture of the model worker system is shown in Figure 8.1. The main functional blocks include: (1) Modular mechanism, (2) model worker rule repository, and (3) modulo inference engine and (4) de-modulo regionalization mechanism.

The Blur mechanism is related to Fuzzy Sets and membership functions.

Fuzzy Rules are also mentioned in the previous article. deblurring involves only the center of gravity method. Here we will briefly describe the fuzzy inference engine.

The fuzzy inference engine is the core of a model embedding system. It can simulate human thinking and decision-making models through approximate inference or model embedding inference to achieve the goal of solving problems.

For example:

Premise (premise) 1: x is'

Premise (premise) 2: if x is A, y is B

Conclusion: y is B'

Simple implementation of a fuzzy inference system

The corresponding class in AForge. Net is InferenceSystem.

In program implementation, a Fuzzy Inference System is composed of a Database and a rule base. The general operation is as follows:

1. Obtain the value input

2. Convert the value input to the semantic meaning through the Database

3. Verify which rules in the rule library (Rulebase) are input and activated

4. Combine the activated rules to obtain the Fuzzy Output)

5. deblur (implementing the IDefuzzifier Interface)

The following is an example of a system that controls a vehicle to avoid a collision.

Input is a distance, universe [1, 0,120], Membership Function

Output as an angle, universe [-10, 50], Membership Function

Core code:

// Membership function (distance)
FuzzySet fsNear = new FuzzySet ("Near ",
New TrapezoidalFunction (15, 50, TrapezoidalFunction. EdgeType. Right ));
FuzzySet fsMedium = new FuzzySet ("Medium ",
New TrapezoidalFunction (15, 50, and 60,100 ));
FuzzySet fsFar = new FuzzySet ("Far ",
New TrapezoidalFunction (60,100, TrapezoidalFunction. EdgeType. Left ));

// Draw the image
Int length1 = (int) (chart1.RangeX. Max-chart1.RangeX. Min );
Double [,] NearValues = new double [length1, 2];
For (int I = (int) chart1.RangeX. Min; I <chart1.RangeX. Max; I ++)
{
NearValues [I, 0] = I;
NearValues [I, 1] = fsNear. GetMembership (I );
}
Double [,] MediumValues = new double [length1, 2];
For (int I = (int) chart1.RangeX. Min; I <chart1.RangeX. Max; I ++)
{
MediumValues [I, 0] = I;
MediumValues [I, 1] = fsMedium. GetMembership (I );
}
Double [,] FarValues = new double [length1, 2];
For (int I = (int) chart1.RangeX. Min; I <chart1.RangeX. Max; I ++)
{
FarValues [I, 0] = I;
FarValues [I, 1] = fsFar. GetMembership (I );
}
Chart1.UpdateDataSeries ("Near", NearValues );
Chart1.UpdateDataSeries ("Medium", MediumValues );
Chart1.UpdateDataSeries ("Far", FarValues );

// Distance (input)
LinguisticVariable lvFront = new LinguisticVariable ("FrontalDistance", 0,120 );
LvFront. AddLabel (fsNear );
LvFront. AddLabel (fsMedium );
LvFront. AddLabel (fsFar );


// Membership Function
FuzzySet fsZero = new FuzzySet ("Zero ",
New TrapezoidalFunction (-10, 5, 5, 10 ));
FuzzySet fsLP = new FuzzySet ("LittlePositive ",
New TrapezoidalFunction (5, 10, 20, 25 ));
FuzzySet fsP = new FuzzySet ("Positive ",
New TrapezoidalFunction (20, 25, 35, 40 ));
FuzzySet fsVP = new FuzzySet ("VeryPositive ",
New TrapezoidalFunction (35, 40, TrapezoidalFunction. EdgeType. Left ));

// Draw the image
Int lengh2 = (int) (chart2.RangeX. Max-chart2.RangeX. Min );
Double [,] ZeroValues = new double [leng2, 2];
For (int I = (int) chart2.RangeX. Min; I <chart2.RangeX. Max; I ++)
{
ZeroValues [I + 10, 0] = I;
ZeroValues [I + 10, 1] = fsZero. GetMembership (I );
}
Double [,] LittlePositiveValues = new double [leng2, 2];
For (int I = (int) chart2.RangeX. Min; I <chart2.RangeX. Max; I ++)
{
LittlePositiveValues [I + 10, 0] = I;
LittlePositiveValues [I + 10, 1] = fsLP. GetMembership (I );
}
Double [,] PositiveValues = new double [leng2, 2];
For (int I = (int) chart2.RangeX. Min; I <chart2.RangeX. Max; I ++)
{
PositiveValues [I + 10, 0] = I;
PositiveValues [I + 10, 1] = fsP. GetMembership (I );
}
Double [,] VeryPositiveValues = new double [leng2, 2];
For (int I = (int) chart2.RangeX. Min; I <chart2.RangeX. Max; I ++)
{
VeryPositiveValues [I + 10, 0] = I;
VeryPositiveValues [I + 10, 1] = fsVP. GetMembership (I );
}
Chart2.UpdateDataSeries ("Zero", ZeroValues );
Chart2.UpdateDataSeries ("LittlePositive", LittlePositiveValues );
Chart2.UpdateDataSeries ("Positive", PositiveValues );
Chart2.UpdateDataSeries ("VeryPositive", VeryPositiveValues );

// Angle
LinguisticVariable lvAngle = new LinguisticVariable ("Angle",-10, 50 );
LvAngle. AddLabel (fsZero );
LvAngle. AddLabel (fsLP );
LvAngle. AddLabel (fsP );
LvAngle. AddLabel (fsVP );

// Set the database
Database fuzzyDB = new Database ();
FuzzyDB. AddVariable (lvFront );
FuzzyDB. AddVariable (lvAngle );

// Create a fuzzy inference system
InferenceSystem IS = new InferenceSystem (fuzzyDB, new CentroidDefuzzifier (1000 ));

// Direct row rule
IS. NewRule ("Rule 1", "IF FrontalDistance IS Far THEN Angle IS Zero ");
// Left turn rule
IS. NewRule ("Rule 2", "IF FrontalDistance IS Near THEN Angle IS Positive ");

// Start Inference

// Set input
IS. SetInput ("FrontalDistance", float. Parse (inputBox. Text ));

// Print the output
Try
{
Float newAngle = IS. Evaluate ("Angle ");
OutputBox. Text = newAngle. ToString ();
}
Catch (Exception ex)
{
MessageBox. Show ("error =>" + ex. Message );
}

Effect:

If you want to output a fuzzy conclusion, you can use:

FuzzyOutput fuzzyOutput = IS.ExecuteInference("Angle");

foreach (FuzzyOutput.OutputConstraint oc in fuzzyOutput.OutputList)
{
Console.WriteLine(oc.Label + " - " + oc.FiringStrength.ToString());
}

Extension and improvement of the fuzzy inference system

With AForge. Net, we can quickly build a system, but AForge. Net is not perfect.

First, its merging operator is not completely implemented, and some are commonly used, such as the maximum boundary operator.

Secondly, there is only one de-blur implementation. You can consider implementing your own algorithm:

1. modified mean of maxima defuzzifier)

2. modified mean of maxima defuzzifier)

3. center average method (modified center average defuzzifier)

4. modified center average defuzzifier)

5. the weighted average method combines the start intensity and is more widely used.


However, the AForge. Net interface is well designed and can be easily expanded.

In fact, the fuzzy system can also be achieved by matlab, but matlab is not open-source, and expansion is indeed inconvenient, so it is not used. If there is no alternative, you can consider mixed encoding.

Fuzzy systems are also inconvenient to use, mainly because of the establishment of rule libraries.

The first and most direct way is to ask human experts. However, human experts often fail to provide all the necessary semantic Semantic Modeling rules, so that the rule repository is incomplete.

The effect of a fuzzy system is mainly influenced by rules and membership functions. Sometimes, incomplete rule repository results in devastating damage to the system.

The second method for obtaining semantic Semantic Rules is to obtain a semantic rule from numerical data through the training rule, this approach often involves how to split the input and output variable spaces. Neural Networks are commonly used.

AForge. Net is also related to neural networks, so it is very convenient to use.

 

Finally attached to the entire project: http://www.ctdisk.com/file/4512079

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.