Ok, so the overall block diagram looks like this. Force enters the cart/pole dynamic system, and the four state variables come out. Then a fuzzy logic controller uses one or more of the output variables to determine the appropriate force that keeps the pole upright. Simple enough, right?
If I had just defined these membership functions between plus minus 0.5 radians, then this controller would not produce a response if the pole happens to fall outside of that range. But by defining the functions across the entire input range of plus minus pi, we guarantee that the controller will still label the input as fully negative or positive.
Once again we can come back to our intuition and experience with the problem and realize that if we take into account the pole angular velocity and not just the angle then we can use that to help slow the pole rotation down right as it reaches the balance point.
Now I can add two more rules to our inference system. If theta dot is negative then force is negative large. That is, if the pole is rotating in the negative direction, really try to stop that rotation by moving the cart with a large negative force. And the opposite for a positive theta dot.
Ok, lastly, I want to remind you that fuzzy interference systems have a lot of practical applications and have been used in many different industries. We already know that we can develop a fuzzy logic controller which can take the place of other traditional control methods.
Another example of this is within autonomous driving where a fuzzy logic controller has been developed that can automatically park a car. This system uses range sensors on all four sides to guide the car into the empty spot. This is a really interesting example because the car has nonholonomic constraints. Basically that means that there are more degrees of freedom for the car than there are possible ways to move it. For example, the car cannot directly move sideways but instead must make a series of other motions to go in that direction. And this is intuitive to a human driver and therefore can be a great candidate for a fuzzy logic-based controller.
Another famous example is the speed controller for the Sendai Subway system in Japan. Using a fuzzy logic controller, the engineers were able to make smoother starts and stops as well as be 10% more energy efficient than human controlled acceleration.
However, we also talked about in earlier videos how fuzzy inference system can be used for decision processes not just controllers. In the second video we talked about a loan risk example and it turns out that there are many practical examples of fuzzy inference decision systems in the field of finance.
There are also some really interesting examples in the medical industry. In fact, one in particular is the use of fuzzy logic to control an artificial pancreas. Researches show that fuzzy logic is a viable alternative to other model-based controllers for a closed-loop insulin delivery system because it "does not require differential equations of the glucoregulatory system and allows clinicians to personalize dosing aggressiveness to meet individual patient requirements.
To generate code for evaluating fuzzy systems, you must first design a fuzzy inference system (FIS). For more information, see Build Fuzzy Systems at the Command Line, Build Fuzzy Systems Using Fuzzy Logic Designer, and Tuning Fuzzy Inference Systems.
Generating code using MATLAB Coder does not support FIS objects or FIS tree objects directly. Instead, to generate code for evaluating a fuzzy system, you must convert your FIS or FIS tree into a homogeneous structure using the getFISCodeGenerationData function.
If your type-1 or type-2 FIS is stored in a FIS file, you can embed the FIS data in the generated code by reading the FIS data from within the evaluation function. This workflow is not supported for FIS trees.
Specify a function for evaluating a fuzzy system for input vector x. Within this function, read the FIS data from the file predictType2.fis. Since the stored FIS is a type-2 system, you must specify the FIS type when calling getFISCodeGenerationData. If your stored FIS is a type-1 system, you do not have to specify the FIS type.
To change the FIS properties after compilation, you can generate code for evaluating a FIS that is read from a FIS file specified at run time. In this case, the FIS data is not embedded in the generated code. Modifying the fuzzy system properties after compilation using a FIS file is not supported for FIS trees.
Each time you run evaluatefis4, the function reloads the fuzzy system from the specified file. For computational efficiency, you can create a function that does not reload a previously loaded FIS. For example, the evaluatefis5 function loads a FIS from a FIS file only when a new file name is specified.
You can use this function to evaluate another FIS with the same number of inputs. For example, save an intermediate version of the FIS from Predict Chaotic Time Series Using Type-2 FIS to predictTimeSeries2.fis, and evaluate the FIS using the MEX file for the same input values.
The preceding examples generated code for double-precision data. To generate code for single-precision data, specify the data type of the input values as single. You can use single-precision data when evaluating FIS objects and FIS tree objects. For example, generate code for evaluatefis2 using single-precision data.
Once you interactively tune a fuzzy system using Fuzzy Logic Designer, you can generate MATLAB code to programmatically tune that system. You can then use or modify the generated code for your applications.
Often, tuning a FIS is a two-stage process: Learn the rules for the FIS, then tune the membership function (MF) and rule parameters. For this example, you generate code for the two stages separately and combine the generated code for the full two-stage tuning process.
For this example, you generate code for tuning the FIS in Tune Fuzzy Inference System Using Fuzzy Logic Designer. For details on how to load the initial FIS structure and training data, see Load Example Data.
The MATLAB Editor opens a generated script with the following code for creating and learning the rules for the current active FIS. For clarity, some of the input and output MF configuration code is omitted.
To tune the MF and rule parameters for your FIS, first specify the tuning options. In the Tuning Options dialog box, in the Optimization Type section, select Tuning. Configure the remaining tuning options as specified in Tune MF and Rule Parameters.
The MATLAB Editor opens a generated script with the following code for creating and tuning the current active FIS. For clarity, some of the input MF, output MF, and rule configuration code is omitted.
When you build a fuzzy inference system (FIS), you can replace the built-in membership functions (MFs) or inference functions with custom functions. You can create a FIS that uses these custom functions in the Fuzzy Logic Designer app and at the MATLAB command line.
You can create custom membership functions and use them in the fuzzy inference process. The values of these functions must lie between 0 and 1. For more information on the properties of membership functions, see Membership Functions.
When you create a custom membership function, you must save it in your current working folder or on the MATLAB path. You can then design a FIS that uses the custom membership function at the command line or in the Fuzzy Logic Designer app.
To use a custom membership function when designing a FIS using the Fuzzy Logic Designer app, first select the corresponding variable in the System Browser. Then, in the Add Components gallery, click MF.
Depending on the type of FIS you design, you can replace the built-in AND, OR, implication, aggregation, and defuzzification inference methods with custom functions. For each type of inference function, the following table lists the FIS objects that support using custom functions.
When you create a custom inference function, you must save it in your current working folder or on the MATLAB path. You can then design a FIS that uses the custom inference function at the command line or in the Fuzzy Logic Designer app.
Custom implication functions must operate in the same way as the MATLAB functions max, min, and prod. Your custom implication function must be a T-norm fuzzy intersection operation. For more information, see Additional Fuzzy Operators.
To calculate the output fuzzy set values using the firing strength of all the rules and the corresponding output membership functions. In this case, the software calls the implication function using two inputs as follows.
To calculate the output fuzzy value using the firing strength of a single rule and the corresponding output membership function, for a given sample. In this case, the software calls the implication function using one input, similar to the following example.
Custom aggregation functions must operate in the same way as the MATLAB functions max, min, and prod and must be of the form y = customagg(x). Your custom implication function must be a T-conorm (S-norm) fuzzy intersection operation. For more information, see Additional Fuzzy Operators.
x is an Nv-by-Nr matrix, which is the list of truncated output functions returned by the implication method for each rule. Nv is the number of output variables and Nr is the number of rules. The output of the aggregation method is one fuzzy set for each output variable.
Custom defuzzification functions must be of the form y = customdefuzz(x,ymf), where x is the vector of values in the membership function input range and ymf contains the values of the membership function for each x value.
For type-2 fuzzy inference systems, you can specify a custom type-reduction function. This function must be of the form y = customtr(x,umf,lmf), where x is the vector of values in the membership function input range. umf and lmf are the respective values of the upper and lower membership function for each x value. The output y is a two-element row vector of centroids [cL,cR].
c80f0f1006