indii/ml/filter/FixableStateModel.cpp

00001 #include "FixableStateModel.hpp"
00002 
00003 namespace aux = indii::ml::aux;
00004 namespace ublas = boost::numeric::ublas;
00005 
00006 using namespace indii::ml::filter;
00007 
00008 FixableStateModel::FixableStateModel() {
00009   //
00010 }
00011 
00012 FixableStateModel::FixableStateModel(const unsigned int N) : N(N), F(0),
00013     fixed(N), projectCondense(N,N) {
00014   unsigned int i;
00015   
00016   fixed.clear();
00017   projectCondense.clear();
00018   for (i = 0; i < N; i++) {
00019     projectCondense(i,i) = 1;
00020   }
00021 }
00022 
00023 FixableStateModel::~FixableStateModel() {
00024   //
00025 }
00026 
00027 unsigned int FixableStateModel::getVariableSize() const {
00028   return N;
00029 }
00030 
00031 unsigned int FixableStateModel::getFixedSize() const {
00032   return F;
00033 }
00034 
00035 void FixableStateModel::fix(const unsigned int i, const double value) {
00036   /* pre-condition */
00037   assert (i < N + F);
00038 
00039   unsigned int row, col;
00040   bool isFixed = true; // is variable already fixed?
00041   
00042   for (row = 0; row < projectCondense.size1(); row++) {
00043     if (projectCondense(row,i) == 1) {
00044       isFixed = false;
00045       break;
00046     }
00047   }
00048 
00049   if (!isFixed) {
00050     /* update projection matrix */
00051     /**
00052      * @todo Preservation in resize() is not yet implemented in uBLAS
00053      * for sparse matrices. Copy into dense matrix at present,
00054      * sparse matrices are used here for computational rather than
00055      * storage efficiency after all. Review in future if
00056      * preservation for sparse matrices is implemented in uBLAS.
00057      */
00058     aux::matrix projectCondenseDense(projectCondense);
00059     ublas::range cols(0, N + F);
00060     ublas::range to(row, N - 1);
00061     ublas::range from(row + 1, N);
00062     ublas::matrix_range<aux::matrix>(projectCondenseDense, to, cols) =
00063         ublas::matrix_range<aux::matrix>(projectCondenseDense, from, cols);
00064     projectCondenseDense.resize(N - 1, N + F, true);
00065     projectCondense.resize(N - 1, N + F, false);
00066     projectCondense.clear();
00067     for (col = 0; col < projectCondenseDense.size2(); col++) {
00068       for (row = 0; row < projectCondenseDense.size1(); row++) {
00069         if (projectCondenseDense(row,col) == 1) {
00070           projectCondense(row,col) = 1;
00071       }
00072       }
00073     }
00074     
00075     N--;
00076     F++;
00077   }
00078   
00079   /* update fixed variables */
00080   fixed(i) = value;
00081 
00082   /* post-condition */
00083   assert (projectCondense.size1() == N);
00084   assert (projectCondense.size2() == N + F);
00085 }
00086 

Generated on Wed Dec 17 15:11:57 2008 for dysii Dynamical Systems Library by  doxygen 1.5.3