main content

explain black-凯发k8网页登录

this example shows how to develop a fuzzy inference support system that explains the behavior of a black-box model.

using nondeterministic machine learning methods, such as deep learning, you can design a black-box model to estimate the input-output mapping for a given set of experimental or simulation data. however, the input-output relationship defined by such a black-box model is difficult to understand.

in such cases, a common approach is to create a transparent support system to explain the input-output relationships modeled by the a black box system.

a fuzzy inference system (fis) is a transparent model that represents system knowledge using an explainable rule base. since the rule base of a fuzzy system is easier for a user to intuitively understand, a fis is often used as a support system to explain an existing black box model.

the following figure shows the general steps for developing a fuzzy support system from an existing black box with the assumption that the original training data of the black box is available.

  • tune a support fis using the original training data for the black box.

  • compare the behavior of the black-box system and the fis using test data.

  • examine the fis rules to explain the behavior of the black-box system.

in general, you can uses a fuzzy support system to explain different types of black-box models. for this example, the black-box model is implemented using a deep neural network (dnn), which requires deep learning toolbox™ software.

black-box model

the dnn model for this example imitates an automotive lane keeping assist (lka) system implemented using model predictive control (mpc). a vehicle (ego car) equipped with an lka system has a sensor, such as camera, that measures the lateral deviation and relative yaw angle between the centerline of a lane and the ego car. the sensor also measures the current lane curvature and curvature derivative. depending on the curve length that the sensor can view, the curvature in front of the ego car can be calculated from the current curvature and curvature derivative. the lka system keeps the ego car travelling along the centerline of the lane by adjusting the front steering angle of the ego car. the goal for lane keeping control is to drive both lateral deviation and relative yaw angle close to zero. for more information on lane keeping using mpc, see (model predictive control toolbox).

the dnn-based lka system uses the following inputs to generate the output steering angle u*.

  1. lateral velocity vy m/s

  2. yaw angle rate r rad/s

  3. lateral deviation e1 m

  4. relative yaw angle e2 rad

  5. previous steering angle (control variable) u rad

  6. measured disturbance (road yaw rate: longitudinal velocity * curvature (ρ))

for more information on creating and training the dnn, see (reinforcement learning toolbox).

download and unzip the data for this example.

datafile = matlab.internal.examples.downloadsupportfile("fuzzy","fuzzylkadata.zip");
unzip(datafile)
data = load('dataexplaindnn.mat');

obtain the saved dnn model of an lka system.

dnnlka = data.traineddnn;

the trained dnn predicts a steering angle based on the current input values to keep the car along the centerline of a lane. to make a prediction, use the predict function. for example, the following command predicts the steering angle when all input signals are zero.

steeringangle = predict(dnnlka,zeros(1,6))
steeringangle = single
    -0.0195

however, the dnn model does not provide any explanation about how it derives the steering angle. the dnn model parameters are the steering angle generation algorithm in terms of hidden units and their associated parameters. therefore, input-output relations cannot be described using the dnn structure alone.

figure
plot(layergraph(dnnlka))

to explain the dnn model behavior, you can create and tune a fuzzy support system.

create initial fuzzy inference system

for an lka controller with six inputs, a single monolithic fis contains a large complex rule base that is difficult to interpret. as an alternative. you can create a fis tree that incrementally combines input values using multiple fiss, each with a smaller rule base.

create a fis tree with four layers and five fiss. each fis has two inputs and one output. to create each component fis, use the constructfis helper function, which is shown at the end of this example.

nummfs = 2;
fis1 = constructfis('fis1',nummfs, ...
    data.vrange,data.e1range,data.urange,'vy','e1','u1');
fis2 = constructfis('fis2',nummfs, ...
    data.rrange,data.e2range,data.urange,'r','e2','u2');
fis3 = constructfis('fis3',nummfs, ...
    data.urange,data.urange,data.urange,'u1','u2','u3');
fis4 = constructfis('fis4',nummfs, ...
    data.urange,data.urange,data.urange,'u3','u','u4');
fis5 = constructfis('fis5',nummfs, ...
    data.urange,data.drange,data.urange,'u4','d','u*');
fis = [fis1 fis2 fis3 fis4 fis5];
connections = [...
    fis1.name "/" fis1.outputs(1).name fis3.name "/" fis3.inputs(1).name; ...
    fis2.name "/" fis2.outputs(1).name fis3.name "/" fis3.inputs(2).name; ...
    fis3.name "/" fis3.outputs(1).name fis4.name "/" fis4.inputs(1).name; ...
    fis4.name "/" fis4.outputs(1).name fis5.name "/" fis5.inputs(1).name ...
    ];
fistin = fistree(fis,connections);

view the fis tree structure.

showfistree(fistin)

in this fis tree:

  • the first layer uses two fiss: fis1 and fis2, where fis1 combines lateral velocity (vy) and lateral deviation (e1), and fis2 combines yaw angle (r) and relative yaw angle (e2) to predict expected steering angles u1 and u2 for the respective input values.

  • the second layer uses fis3 to combine the outputs of fis1 and fis2, that is, fis3 combines the effects of lateral displacement and yaw angle to produce a desired steering angle (u3) for the lka system.

  • the third layer uses fis4 to combine the effect of the previous steering angle (u) with the output of second layer to generate u4.

  • the fourth layer combines the effect of the measured disturbance (d) with the desired steering angle predicted by the previous layers using fis5.

each input of a fis includes two membership functions (mfs) and each output includes four mfs. as a result, each fis has four rules and the overall fis tree has 20 rules.

tune fuzzy inference system

for this example, you tune the fis in two stages.

  1. establish the input-output relations for each fis by learning the output membership functions for each possible input combination.

  2. tune the mf parameters for the input and output variables of each fis.

to learn the output membership functions for each rule, first obtain the rule parameter settings from the initial fis fistin.

[~,~,rule] = gettunablesettings(fistin);

then, specify that the antecedent membership functions are fixed during the tuning process.

for ct = 1:length(rule)
     rule(ct).antecedent.free = 0;
end

create an option set for tuning. use the default genetic algorithm (ga) tuning method. set maximum stall generations to 5.

options = tunefisoptions;
options.methodoptions.maxstallgenerations = 5;

to visualize the convergence process, set the plotfcn tuning method option to gaplotbestf.

options.methodoptions.plotfcn = @gaplotbestf;

to prevent overfitting, use k-fold cross validation with two partitions.

options.kfoldvalue = 2;

tuning is a time-consuming process, so for this example, load a pretuned fis tree. to tune the fis tree yourself instead, set runtunefis to true.

runtunefis = false;

since the fis tree input order is different than that of the black-box model, reorder the training data.

traininputdata = [data.vy data.e1 data.r data.e2 data.uprev data.d];

tune the fuzzy rules. for reproducibility, reset the random number generator using the default seed.

if runtunefis
    rng('default')
    fistoutr = tunefis(fistin,rule,traininputdata,data.trainoutputdata,options);
else
    fistoutr = data.fistoutr;
end

evaluate the performance of the fis using the training data. the calculaterms helper function evaluates the input data using the specified fis and computes the rms error for the result.

rms = calculaterms(fistoutr,traininputdata,data.trainoutputdata)
rms = 0.3507

display the tuned rule base of each fis in the tree using the showrules helper function.

showrules(fistoutr)
                fis1rules                           fis2rules            
    _________________________________    ________________________________
    "vy==mf1 & e1==mf1 => u1=mf4 (1)"    "r==mf1 & e2==mf1 => u2=mf1 (1)"
    "vy==mf2 & e1==mf1 => u1=mf3 (1)"    "r==mf2 & e2==mf1 => u2=mf2 (1)"
    "vy==mf1 & e1==mf2 => u1=mf2 (1)"    "r==mf1 & e2==mf2 => u2=mf4 (1)"
    "vy==mf2 & e1==mf2 => u1=mf1 (1)"    "r==mf2 & e2==mf2 => u2=mf3 (1)"
                fis3rules                           fis4rules            
    _________________________________    ________________________________
    "u1==mf1 & u2==mf1 => u3=mf3 (1)"    "u3==mf1 & u==mf1 => u4=mf1 (1)"
    "u1==mf2 & u2==mf1 => u3=mf4 (1)"    "u3==mf2 & u==mf1 => u4=mf4 (1)"
    "u1==mf1 & u2==mf2 => u3=mf1 (1)"    "u3==mf1 & u==mf2 => u4=mf1 (1)"
    "u1==mf2 & u2==mf2 => u3=mf2 (1)"    "u3==mf2 & u==mf2 => u4=mf4 (1)"
               fis5rules            
    ________________________________
    "u4==mf1 & d==mf1 => u*=mf1 (1)"
    "u4==mf2 & d==mf1 => u*=mf4 (1)"
    "u4==mf1 & d==mf2 => u*=mf1 (1)"
    "u4==mf2 & d==mf2 => u*=mf4 (1)"

fis1, fis3, fis4, and fis5 do not use all of the output mfs. hence, you can remove these unused output membership functions.

fistoutr2 = fistoutr;
for ct = 1:length(fistoutr2.fis)
    numoutputmfs = length(fistoutr2.fis(ct).outputs(1).membershipfunctions);
    numoutputmfused = unique([fistoutr2.fis(ct).rules.consequent]);
    numoutputmfnotused = setdiff(1:numoutputmfs,numoutputmfused);
    if ~isempty(numoutputmfnotused)
        fistoutr2.fis(ct).outputs(1).membershipfunctions(numoutputmfnotused) = [];
    end
end

next, tune the input and output mf parameters. to do so, first get the input and output variable tunable settings for the fis tree.

[in,out] = gettunablesettings(fistoutr2);

to improve the optimization results, increase the mf parameter ranges.

for fisid = 1:numel(fistoutr2.fis)
    id = (fisid-1)*2;
    for inid = 1:numel(fistoutr2.fis(fisid).inputs)
        d = diff(fistoutr2.fis(fisid).inputs(inid).range);
        l = fistoutr2.fis(fisid).inputs(inid).range(1)-0.5*d;
        u = fistoutr2.fis(fisid).inputs(inid).range(2) 0.5*d;
        for mfid = 1:numel(fistoutr2.fis(fisid).inputs(inid).membershipfunctions)
            in(id inid).membershipfunctions(mfid).parameters.minimum = l;
            in(id inid).membershipfunctions(mfid).parameters.maximum = u;
        end
    end
end

use the patternsearch algorithm for tuning the mf parameters.

options.method = 'patternsearch';

to visualize the convergence process, set the plotfcn tuning method option to psplotbestf.

options.methodoptions.plotfcn = @psplotbestf;

tune the mf parameters.

if runtunefis
    rng('default')
    options.methodoptions.maxiterations = 10;
    fistoutmf = tunefis(fistoutr2,[in;out],traininputdata,data.trainoutputdata,options);
else
    fistoutmf = data.fistoutmf;
end

the lower rms error indicates that the fuzzy system performance improves after tuning the mf parameters.

rms = calculaterms(fistoutmf,traininputdata,data.trainoutputdata)
rms = 0.0506

compare fis to black-box model

before you can explain the behavior of the black-box model, first verify that the tuned fis properly reproduces the behavior of the black-box model.

evaluate the test data using the black-box dnn model and compute the rms error for the result.

ydnn = predict(dnnlka,data.testinputdata);
d = ydnn - data.testoutputdata;
rmsednn = sqrt(mean(d.^2))
rmsednn = single
    0.0320

evaluate the test data using the fis and compute the rms error for the result. also, return the computed steering angles in yfis.

testinputdata = [data.testinputdata(:,1) data.testinputdata(:,3) ...
    data.testinputdata(:,2) data.testinputdata(:,4:6)];
[rmsefis,yfis] = calculaterms(fistoutmf,testinputdata,data.testoutputdata);
rmsefis
rmsefis = 0.0518

the low rms error values indicate that both the dnn and fis closely reproduce the steering angles in the output training data. to further validate this result, plot the calculated steering angles for both systems over a subset of the training data.

start = 1;
stop = 50;
x = 1:length(data.testoutputdata);
plot(x(start:stop),data.testoutputdata(start:stop), ...
    x(start:stop),ydnn(start:stop), ...
    x(start:stop),yfis(start:stop))
xlabel("test data point")
ylabel("steering angle (radians)")
legend("test data","dnn","fis")

the dnn and fis both reproduce the expected steering angles from the training data.

explain black-box model using fis

to explain the black-box model, first specify meaningful names for the mfs of each fis. doing so improves the interpretability of the fis behavior.

mfnames = {...
    ["negative" "positive"], ...
    ["negative" "zero" "positive"], ...
    ["negativelow" "negative" "positive" "positivehigh"] ...
    };
for fisid = 1:numel(fistoutmf.fis)
    for inid = 1:numel(fistoutmf.fis(fisid).inputs)
        numinputmfs = numel(fistoutmf.fis(fisid).inputs(inid).membershipfunctions);
        names = mfnames{numinputmfs-1};
        for mfid = 1:numel(fistoutmf.fis(fisid).inputs(inid).membershipfunctions)
            fistoutmf.fis(fisid).inputs(inid).membershipfunctions(mfid).name = names(mfid);
        end
    end
    numoutputmfs = numel(fistoutmf.fis(fisid).outputs(1).membershipfunctions);
    names = mfnames{numoutputmfs-1};
    for mfid = 1:numoutputmfs
        fistoutmf.fis(fisid).outputs(1).membershipfunctions(mfid).name = names(mfid);
    end
end

view the fis rules.

showrules(fistoutmf)
                         fis1rules                                               fis2rules                     
    ____________________________________________________    ___________________________________________________
    "vy==negative & e1==negative => u1=positivehigh (1)"    "r==negative & e2==negative => u2=negativelow (1)" 
    "vy==positive & e1==negative => u1=positive (1)"        "r==positive & e2==negative => u2=negative (1)"    
    "vy==negative & e1==positive => u1=negative (1)"        "r==negative & e2==positive => u2=positivehigh (1)"
    "vy==positive & e1==positive => u1=negativelow (1)"     "r==positive & e2==positive => u2=positive (1)"    
                         fis3rules                                             fis4rules                   
    ____________________________________________________    _______________________________________________
    "u1==negative & u2==negative => u3=positive (1)"        "u3==negative & u==negative => u4=negative (1)"
    "u1==positive & u2==negative => u3=positivehigh (1)"    "u3==positive & u==negative => u4=positive (1)"
    "u1==negative & u2==positive => u3=negativelow (1)"     "u3==negative & u==positive => u4=negative (1)"
    "u1==positive & u2==positive => u3=negative (1)"        "u3==positive & u==positive => u4=positive (1)"
                       fis5rules                   
    _______________________________________________
    "u4==negative & d==negative => u*=negative (1)"
    "u4==positive & d==negative => u*=positive (1)"
    "u4==negative & d==positive => u*=negative (1)"
    "u4==positive & d==positive => u*=positive (1)"

you can make the following observations from the rule bases.

  • steering angle u1 (output of fis1) is inversely proportional to lateral velocity (vy) and deviation (e1). for example, the first rule of fis1 describes that the steering angle u1 is positivehigh (high positive value) when the lateral velocity (vy) and deviation (e1) are both negative.

  • steering angle u2 (output of fis2) is proportional to yaw angle rate (r) and relative yaw angle (e2). for example, the first rule of fis2 describes that the steering angle u2 is negativelow (low negative value) when the yaw angle rate (r) and relative yaw angle (e2) are both negative.

  • steering angles u1 (output of fis1) and u2 (output of fis2) have a negative correlation, that is, fis3 output u3 increases when u1 increases, whereas u3 decreases when u2 increases. hence, the lateral deviation and yaw angle have opposite effects on the steering angle.

  • the rule base of fis4 shows that the previous steering input u has insignificant effect on the steering angle calculation. the output u4 of fis4 uses similar linguistic variables as does the output of fis3.

  • the measured disturbance d also has insignificant effect on the steering angle calculation since the output u5 of fis5 uses similar linguistic variables as does the output of fis4.

hence, the rule bases of the fiss in the fis tree describe the effects and relations between the input variables for steering calculation in the lka system.

you can visualize each rule base using its control surface, which describes numerical mappings from the inputs to output according to the rule base.

figure
subplot(3,2,1)
gensurf(fistoutmf.fis(1))
subplot(3,2,2)
gensurf(fistoutmf.fis(2))
subplot(3,2,3)
gensurf(fistoutmf.fis(3))
subplot(3,2,4)
gensurf(fistoutmf.fis(4))
subplot(3,2,5)
gensurf(fistoutmf.fis(5))

a fuzzy rule base provides linguistic relation between the inputs and output. the control surface augments this linguistic relation by adding numeric detail for input to output mapping.

explain run-time black-box predictions

the previous explanation of the black-box behavior describes the general relationships between the input observations and the resulting steering angle by interpreting the rule base of the fuzzy support system itself.

you can also use the support system to explain black-box outcomes generated in each control interval. the following diagram explains the parallel execution settings of the black-box model and the support system for run-time explanation of the black-box predictions.

compare_0.png

the black-box model and the support system run in parallel and use the same input values (observations) for output prediction. the prediction from black-box model drives environment changes, while the support system only explains the black-box predictions. for this example, the fuzzy support system includes the following components in the explanation for each control interval.

  1. current simulation time

  2. current input values

  3. steering angle outputs generated by the dnn black-box model and fuzzy support system

  4. fuzzy rules having the maximum firing strength from each fis of the fis tree.

the output data format for each control interval is as follows.

================ simulation time:  sec ================
inputs: [v r e1 e2 u d], outputs: [u*(dnn) u*(fuzzy)] rad
max strength rules:
    fis1:  
    fis2:  
    fis3: 
    fis4:  
    fis5: 

the following simulation results explain the dnn model outputs in each control cycle using the fuzzy support system.

initialize the vehicle state using the input from a test data point.

id = round(median(1:size(data.testinputdata,1)));
x0 = data.testinputdata(id,:);

simulate the dnn and fis with the same input data using the comparednnwithfis helper function.

[dnnoutputs,fisoutput] = comparednnwithfis(dnnlka,fistoutmf,data,x0);
================ simulation time: 0 sec ================
inputs: [0.0737824 -0.726656 -0.0161284 0.0484033 0.569496 -0.00256057], 
outputs: [1.01041 1.0472] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==positive => u2=positive (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==positive & u==negative => u4=positive (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 0.1 sec ================
inputs: [1.2579 -0.532934 1.33827 0.119282 1.01041 -0.00256057], 
outputs: [-0.0654638 -0.114224] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==positive => u2=positive (1)
	fis3: u1==positive & u2==positive => u3=negative (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==negative & d==negative => u*=negative (1)
================ simulation time: 0.2 sec ================
inputs: [-0.338464 -0.23482 0.745212 0.222974 -0.0654638 -0.00256057], 
outputs: [-0.933683 -0.982878] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==positive => u2=positive (1)
	fis3: u1==positive & u2==positive => u3=negative (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==negative & d==negative => u*=negative (1)
================ simulation time: 0.3 sec ================
inputs: [-1.86933 -0.0209625 -0.862648 0.212142 -0.933683 -0.00256057], 
outputs: [-0.817988 -0.751812] rad
max strength rules:
	fis1: vy==negative & e1==negative => u1=positivehigh (1)
	fis2: r==negative & e2==positive => u2=positivehigh (1)
	fis3: u1==positive & u2==positive => u3=negative (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==negative & d==negative => u*=negative (1)
================ simulation time: 0.4 sec ================
inputs: [-1.43016 0.0363023 -1.71046 0.0795596 -0.817988 -0.00256057], 
outputs: [0.067486 0.285178] rad
max strength rules:
	fis1: vy==negative & e1==negative => u1=positivehigh (1)
	fis2: r==negative & e2==positive => u2=positivehigh (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==positive & u==negative => u4=positive (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 0.5 sec ================
inputs: [0.518155 0.0163838 -0.959078 -0.0526409 0.067486 -0.00256057], 
outputs: [0.341617 0.307694] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==negative & e2==negative => u2=negativelow (1)
	fis3: u1==negative & u2==negative => u3=positive (1)
	fis4: u3==positive & u==negative => u4=positive (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 0.6 sec ================
inputs: [1.43122 0.00176658 -0.0241615 -0.0985401 0.341617 -0.00256057], 
outputs: [0.2509 0.266469] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==negative => u2=negative (1)
	fis3: u1==negative & u2==negative => u3=positive (1)
	fis4: u3==positive & u==negative => u4=positive (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 0.7 sec ================
inputs: [1.16149 -0.000896733 0.439618 -0.075189 0.2509 -0.00256057], 
outputs: [0.0708356 0.0913793] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==negative => u2=negative (1)
	fis3: u1==negative & u2==negative => u3=positive (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 0.8 sec ================
inputs: [0.440393 -0.00281434 0.429965 -0.0306668 0.0708356 -0.00256057], 
outputs: [-0.018147 0.00702747] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==negative => u2=negative (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 0.9 sec ================
inputs: [-0.0839109 -0.00710326 0.246288 0.00320765 -0.018147 -0.00256057], 
outputs: [-0.0571112 -0.0431572] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==negative => u2=negative (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==negative & d==negative => u*=negative (1)
================ simulation time: 1 sec ================
inputs: [-0.302092 -0.0110731 0.0509452 0.0177286 -0.0571112 -0.00256057], 
outputs: [-0.0356867 -0.00903791] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==positive => u2=positive (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==negative & d==negative => u*=negative (1)
================ simulation time: 1.1 sec ================
inputs: [-0.258972 -0.012099 -0.0449731 0.0178176 -0.0356867 -0.00256057], 
outputs: [-0.0338398 -0.00862586] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==positive => u2=positive (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==negative & d==negative => u*=negative (1)
================ simulation time: 1.2 sec ================
inputs: [-0.159425 -0.01097 -0.091006 0.0109606 -0.0338398 -0.00256057], 
outputs: [-0.0138319 0.000404072] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==positive => u2=positive (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 1.3 sec ================
inputs: [-0.0423529 -0.0105425 -0.0811233 0.00251846 -0.0138319 -0.00256057], 
outputs: [0.000331631 0.0269576] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==negative => u2=negative (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 1.4 sec ================
inputs: [0.0361998 -0.0114349 -0.0471621 -0.00358271 0.000331631 -0.00256057], 
outputs: [0.0304953 0.0473974] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==negative => u2=negative (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 1.5 sec ================
inputs: [0.0930044 -0.0110261 0.0178849 -0.0045736 0.0304953 -0.00256057], 
outputs: [0.00543881 0.0263823] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==negative => u2=negative (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 1.6 sec ================
inputs: [0.0479659 -0.00916726 0.0247146 -0.00210616 0.00543881 -0.00256057], 
outputs: [-0.00489218 0.013721] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==negative => u2=negative (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 1.7 sec ================
inputs: [0.00396816 -0.00833844 0.0109447 -7.63103e-05 -0.00489218 -0.00256057], 
outputs: [-0.0103413 0.0106303] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==negative => u2=negative (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 1.8 sec ================
inputs: [-0.018166 -0.0089212 -0.00744726 0.000300261 -0.0103413 -0.00256057], 
outputs: [-0.00482928 0.0185661] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==negative => u2=negative (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 1.9 sec ================
inputs: [-0.0108874 -0.0104442 -0.0119736 -0.00044273 -0.00482928 -0.00256057], 
outputs: [0.00649286 0.0270567] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==negative => u2=negative (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 2 sec ================
inputs: [0.0102737 -0.0112775 0.00120233 -0.000692395 0.00649286 -0.00256057], 
outputs: [0.00606815 0.023241] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==negative => u2=negative (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 2.1 sec ================
inputs: [0.0123836 -0.0105726 0.00956554 0.000135917 0.00606815 -0.00256057], 
outputs: [-0.00548606 0.0132276] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==negative => u2=negative (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 2.2 sec ================
inputs: [-0.00638756 -0.00962136 -0.00104885 0.000793332 -0.00548606 -0.00256057], 
outputs: [-0.0101493 0.0127077] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==negative => u2=negative (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 2.3 sec ================
inputs: [-0.0150607 -0.00993626 -0.0145728 0.000219598 -0.0101493 -0.00256057], 
outputs: [-0.000622749 0.0224691] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==negative => u2=negative (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 2.4 sec ================
inputs: [0.00129175 -0.0109741 -0.0100013 -0.000752014 -0.000622749 -0.00256057], 
outputs: [0.00826702 0.0272876] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==negative => u2=negative (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 2.5 sec ================
inputs: [0.0180957 -0.0110403 0.00564719 -0.000665084 0.00826702 -0.00256057], 
outputs: [0.00268267 0.0195868] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==negative => u2=negative (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 2.6 sec ================
inputs: [0.00964099 -0.00996295 0.00814148 0.000300946 0.00268267 -0.00256057], 
outputs: [-0.00864567 0.0113769] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==negative => u2=negative (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 2.7 sec ================
inputs: [-0.0106986 -0.00937355 -0.00624473 0.000612801 -0.00864567 -0.00256057], 
outputs: [-0.00803808 0.0154329] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==negative => u2=negative (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 2.8 sec ================
inputs: [-0.0111989 -0.0101628 -0.0149538 -0.000228281 -0.00803808 -0.00256057], 
outputs: [0.00356137 0.0254181] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==negative => u2=negative (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==positive & d==negative => u*=positive (1)
================ simulation time: 2.9 sec ================
inputs: [0.00883551 -0.0110872 -0.00433248 -0.000913484 0.00356137 -0.00256057], 
outputs: [0.00806062 0.0257676] rad
max strength rules:
	fis1: vy==positive & e1==negative => u1=positive (1)
	fis2: r==positive & e2==negative => u2=negative (1)
	fis3: u1==positive & u2==negative => u3=positivehigh (1)
	fis4: u3==negative & u==negative => u4=negative (1)
	fis5: u4==positive & d==negative => u*=positive (1)

plot the dnn and fis outputs.

plotvalidationresults(data.ts,dnnoutputs,fisoutput)

as expected, the fuzzy support system produces similar steering angle outputs as compared to the dnn black-box model.

explanation using fuzzy rule inference

you can further explore the decision-making process of a fis in the tree using its rule inference viewer. for example, the following simulation shows rule inference process of fis1 of the fis tree.

fisindex = 1;
showruleinference(data,fistoutmf,fisindex,x0)

the left plot shows the output pattern of fis1 as compared to the overall fis tree output. the right plot shows individual rule activations of fis1 in each control cycle.

fis tree data propagation

finally, you can also visualize how each fis contributes to the decision-making process for a given set of input values. the following example shows output propagation in the fis tree for a test input vector.

[~,~,fisins,fisouts] = evaluatefistree(fistoutmf,[x0(1) x0(3) x0(2) x0(4:6)]);
fistwithiovalues = updatelabelswithiovalues(fistoutmf,fisins,fisouts);
showfistree(fistwithiovalues,0.85)

for this combination of input values, the output of fis1 dominates over the fis2 output, which indicates that lateral displacement and its rate contribute more to the overall output value.

conclusion

you can further improve the performance of the support fuzzy system by using:

  • additional input mfs

  • continuous mfs for smooth variations in outputs

  • more training data, and

  • different configurations of the fis tree, as shown in the following figure

showotherblackboxfistrees(data)
example 1

example 2

different tuning methods with different random number generation seeds may also improve the optimization of the support system.

you can also intuitively update each individual fis rule base to check possible variations in output generation to further improve the performance of the support system.

helper functions

function fis = constructfis(name,nummfs,in1range,in2range,outrange,in1,in2,out)
% construct a sugeno fis.
fis = sugfis('name',name);
numoutputmfs = nummfs^2;
fis = addinput(fis,in1range,'name',in1,'nummfs',nummfs);
fis = addinput(fis,in2range,'name',in2,'nummfs',nummfs);
for ct = 1:2
    fis.inputs(ct).membershipfunctions(1).type = 'linzmf';
    fis.inputs(ct).membershipfunctions(end).type = 'linsmf';
    nummfs = length(fis.inputs(ct).membershipfunctions);
end
fis = addoutput(fis,outrange,'name',out,'nummfs',numoutputmfs);
range = 1:nummfs;
[in1,in2] = ndgrid(range,range);
rules = [in1(:) in2(:) ones(numoutputmfs,3)];
fis = addrule(fis,rules);
end
function [rms,yfis] = calculaterms(fis,x,y)
% evaluate the fis using the specified input data and calculate the rms error
% the simulated and reference outputs.
options = evalfisoptions;
options.emptyoutputfuzzysetmessage = 'none';
options.norulefiredmessage = 'none';
options.outofrangeinputvaluemessage = 'none';
yfis = evalfis(fis,x,options);
e = yfis - y;
rms = sqrt(mean(e.*e));
end
function showrules(fist)
% display rule bases of the fiss in a fis tree as tables.
fis1rules = [fist.fis(1).rules.description]';
fis2rules = [fist.fis(2).rules.description]';
fis3rules = [fist.fis(3).rules.description]';
fis4rules = [fist.fis(4).rules.description]';
fis5rules = [fist.fis(5).rules.description]';
disp(table(fis1rules,fis2rules))
disp(table(fis3rules,fis4rules))
disp(table(fis5rules))
end
function [uhistorydnn,uhistoryfis] = comparednnwithfis(dnnlka,fistoutmf,data,x0)
% compares dnn and fis tree model.
xhistorydnn = repmat(x0(1:4),data.tsteps 1,1);
uhistorydnn = zeros(data.tsteps,1);
uhistoryfis = zeros(data.tsteps,1);
lastmv = x0(5);
d = x0(6);
for k = 1:data.tsteps
    % obtain plant output measurements, which correspond to the plant outputs.
    xk = xhistorydnn(k,:)';
    % predict the next move using the trained deep neural network.
    in = [xk',lastmv,d];
    ukdnn = predict(dnnlka,in);
    % predict the next move using the trained fuzzy system.
    tmp = in(2); in(2) = in(3); in(3) = tmp; % config 1
    [ukfis,maxrules] = evaluatefistree(fistoutmf,in);
    % store the control action and update the last mv for the next step.
    uhistorydnn(k,:) = ukdnn;
    uhistoryfis(k,:) = ukfis;
    lastmv = ukdnn;
    % update the state using the control action.
    xhistorydnn(k 1,:) = (data.a*xk   data.b*[ukdnn;d])';
    % explanations/diagnostics
    fprintf('\n================ simulation time: %g sec ================',...
        (k-1)*data.ts);
    fprintf('\ninputs: [%g %g %g %g %g %g], \noutputs: [%g %g] rad', ...
        in(1),in(2),in(3),in(4),in(5),in(6),ukdnn,ukfis);
    fprintf('\nmax strength rules:');
    fprintf('\n\tfis1: %s\n\tfis2: %s\n\tfis3: %s\n\tfis4: %s\n\tfis5: %s', ...
        maxrules(1),maxrules(2),maxrules(3),maxrules(4),maxrules(5));
end
end
function [y,maxrules,fisins,fisouts] = evaluatefistree(fist,x)
% evaluates fis tree with the specified input values.
options = evalfisoptions;
options.outofrangeinputvaluemessage = 'none';
options.norulefiredmessage = 'none';
options.emptyoutputfuzzysetmessage = 'none';
numfis = numel(fist.fis);
fisins = zeros(numfis,2);
fisins(1,:) = x(1:2);
[y1,~,~,~,rfs1] = evalfis(fist.fis(1),x(1:2),options);
fisins(2,:) = x(3:4);
[y2,~,~,~,rfs2] = evalfis(fist.fis(2),x(3:4),options);
fisins(3,:) = [y1 y2];
[y3,~,~,~,rfs3] = evalfis(fist.fis(3),[y1 y2],options);
fisins(4,:) = [y3 x(5)];
[y4,~,~,~,rfs4] = evalfis(fist.fis(4),[y3 x(5)],options);
fisins(5,:) = [y4 x(6)];
[y,~,~,~,rfs5] = evalfis(fist.fis(5),[y4 x(6)],options);
fisouts = [y1 y2 y3 y4 y];
[~,id1] = sort(rfs1,'descend');
[~,id2] = sort(rfs2,'descend');
[~,id3] = sort(rfs3,'descend');
[~,id4] = sort(rfs4,'descend');
[~,id5] = sort(rfs5,'descend');
maxrules = [...
    fist.fis(1).rules(id1(1)).description; ...
    fist.fis(2).rules(id2(1)).description; ...
    fist.fis(3).rules(id3(1)).description; ...
    fist.fis(4).rules(id4(1)).description; ...
    fist.fis(5).rules(id5(1)).description ...
    ];
end
function plotvalidationresults(ts,udnn,ufis)
% plot validation results of the dnn and fis tree model.
figure
% plot output steering angles of dnn and fis.
tu  = ((0:(size(udnn,1))-1)*ts)';
stairs(tu,udnn);
title('dnn and fis output comparison')
xlabel('time (s)')
ylabel('steering angle (rad)')
axis([0 tu(end) -1.1 1.1]);
hold on
stairs(tu,ufis);
legend('dnn','fis')
grid on;
hold off
pause(0.1)
end

see also

| |

related topics

网站地图