Fuzzy training of outputs example

The fuzzy training will be demonstrated with an artificial example: The saddle function: F(x,y)=x**2 - 4*y**2 is used to build a stub of a fuzzy model ('example/stub.fis') and was used to sample 200 data lines from this function.

In [1]:
import sys
sys.path.append('../src')
import Pyfuzzy as fuzz
%matplotlib inline

In [2]:
f1=fuzz.read_model('stub.fis')

In [3]:
f1.show_model()


Out[3]:
True
The model looks nicely but it was build relying only on expert knowledge. The training data will be used to update the model.

In [4]:
(X,Y)=f1.read_training_data('saddle.dat')  # reads 200 data sets, can be changed using "example/saddle.py"

In [5]:
f1.get_rmse()   # the rsme before training


-c:1: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
Out[5]:
1.1735750436782837

In [6]:
fuzz.start_training(f1)   # the training takes up to one minute, be patient


('minout:', [-22.0, -16.0, -10.0, -4.0, 0.0, 1.0, 4.0])
('maxout:', [-10.0, -4.0, 0.0, 1.0, 4.0, 9.0, 14.0])
('start:', [-16.0, -10.0, -4.0, 0.0, 1.0, 4.0, 9.0])
 *************Result of Optimization*****************
('max:', 0.503550112247467)
('parameter:', array([-14.71604938, -10.09876543,  -3.14814815,   0.14609053,
         2.65843621,   5.79012346,   9.16460905]))
Compare the "start:" which shows the outputs without training and the "parameter:" after training

In [7]:
f1.get_rmse()   # the rsme after training


Out[7]:
0.7095016241073608

In [8]:
f1.show_model()


Out[8]:
True
The model looks similar but more elaboarated, the rsme has changed. This can be understood as combination of rsme and the influence of the "regularization" which was used in the optimization procedure. The example directory contains the files "example/saddle.py" which can be used to build a training data set and the analysis.py to check the training data set. Saddle.py can be adapted to investigate the influence of the training data (for example by adding noise). An other way is to adapt the training parameter in Pyfuzzy.py or adapt the regularization (myfunc) of the fuzzy model.