# Running experiment `estimator` with ARX data fields

The experiment estimator::cpp can be run either on command line, or as a mex file in Matlab.

## Command-line usage

In order to use it for estimation of an ARX model, we can define the following User Infos and their use structure:

    //Data generating system
    system = {
            class = "ArxDS";
            y = {class="RV"; names=("y", "u");};
            u = {class="RV"; names=(); };
            rgr = {class="RV";
                    names = ("y","y","y","u");
                    times = [-1, -2, -3, -1];
            };
            //AR parameters
            theta = (2,4,[0.8, -0.3, 0.4, 1.0,
                          0.0, 0.0, 0.0, 0.0]);
            // offset
            offset = [0.0, 0.0];
            //variance
            r = (2,2,[0.1, 0.0,
                     0.0, 1.0] );
            // log also theta
            opt="L_theta";
    };

    //store results
    logger = {
            class= "dirfilelog";
            dirname = "exp/arx_ui";
            maxlen = 1000; //
    };

    //estimation
    estimator = {
            class = "ARX";
            y = {class="RV"; names=("y"); };
            rgr = {class="RV";
                    names = ("y","y","y","u");
                    times = [-1, -2, -3, -1];
            };

            //optional fields
            dV0 = [1e-3, 1e-5, 1e-5, 1e-5, 1e-5]; //default: 1e-3 for y, 1e-5 for rgr
            nu0 = 8.;      //default: rgrlen + 2
            frg = 1.0;    // forgetting, default frg=1.0
    };

    //experiment description
    experiment:{
            ndat = 9000;
    };

The structure is interpreted by application `estimator`, which looks for fields:

system
  description of a Data Source generating Data. The structure must by UI with `type="DS_offspring"`. In our example, it is of type "ArxDS" which is parsed by bdm::UIArxDS UIbuilder generating a Data Source simulating ARX process.
estimator
  description of a Baysian model used to estimate parameters of the data model. In this case, it is of type "ARXest" which is parsed by bdm::UIARX UIbuilder generating Bayesian estimator of autoregressive processess.
logger
  description of a way how to store results. UI is of `type="logger_offspring"`. In this case, it is of class "dirfilelog" which is parsed by bdm::UIdirfilelog which generates object storing data in directory specified by dirname="" field in fileformat understood by program kst.

When the application estimator is run with the above code, it produces a directory of data files, which can be displayed by program kst. Expected results are:

## Matlab mex file

The matlab mex file can be run with exactly the same configuration as above. However, when we wish to see the results in Matlab, we may wish to change the logger object to `type="mexlog"` which will store the results in a matlab structure.

The exact configuration file may look as follows:

    //Data generating system
    system = { type="external"; filename="arx_test.cfg"; path="system";};

    //store results
    logger = {
            type= "mexlog";
            maxlen = 90; //
        //dirname = "exp/ax";
    };

    //estimation
    estimator = {
       type = "ARX";
            y = {type="RV"; names=("y"); };
            rgr = {type="RV";
                    names = ("y","y","y","u");
                    times = [-1, -2, -3, -1];
            };

            //optional fields
            dV0 = [1e-3, 1e-5, 1e-5, 1e-5, 1e-5]; //default: 1e-3 for y, 1e-5 for rgr
            //nu0 = 8.;      //default: rgrlen + 2
            frg = .9991;    // forgetting, default frg=1.0
    };

    //experiment description
    experiment:{
            ndat = 90;
    };

The resulting structure can be displayed using matlab script arx_test_disp.m, typically producing the following results: