00001 #ifndef INDII_ML_ODE_AUTOCORRELATOR_HPP 00002 #define INDII_ML_ODE_AUTOCORRELATOR_HPP 00003 00004 #include "NumericalSolver.hpp" 00005 #include "../aux/matrix.hpp" 00006 00007 namespace indii { 00008 namespace ml { 00009 namespace ode { 00010 /** 00011 * Auto-correlator. 00012 * 00013 * @author Lawrence Murray <lawrence@indii.org> 00014 * @version $Rev: 574 $ 00015 * @date $Date: 2008-10-04 14:14:57 +0100 (Sat, 04 Oct 2008) $ 00016 * 00017 * Calculates the autocorrelation of a Markov process for a particular time 00018 * step \f$\Delta t\f$: 00019 * 00020 * \f[ 00021 * R_s(\Delta t) = \left(\sum_{n = 1}^{s}\mathbf{y}_{n-1}\mathbf{y}_n^T - 00022 * \hat{\mathbf{\mu}}_s\hat{\mathbf{\mu}}_s^T\right) \hat{\Sigma}_s^{-1} 00023 * \,, 00024 * \f] 00025 * 00026 * where \f$s\f$ is the current step, each \f$\mathbf{y}_n\f$ is the state 00027 * of the system at step \f$n\f$ (time \f$n\Delta t\f$), and 00028 * \f$\hat{\mathbf{\mu}}_s\f$ and \f$\hat{\Sigma}_s\f$ are the sample mean 00029 * and covariance of \f$\mathbf{y}_0,\ldots,\mathbf{y}_s\f$, respectively. 00030 * 00031 * The autocovariance is given by the autocorrelation without the 00032 * normalisation term. 00033 * 00034 * @section Usage 00035 * 00036 * Firstly construct a NumericalSolver for simulating a trajectory from the 00037 * model of interest. Pass this into the constructor of the 00038 * AutoCorrelator object. 00039 * 00040 * Call step() to advance the system by a number of steps, adding each new 00041 * point to the autocorrelation calculation. The return value of step() 00042 * indicates whether the calculation has converged. Note that this 00043 * convergence check compares the autocorrelations before and after the call 00044 * to step(), so that multiple calls are necessary for the return value to be 00045 * meaningful. 00046 */ 00047 class AutoCorrelator { 00048 public: 00049 /** 00050 * Constructor. 00051 * 00052 * @param solver Numerical solver. 00053 * @param delta \f$\Delta t\f$; time step. 00054 */ 00055 AutoCorrelator(NumericalSolver* solver, const double delta); 00056 00057 /** 00058 * Destructor. 00059 */ 00060 virtual ~AutoCorrelator(); 00061 00062 /** 00063 * Set the error bounds for the convergence criterion. 00064 * 00065 * @param maxAbsoluteError The maximum permitted absolute error. 00066 */ 00067 void setErrorBounds(double maxAbsoluteError = 1e-3); 00068 00069 /** 00070 * Get the autocorrelation as calculated up to the current time. 00071 * 00072 * @return Autocorrelation as calculated up to the current time. 00073 */ 00074 const indii::ml::aux::matrix& getAutoCorrelation(); 00075 00076 /** 00077 * Get the autocovariance as calculated up to the current time. 00078 * 00079 * @return Autocovariance as calculated up to the current time. 00080 */ 00081 const indii::ml::aux::matrix& getAutoCovariance(); 00082 00083 /** 00084 * Step. 00085 * 00086 * @param steps \f$\delta s\f$; number of steps to take. 00087 * 00088 * @return True if the calculation has converged. 00089 * 00090 * Advances system in time by \f$\Delta s \Delta t\f$ and adds the new 00091 * point to the autocorrelation calculation. 00092 * 00093 * Convergence is checked in the sense: 00094 * 00095 * \f[ 00096 * \|R_s(\Delta t) - R_{s+\Delta s}(\Delta t)\| < \epsilon + 00097 * \xi\|R_s(\Delta t) - R_{s+\Delta s}(\Delta t)\|\,, 00098 * \f] 00099 * 00100 * where \f$\epsilon\f$ is the maximum permitted absolute error, and 00101 * \f$\xi\f$ the maximum permitted relative error. 00102 */ 00103 bool step(const unsigned int steps); 00104 00105 private: 00106 /** 00107 * Numerical solver. 00108 */ 00109 NumericalSolver* solver; 00110 00111 /** 00112 * \f$\Delta t\f$; time step. 00113 */ 00114 const double delta; 00115 00116 /** 00117 * \f$t\f$; current time step. 00118 */ 00119 unsigned int s; 00120 00121 /** 00122 * \f$s\mathbf{\mu}_t\f$; mean at current time. 00123 */ 00124 indii::ml::aux::vector mu; 00125 00126 /** 00127 * \f$\Sigma_t\f$; covariance at current time, no mean correction. 00128 */ 00129 indii::ml::aux::symmetric_matrix sigma; 00130 00131 /** 00132 * \f$\frac{1}{s}\sum_{n = 1}{s}\mathbf{y}_{n-1}\mathbf{y}_n^T\f$; 00133 * cross correlation numerator sum at current time. 00134 */ 00135 indii::ml::aux::matrix cross; 00136 00137 /** 00138 * \f$R_s(\Delta t)\f$; autocorrelation at the current time. 00139 */ 00140 indii::ml::aux::matrix R; 00141 00142 /** 00143 * Autocovariance at the current time. 00144 */ 00145 indii::ml::aux::matrix P; 00146 00147 /** 00148 * \f$\epsilon\f$; absolute error bound. 00149 */ 00150 double maxAbsoluteError; 00151 00152 }; 00153 00154 } 00155 } 00156 } 00157 00158 #endif 00159
1.5.3