Index: /library/doc/tutorial/000install.dox
===================================================================
--- /library/doc/tutorial/000install.dox (revision 948)
+++ /library/doc/tutorial/000install.dox (revision 983)
@@ -6,6 +6,6 @@
 
 BDM comes in two basic versions:
-\li \b binary   with precompiled executables and matlab mex files that can be configured by external text files
-\li \b source \b code  that can be compiled into any required form. 
+ - \b binary   with precompiled executables and matlab mex files that can be configured by external text files
+ - \b source \b code  that can be compiled into any required form. 
 
 \section in_bin Binaries for BDMtoolbox
@@ -13,7 +13,7 @@
 
 Installation:
-\li svn checkout http://mys.utia.cas.cz:1800/svn/mixpp/applications/bdmtoolbox/ into your local directory of your choice (this will be denoted \<toolbox_dir\>)
-\li or download a prepared zip file from http://staff.utia.cas.cz/smidl/Public/bdmtoolbox_win32.zip and extract it to any directory (will be denoted \<toolbox_dir\>)
-\li open matlab and type:
+ - svn checkout http://mys.utia.cas.cz:1800/svn/mixpp/applications/bdmtoolbox/ into your local directory of your choice (this will be denoted \<toolbox_dir\>)
+ - or download a prepared zip file from http://staff.utia.cas.cz/smidl/Public/bdmtoolbox_win32.zip and extract it to any directory (will be denoted \<toolbox_dir\>)
+ - open matlab and type:
 \code 
 >> addpath <toolbox_dir>/mex; 
@@ -29,9 +29,9 @@
 \endcode
 For linux, the default build dir is \<toolbox_dir\>/mex, hence only me and mex_classes need to be in the path.
-\li the toolbox is ready to be used, test it e.g. by: 
+ - the toolbox is ready to be used, test it e.g. by: 
 \code >> cd tutorial/userguide; 
 >> pdfds_example \endcode
-\li if no error is given, the toolbox is installed correctly
-\li proceed to tutorial at http://mys.utia.cas.cz:1800/trac/bdm/doxygen/pages.html to learn how to use it
+ - if no error is given, the toolbox is installed correctly
+ - proceed to tutorial at http://mys.utia.cas.cz:1800/trac/bdm/doxygen/pages.html to learn how to use it
 
 \section src Source code
@@ -47,6 +47,6 @@
 
 You need to have the following tools available on your system:
-\li working C++ compiler, e.g. gcc on Linux, or Visual Studio on windows
-\li CMake, a cross-platform build system, http://www.cmake.org
+ - working C++ compiler, e.g. gcc on Linux, or Visual Studio on windows
+ - CMake, a cross-platform build system, http://www.cmake.org
  
 \section lin Linux
@@ -89,12 +89,12 @@
 Compilation of BDM:
 
- * When everything is set-up, make a copy of library\system\win32\run_cmake.bat, edit it 
+ - When everything is set-up, make a copy of library\system\win32\run_cmake.bat, edit it 
   to reflect your environment (i.e. change paths to cmake and your C++ target environment) 
   and run it.
 
- * Alternatively, you can run CMake GUI and specify address to your \<bdm_dir\>
+ - Alternatively, you can run CMake GUI and specify address to your \<bdm_dir\>
 
 
- * It should generate build files for your compiler in the main BDM 
+ - It should generate build files for your compiler in the main BDM 
   directory
 
@@ -108,5 +108,5 @@
 
 Right now, Cmake configuration is hard-coded for one testing machine. Look for the paths in SetBDMEnv.cmake and correct them.
-Open CMake GUI, clisk Configure followed by Create.
+Open CMake GUI, click Configure followed by Create.
 Configuration files for your favourite build environment should be created in the BDM directory.
 
Index: /library/doc/tutorial/045devguide_cpp.dox
===================================================================
--- /library/doc/tutorial/045devguide_cpp.dox (revision 983)
+++ /library/doc/tutorial/045devguide_cpp.dox (revision 983)
@@ -0,0 +1,33 @@
+/*!
+\page devguide_cpp  BDM Development - your first bdm application in C++
+
+In principle, BDM is just another library which you can use in a standard way.
+To ease the learning curve for newcommers, we provide the following starting application:
+
+The application itself is in directory applications/example_application
+Where the following files are provided:
+
+ - <b>example_lib.[h,cpp]</b> files in which your extensions of BDM classes are defined.
+ - <b>example_main.cpp</b> the main application which calls routines from library example_lib
+ - <b>CMakeList.txt</b>   which contains information for cmake how to build the example_lib library and link it with tha main application
+ 
+ To build the application, you need to use Cmake:
+ In Linux:
+ \code
+ $ cd path_to_example_application/
+ $ cmake .
+ $ make
+ \endcode
+In windows and Mac:
+  - Open CMake GUI and fill the path_to_example_application in both fields for paths
+  - click Configure, pick your development environment (e.g. VisualStudio 2010)
+  - click Generate, which will create project file for your environment (e.g. example_application.sln for VS10)
+  - open the created file and press build
+  
+ Where to go next:
+  - see trivial examples in library/tests/tutorial/arx_simple.cpp and kalman_simple.cpp.
+  - in directory applications/bdmtoolbox/mex are examples of more advanced applications using the root classes of BDM. 
+  
+
+
+*/
Index: /library/doc/tutorial/02userguide_estim.dox
===================================================================
--- /library/doc/tutorial/02userguide_estim.dox (revision 948)
+++ /library/doc/tutorial/02userguide_estim.dox (revision 983)
@@ -28,5 +28,5 @@
 \li Result Logger is an object (class logger) dedicated to storing important data from the experiment.
 
-Since objects  datasource and the logger has already been introduced in section \ref userguide, it remains to introduce 
+Since objects  datasource and the logger has already been introduced in section \ref userguide_sim, it remains to introduce 
 object \c Bayesian \c Model (bdm::BM).
 
@@ -62,5 +62,5 @@
  - logbounds - store also lower and upper bounds on estimates (obtained by calling BM::posterior().qbounds()),
  - logevidence - store also evidence of each step of the Bayes rule.
-These values are stored in given logger (\ref ug_loggers). By default, only mean values of the estimate are stored.
+These values are stored in given logger (\ref ug_store). By default, only mean values of the estimate are stored.
 
 Storing of the evidence is useful, e.g. in model selection task when two models are compared.
@@ -179,5 +179,5 @@
 Similarly to the extension of pdf, the estimators (or filters) can be extended via prepared class \c mexBM in directory bdmtoolbox/mex/mex_classes.
 
-An example of such class is mexLaplaceBM in \<toolbox_dir\>\tutorial\userguide\laplace_example.m
+An example of such class is mexLaplaceBM in \<toolbox_dir\>/tutorial/userguide/laplace_example.m
 
 Note that matlab-extended classes of mexEpdf, specifically, mexDirac and mexLaplace are used as outputs of methods posterior and epredictor, respectively.
Index: /library/doc/tutorial/040devguide_matlab.dox
===================================================================
--- /library/doc/tutorial/040devguide_matlab.dox (revision 983)
+++ /library/doc/tutorial/040devguide_matlab.dox (revision 983)
@@ -0,0 +1,175 @@
+/*!
+\page devguide_mat  BDM Development - your first bdm class in Matlab
+
+bdmtoolbox provides a prodefined points of extensions in directory applications/bdmtoolbox/mex/mex_classes.
+
+The easiest way to extend bdmtoolbox is to use clasess starting with "mex". The simplies class of this type is mexFnc, which just contains name of an arbitrary matlab function to call.
+See \ref ug_pdf_fnc example.
+
+This tutorial assumes you are familiar with basic classes of BDM: random variables \ref userguide_pdf and estimators \ref userguide_estim.
+
+If no premade class is suitable for your mneeds, you can create your own class in Matlab via predefined interfaces to class epdf (mexEpdf) and BM (mexBM).
+These classes are treated as regular C++ classes in prepared mex files. Creation of a new estimator (offspring of mexBM) can be achieved by inheriting from class mexBM.
+
+In practice this means creation of a new file, e.g. my_bm.m, with header:
+\code
+class my_bm < mexBM
+\endcode
+This file must be located in directories known to matlab (must be in its path). This can be any directory if you use addpath command. 
+See relevant documentation in Matlab.
+
+\section dev_mat_pdf Creating your own probability density
+
+Creation of your own density is achieved by inheriting from mexEpdf:
+\code
+class my_pdf < mexEpdf
+\endcode
+in a file called my_pdf.m. 
+
+Calling methods from mexEpdf will result in an error that tells you which functionality is missing.
+It is necessary to give them a meaning.
+
+Epdf is a class representing probability density function of a multivariate (vector) variable.
+
+The easiest example of a density is dirac Delta function:
+\code
+classdef mexDirac < mexEpdf
+    % Dirac delta probability distribution
+    properties                                                 % DATA structures
+        point                                                  % point of the support
+    end
+    methods
+        function m=mean(obj)                                   % compute mean values of the density
+            m = obj.point;
+        end
+        function obj=validate(obj)                             % check if data structures are consistent
+            % point should be a column
+            if (size(obj.point,2)>1)
+                if (size(obj.point,1)==1) % it is row
+                    obj.point = obj.point';
+                end
+            else
+                error('Point in mexDirac is not a vector');
+            end
+        end
+        function dim=dimension(obj)                            % inform others about your dimensions
+            dim = size(obj.point,1);
+        end
+        function v=variance(obj)                               % compute variance
+            v=zeros(size(obj.point));
+        end
+        function l=evallog(obj,x)                              % return logarithm of your density at point x
+            if obj.point==x
+                l = inf;
+            else
+                l=0;
+            end
+        end
+        function s=sample(obj);                                % return random sample from your density
+            s = obj.point;
+        end
+    end
+end
+\endcode
+
+Once you define these functions, this object can be plugged into (almost) an arbitrary algoritm, such as simulator, etc.
+
+For seamless use with other objects, you nedd to define its random variables - via attribute rv, \ref ug_pdf_create.
+
+For inspiration see example class mexLaplace.m and its use in simulation in tutorial/userguide/epdfds_example.m
+
+\section dev_mat_bm Creating your own Bayesian Model (BM)
+
+If you look into the mexBM.m file you see the basic attributes and default functions. mexBM as such will not work as a valid estimator.
+In order to make it work, you need to re-define at least functions <b>dimensions</b> and <b>bayes</b>, and attribute <b>apost_pdf</b>:
+  \code
+  function dims=dimensions(p)
+      %please fill
+      %dims = [size_of_posterior size_of_data size_of_condition]
+      dims = [0,0,0] %
+  end
+  \endcode
+This function announces sizes of random variables to other objects. 
+
+These sizes can be fixed for a specific problem, or derived from size of internal objects. E.g. for a Kalman filter, the function would be:
+\code
+function dims=dimensions(p)
+   %please fill
+   %dims = [size_of_posterior size_of_data size_of_condition]
+   dims = [size(A,1), size(C,1), size(B,2)] %
+end
+\endcode
+Which indicates that dimension of \f$x_t\f$ is the rows of matrix A, size of \f$y_t\f$ is the rows of matrix C and the size of \f$u_t\f$ is given by columns of matrix B.
+  
+The argument apost_pdf should be a valid object of class mexEpdf, see previous section how to achieve it.
+
+The second function to extend is
+\code
+function obj=bayes(obj,dt,cond)
+   % transform old estimate into new estimate
+end
+\endcode
+
+Here, you need to define an update (both time- and data-update) of your Bayesian filter.
+
+Note, that statistics of the posterior are stored in attribute apost_pdf. So, the task of this function is to update fileds in apost_pdf. 
+
+Any additional sttributes needed for this task shoul be added to properties of the object.
+
+An example calss of BM for Laplace pdf is implemented in class mexLaplaceBM.m. This class represents maximum likelihood estimator of two parameters of the density. 
+One parameter is a median of data on a sliding window.  
+This can be interpreted as a coarse approximation of Bayesian filtering with posterior reduced to Dirac delta.
+
+Hence, we need:
+ - apost_pdf to be of type mexDirac,
+ - store information about window length in the properties
+ - store the windown of data in properties
+ - the method bayes adds new data to the window and copies median of the window to the point in apost_pdf.
+ 
+This is implemented as follows:
+\code
+classdef mexLaplaceBM < mexBM
+    % Approximate Bayesian estimator of parameters of Laplace distributed observation.
+    % Maximum likelihood approximation of the Bayes rule is used, posterior is in the form of dirac.
+    properties
+        max_window_length = 10;                               % max window length (default = 10)
+        data_window =[];                                      % sliding window of data 
+    end
+    methods
+        function obj=validate(obj)                            % prepare all internal objects for use
+            obj.apost_pdf = mexDirac;
+            obj.apost_pdf.point = [0;0];
+            obj.log_evidence = 0;                             % evidence is not computed!
+            disp('val');
+        end
+
+        function dims=dimensions(obj)
+            %please fill: dims = [size_of_posterior size_of_data size_of_condition]
+            dims = [2,1,0]                                    % we have: [2d parameters, 1d observations, 0d condition]
+        end
+        function obj=bayes(obj,dt,cond)                       % approximate bayes rule
+            if size(obj.data_window,2)>=obj.max_window_length
+                obj.data_window = [dt obj.data_window(1:end-1)];
+            else
+                obj.data_window = [dt obj.data_window];
+            end
+            % transform old estimate into new estimate
+            m_hat = mean(obj.data_window);
+            b_hat = sum(abs(obj.data_window-m_hat))/ size(obj.data_window,2);
+            obj.apost_pdf.point = [m_hat; b_hat];             % store result in psoterior pdf
+        end
+        function p=epredictor(obj,cond)                       % when predictive density is needed approximate it by Laplace with point estimates
+            % return predictive density (max likelihood)
+            p = mexLaplace;
+            p.mu = obj.apost_pdf.point(1);
+            p.b  = obj.apost_pdf.point(2);
+            p=p.validate;
+        end
+    end
+
+end
+\endcode
+  
+Similar extensions to mexEpdf and mexBM can be made to other classes. See library/mex/mex_Epdf.h and library/mex/mex_BM.h how it is done.
+As always, feel free to contact the maintainer for help.
+*/
Index: /library/doc/tutorial/005userguide0.dox
===================================================================
--- /library/doc/tutorial/005userguide0.dox (revision 944)
+++ /library/doc/tutorial/005userguide0.dox (revision 983)
@@ -41,5 +41,5 @@
  - \ref userguide_pdf
  - \ref userguide_sim
-- \ref userguide_estim
+ - \ref userguide_estim
 
 */
Index: /library/doc/tutorial/030userguide3.dox
===================================================================
--- /library/doc/tutorial/030userguide3.dox (revision 948)
+++ /library/doc/tutorial/030userguide3.dox (revision 983)
@@ -2,5 +2,5 @@
 \page userguide_ctrl BDM Use - Control and Design of Decision Making Strategy
 
-Bayesian estimation as introduced in Section \ref userguide2 is a special case of Decision Strategy, see. ....
+Bayesian estimation as introduced in Section \ref userguide_estim is a special case of Decision Strategy, see. ....
 A more demanding scenario is to design a control strategy that will influence the system operating under uncertainty, this is implemented as scenario \c closedloop.
 
Index: /library/doc/tutorial/01userguide_sim.dox
===================================================================
--- /library/doc/tutorial/01userguide_sim.dox (revision 948)
+++ /library/doc/tutorial/01userguide_sim.dox (revision 983)
@@ -70,5 +70,5 @@
  -# return data observed at time \f$ t \f$, 
  -# perform one a time step.
- -# describe what these data are, via class RV, introduced in ref \ug_pdf_marg,
+ -# describe what these data are, via class RV, introduced in ref \ref ug_pdf_marg,
  -# store log of its activity into dedicated logger.
 
Index: /applications/bdmtoolbox/mex/mex_classes/mexLaplaceBM.m
===================================================================
--- /applications/bdmtoolbox/mex/mex_classes/mexLaplaceBM.m (revision 944)
+++ /applications/bdmtoolbox/mex/mex_classes/mexLaplaceBM.m (revision 983)
@@ -3,22 +3,20 @@
     % Maximum likelihood approximation of the Bayes rule is used, posterior is in the form of dirac.
     properties
-        max_window_length = 10;   % max window length
-        data_window =[];          % estimate of mu is median of observations
+        max_window_length = 10;                               % max window length (default = 10)
+        data_window =[];                                      % sliding window of data 
     end
     methods
-        function obj=validate(obj)
-            % prepare all internal objects for use
+        function obj=validate(obj)                            % prepare all internal objects for use
             obj.apost_pdf = mexDirac;
             obj.apost_pdf.point = [0;0];
-            obj.log_evidence = 0; % evidence is not computed!
+            obj.log_evidence = 0;                             % evidence is not computed!
             disp('val');
         end
 
         function dims=dimensions(obj)
-            %please fill
-            %dims = [size_of_posterior size_of_data size_of_condition]
-            dims = [2,1,0] % we have: [2d parameters, 1d observations, 0d condition]
+            %please fill: dims = [size_of_posterior size_of_data size_of_condition]
+            dims = [2,1,0]                                    % we have: [2d parameters, 1d observations, 0d condition]
         end
-        function obj=bayes(obj,dt,cond)
+        function obj=bayes(obj,dt,cond)                       % approximate bayes rule
             if size(obj.data_window,2)>=obj.max_window_length
                 obj.data_window = [dt obj.data_window(1:end-1)];
@@ -29,7 +27,7 @@
             m_hat = mean(obj.data_window);
             b_hat = sum(abs(obj.data_window-m_hat))/ size(obj.data_window,2);
-            obj.apost_pdf.point = [m_hat; b_hat];
+            obj.apost_pdf.point = [m_hat; b_hat];             % store result in psoterior pdf
         end
-        function p=epredictor(obj,cond)
+        function p=epredictor(obj,cond)                       % when predictive density is needed approximate it by Laplace with point estimates
             % return predictive density (max likelihood)
             p = mexLaplace;
Index: /applications/bdmtoolbox/mex/mex_classes/mexDirac.m
===================================================================
--- /applications/bdmtoolbox/mex/mex_classes/mexDirac.m (revision 944)
+++ /applications/bdmtoolbox/mex/mex_classes/mexDirac.m (revision 983)
@@ -1,12 +1,12 @@
 classdef mexDirac < mexEpdf
     % Dirac delta probability distribution
-    properties
-        point % point of the support
+    properties                                                 % DATA structures
+        point                                                  % point of the support
     end
     methods
-        function m=mean(obj)
+        function m=mean(obj)                                   % compute mean values of the density
             m = obj.point;
         end
-        function obj=validate(obj)
+        function obj=validate(obj)                             % check if data structures are consistent
             % point should be a column
             if (size(obj.point,2)>1)
@@ -18,11 +18,11 @@
             end
         end
-        function dim=dimension(obj)
+        function dim=dimension(obj)                            % inform others about your dimensions
             dim = size(obj.point,1);
         end
-        function v=variance(obj)
+        function v=variance(obj)                               % compute variance
             v=zeros(size(obj.point));
         end
-        function l=evallog(obj,x)
+        function l=evallog(obj,x)                              % return logarithm of your density at point x
             if obj.point==x
                 l = inf;
@@ -31,5 +31,5 @@
             end
         end
-        function s=sample(obj);
+        function s=sample(obj);                                % return random sample from your density
             s = obj.point;
         end
