# hilomotDemo6 Demo 6: Dynamic process of second order with 1 input and 1 output.

    HiLoMoT - Nonlinear System Identification Toolbox
    Tobias Ebert, 11-May-2012
    Institute of Mechanics & Automatic Control, University of Siegen, Germany
    Copyright (c) 2012 by Prof. Dr.-Ing. Oliver Nelles

    % Training
    LMN = hilomot;                                   % initialize hilomot object

    load hammersteinT.mat                                      % Data for training

    % The training data was created with the input signal stored in inputSequence1.mat
    % which contains steps and an amplitude-modulated pseudo random binary signal covering
    % the complete operating range.
    % The process to be modeled has the following dynamics:
    % y(k) = 0.1044*atan(u(k-1)) + 0.0883*atan(u(k-2)) + 1.4138*y(k-1) - 0.6065*y(k-2);

    LMN.input = data(:,1);
    LMN.output = data(:,2);
    clear data

    % Set delays of input and output regressors
    LMN.xInputDelay = cell(1,1);
    LMN.xOutputDelay = cell(1,1);
    LMN.zInputDelay = cell(1,1);
    LMN.zOutputDelay = cell(1,1);
    LMN.xInputDelay{1} = [1 2];                                % Second order dynamic system
    LMN.xOutputDelay{1} = [1 2];                               % Second order dynamic system
    LMN.zInputDelay{1} = [1 2];                                % Second order dynamic system
    LMN.zOutputDelay{1} = [1 2];                               % Second order dynamic system

    % Try also the following cases:
    % - Premise input space is only of first order
    % hilomotObject.xInputDelay{1} = [1 2];
    % hilomotObject.xOutputDelay{1} = [1 2];
    % hilomotObject.zInputDelay{1} = [1];
    % hilomotObject.zOutputDelay{1} = [1];
    % - Premise input space does only contain the physical inputs (this reflects the Hammerstein structure)
    % hilomotObject.xInputDelay{1} = [1 2];
    % hilomotObject.xOutputDelay{1} = [1 2];
    % hilomotObject.zInputDelay{1} = [1 2];
    % hilomotObject.zOutputDelay{1} = [];
    % - Local finite impulse response (FIR) models (no feedback is involved which requires high feedforward order)
    % hilomotObject.xInputDelay{1} = [1:30];
    % hilomotObject.xOutputDelay{1} = [];
    % hilomotObject.zInputDelay{1} = [1 2];
    % hilomotObject.zOutputDelay{1} = [];

    % Options for training
    LMN.smoothness = 1;
    LMN.maxNumberOfLM = 10;          % Termination criterion for maximal number of LLMs
    LMN.minError = 0;                % Termination criterion for minimal error
    LMN.kStepPrediction = inf;       % Simulation not one-step-ahead prediction
    LMN.history.displayMode = true;  % display information
    LMN.oblique = 1;

    % Train net
    LMN = LMN.train;

    % Generalization
    load hammersteinG.mat

    % The generalization data was generated with the input signal stored in inputSequence2.mat.
    uG = data(:,1);
    yG = data(:,2);
    clear data

    % Simulate net
    yGModel = calculateModelOutput(LMN, uG, yG);
    JG = calcGlobalLossFunction(LMN ,yG, yGModel);

    % Visualization
    figure
    LMN.plotModel

    Initial net has 1 local model(s): J = 0.216676

    1. Iteration. Number of local models = 1. Checking for split of model 1 ...

       Testing split in dimension 1:         J = 0.109344
       Testing split in dimension 2:         J = 0.110596
       Testing split in dimension 3:         J = 0.177672
       Testing split in dimension 4:         J = 0.182042
       Axes-oblique splitting:               J = 0.109177
    -> SPLITTING RESULT:                     J = 0.109177

    2. Iteration. Number of local models = 2. Checking for split of model 2 ...

       Testing split in dimension 1:         J = 0.087291
       Testing split in dimension 2:         J = 0.084441
       Testing split in dimension 3:         J = 0.094178
       Testing split in dimension 4:         J = 0.096472
       Testing parent split:                 J = 0.087407
       Axes-oblique splitting:               J = 0.084440
    -> SPLITTING RESULT:                     J = 0.084440

    3. Iteration. Number of local models = 3. Checking for split of model 3 ...

       Testing split in dimension 1:         J = 0.036457
       Testing split in dimension 2:         J = 0.036830
       Testing split in dimension 3:         J = 0.057996
       Testing split in dimension 4:         J = 0.063525
       Testing parent split:                 J = 0.036619
       Axes-oblique splitting:               J = 0.035462
    -> SPLITTING RESULT:                     J = 0.035462

    4. Iteration. Number of local models = 4. Checking for split of model 5 ...

       Testing split in dimension 1:         J = 0.023066
       Testing split in dimension 2:         J = 0.030361
       Testing split in dimension 3:         J = 0.029462
       Testing split in dimension 4:         J = 0.030009
       Testing parent split:                 J = 0.030367
       Axes-oblique splitting:               J = 0.022969
    -> SPLITTING RESULT:                     J = 0.022969

    5. Iteration. Number of local models = 5. Checking for split of model 6 ...

       Testing split in dimension 1:         J = 0.015725
       Testing split in dimension 2:         J = 0.016090
       Testing split in dimension 3:         J = 0.018878
       Testing split in dimension 4:         J = 0.019527
       Testing parent split:                 J = 0.015690
       Axes-oblique splitting:               J = 0.015664
    -> SPLITTING RESULT:                     J = 0.015664

    6. Iteration. Number of local models = 6. Checking for split of model 7 ...

       Testing split in dimension 1:         J = 0.013475
       Testing split in dimension 2:         J = 0.013052
       Testing split in dimension 3:         J = 0.015161
       Testing split in dimension 4:         J = 0.015213
       Testing parent split:                 J = 0.013449
       Axes-oblique splitting:               J = 0.013046
    -> SPLITTING RESULT:                     J = 0.013046

    7. Iteration. Number of local models = 7. Checking for split of model 4 ...

       Testing split in dimension 1:         J = 0.012305
       Testing split in dimension 2:         J = 0.012481
       Testing split in dimension 3:         J = 0.012865
       Testing split in dimension 4:         J = 0.012940
       Testing parent split:                 J = 0.012481
       Axes-oblique splitting:               J = 0.012305
    -> SPLITTING RESULT:                     J = 0.012305

    8. Iteration. Number of local models = 8. Checking for split of model 8 ...

       Testing split in dimension 1:         J = 0.011611
       Testing split in dimension 2:         J = 0.011149
       Testing split in dimension 3:         J = 0.010668
       Testing split in dimension 4:         J = 0.010843
       Testing parent split:                 J = 0.011583
       Axes-oblique splitting:               J = 0.010636
    -> SPLITTING RESULT:                     J = 0.010636

    9. Iteration. Number of local models = 9. Checking for split of model 11 ...

       Testing split in dimension 1:         J = 0.009758
       Testing split in dimension 2:         J = 0.009010
       Testing split in dimension 3:         J = 0.009129
       Testing split in dimension 4:         J = 0.009091
       Testing parent split:                 J = 0.009809
       Axes-oblique splitting:               J = 0.009010
    -> SPLITTING RESULT:                     J = 0.009010

    Maximum number of local models reached.

    Final net has 10 local models and 86 parameters: J = 0.009010

    Net 10 with 10 LMs and 86 parameters is suggested as the model with the best complexity trade-off.