MOOSE - Multiscale Object Oriented Simulation Environment
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
MarkovSolver Class Reference

#include <MarkovSolver.h>

+ Inheritance diagram for MarkovSolver:
+ Collaboration diagram for MarkovSolver:

Public Member Functions

MatrixcomputeMatrixExponential ()
 
MatrixcomputePadeApproximant (Matrix *, unsigned int)
 
 MarkovSolver ()
 
void process (const Eref &, ProcPtr)
 
void reinit (const Eref &, ProcPtr)
 
 ~MarkovSolver ()
 
- Public Member Functions inherited from MarkovSolverBase
VectorbilinearInterpolate () const
 
void computeState ()
 
void fillupTable ()
 
Vector getInitialState () const
 
double getInvDx () const
 
double getInvDy () const
 
Matrix getQ () const
 
Vector getState () const
 
unsigned int getXdivs () const
 
double getXmax () const
 
double getXmin () const
 
unsigned int getYdivs () const
 
double getYmax () const
 
double getYmin () const
 
void handleLigandConc (double)
 
void handleVm (double)
 
void init (Id, double)
 
void innerFillupTable (vector< unsigned int >, string, unsigned int, unsigned int)
 
VectorlinearInterpolate () const
 
 MarkovSolverBase ()
 
void process (const Eref &, ProcPtr)
 
void reinit (const Eref &, ProcPtr)
 
void setInitialState (Vector)
 
void setXdivs (unsigned int)
 
void setXmax (double)
 
void setXmin (double)
 
void setYdivs (unsigned int)
 
void setYmax (double)
 
void setYmin (double)
 
virtual ~MarkovSolverBase ()
 

Static Public Member Functions

static const CinfoinitCinfo ()
 
- Static Public Member Functions inherited from MarkovSolverBase
static const CinfoinitCinfo ()
 

Additional Inherited Members

- Protected Attributes inherited from MarkovSolverBase
MatrixQ_
 

Detailed Description

Definition at line 30 of file MarkovSolver.h.

Constructor & Destructor Documentation

MarkovSolver::MarkovSolver ( )

Definition at line 70 of file MarkovSolver.cpp.

71 {
72  ;
73 }
MarkovSolver::~MarkovSolver ( )

Definition at line 75 of file MarkovSolver.cpp.

76 {
77  ;
78 }

Member Function Documentation

Matrix * MarkovSolver::computeMatrixExponential ( )
virtual

Reimplemented from MarkovSolverBase.

Definition at line 230 of file MarkovSolver.cpp.

References computePadeApproximant(), DUMMY, FIRST, moose::log(), matColNorm(), matEyeAdd(), matMatMul(), matScalShift(), matTrace(), MarkovSolverBase::Q_, and thetaM.

231 {
232  double mu, norm;
233  unsigned int n = Q_->size();
234  Matrix *expQ, *Q1;
235 
236  mu = matTrace( Q_ )/n;
237 
238  //Q1 <- Q - mu*I
239  //This reduces the norm of the matrix. The idea is that a lower
240  //order approximant will suffice if the norm is smaller.
241  Q1 = matEyeAdd( Q_, -mu );
242 
243  //We cycle through the first four candidate values of m. The moment the norm
244  //satisfies the theta_M bound, we choose that m and compute the Pade'
245  //approximant to the exponential. We can then directly return the exponential.
246  norm = matColNorm( Q1 );
247  for ( unsigned int i = 0; i < 4; ++i )
248  {
249  if ( norm < thetaM[i] )
250  {
251  expQ = computePadeApproximant( Q1, i );
252  matScalShift( expQ, exp( mu ), 0, DUMMY );
253  return expQ;
254  }
255  }
256 
257  //In case none of the candidates were satisfactory, we scale down the norm
258  //by dividing A by 2^s until ||A|| < 1. We then use a 13th degree
259  //Pade approximant.
260  double sf = ceil( log( norm / thetaM[4] ) / log( (double)2 ) );
261  unsigned int s = 0;
262 
263  if ( sf > 0 )
264  {
265  s = static_cast< unsigned int >( sf );
266  matScalShift( Q1, 1.0/(2 << (s - 1)), 0, DUMMY );
267  }
268  expQ = computePadeApproximant( Q1, 4 );
269 
270  //Upto this point, the matrix stored in expQ is r13, the 13th degree
271  //Pade approximant corresponding to A/2^s, not A.
272  //Now we repeatedly square r13 's' times to get the exponential
273  //of A.
274  for ( unsigned int i = 0; i < s; ++i )
275  matMatMul( expQ, expQ, FIRST );
276 
277  matScalShift( expQ, exp( mu ), 0, DUMMY );
278 
279  delete Q1;
280  return expQ;
281 }
#define DUMMY
Definition: MatrixOps.h:33
Matrix * computePadeApproximant(Matrix *, unsigned int)
Matrix * matScalShift(const Matrix *A, double mul, double add)
Definition: MatrixOps.cpp:175
void log(string msg, serverity_level_ type=debug, bool redirectToConsole=true, bool removeTicks=true)
Log to console (and to a log-file)
Matrix * matMatMul(Matrix *A, Matrix *B)
Definition: MatrixOps.cpp:36
static double thetaM[5]
Definition: MarkovSolver.h:78
Matrix * matEyeAdd(const Matrix *A, double k)
Definition: MatrixOps.cpp:147
vector< vector< double > > Matrix
Definition: MatrixOps.h:22
double matColNorm(Matrix *A)
Definition: MatrixOps.cpp:282
#define FIRST
Definition: MatrixOps.h:30
double matTrace(Matrix *A)
Definition: MatrixOps.cpp:271

+ Here is the call graph for this function:

Matrix * MarkovSolver::computePadeApproximant ( Matrix ,
unsigned  int 
)

Definition at line 80 of file MarkovSolver.cpp.

References b13, b3, b5, b7, b9, DUMMY, FIRST, matAlloc(), matEyeAdd(), matInv(), matMatAdd(), matMatMul(), matScalShift(), mCandidates, and SECOND.

Referenced by computeMatrixExponential().

82 {
83  Matrix *expQ;
84  Matrix *U, *VplusU, *VminusU, *invVminusU, *Qpower;
85  vector< unsigned int >* swaps = new vector< unsigned int >;
86  unsigned int n = Q1->size();
87  unsigned int degree = mCandidates[degreeIndex];
88  double *padeCoeffs = NULL;
89  Matrix *V = matAlloc(n);
90 
91  //Vector of Matrix pointers. Each entry is an even power of Q.
92  vector< Matrix* > QevenPowers;
93 
94  //Selecting the right coefficient array.
95  switch (degree)
96  {
97  case 13:
98  padeCoeffs = b13;
99  break;
100 
101  case 9:
102  padeCoeffs = b9;
103  break;
104 
105  case 7:
106  padeCoeffs = b7;
107  break;
108 
109  case 5:
110  padeCoeffs = b5;
111  break;
112 
113  case 3:
114  padeCoeffs = b3;
115  break;
116  }
117 
118 
120  //Q2 = Q^2 is computed for all degrees.
121  //Q4 = Q^4 = Q^2 * Q^2 is computed when degree = 5,7,9,13.
122  //Q6 = Q^6 = Q^4 * Q^2 is computed when degree = 7,9,13.
123  //Q8 = Q^8 = Q^4 * Q^4 is computed when degree = 7,9.
124  //Note that the formula for the 13th degree approximant used here
125  //is different from the one used for smaller degrees.
127  switch( degree )
128  {
129  case 3 :
130  case 5 :
131  case 7 :
132  case 9 :
133  U = matAlloc( n );
134 
135  QevenPowers.push_back( Q1 );
136 
137  for( unsigned int i = 1; i < (degree + 1)/2 ; ++i )
138  {
139  Qpower = QevenPowers.back();
140  QevenPowers.push_back( matMatMul( Qpower, Qpower ) );
141  }
142 
143  //Computation of U.
144  for ( int i = degree; i > 1; i -= 2 )
145  matMatAdd( U, QevenPowers[i/2], 1.0, padeCoeffs[i], FIRST );
146 
147  //Adding b0 * I .
148  matEyeAdd( U, padeCoeffs[1], 0 );
149  matMatMul( Q1, U, SECOND );
150 
151  //Computation of V.
152  for ( int i = degree - 1; i > 0; i -= 2 )
153  matMatAdd( V, QevenPowers[i/2], 1.0, padeCoeffs[i], FIRST );
154 
155  //Adding b1 * I
156  matEyeAdd( V, padeCoeffs[0], DUMMY );
157 
158  while (!QevenPowers.empty())
159  {
160  delete QevenPowers.back();
161  QevenPowers.pop_back();
162  }
163  break;
164 
165  case 13:
166  Matrix *Q2, *Q4, *Q6;
167  Matrix *temp;
168 
169  Q2 = matMatMul( Q1, Q1 );
170  Q4 = matMatMul( Q2, Q2 );
171  Q6 = matMatMul( Q4, Q2 );
172 
173  //Long and rather messy expression for U and V.
174  //Refer paper mentioned in header for more details.
175  //Storing the result in temporaries is a better idea as it gives us
176  //control on how many temporaries are being created and also to
177  //help in memory deallocation.
178 
179  //Computation of U.
180  temp = matScalShift( Q6, b13[13], 0.0 );
181  matMatAdd( temp, Q4, 1.0, b13[11], FIRST );
182  matMatAdd( temp, Q2, 1.0, b13[9], FIRST );
183 
184  matMatMul( Q6, temp, SECOND );
185 
186  matMatAdd( temp, Q6, 1.0, b13[7], FIRST );
187  matMatAdd( temp, Q4, 1.0, b13[5], FIRST );
188  matMatAdd( temp, Q2, 1.0, b13[3], FIRST );
189  matEyeAdd( temp, b13[1], DUMMY );
190  U = matMatMul( Q1, temp );
191  delete temp;
192 
193  //Computation of V
194  temp = matScalShift( Q6, b13[12], 0.0 );
195  matMatAdd( temp, Q4, 1.0, b13[10], FIRST );
196  matMatAdd( temp, Q2, 1.0, b13[8], FIRST );
197  matMatMul( Q6, temp, SECOND );
198  matMatAdd( temp, Q6, 1.0, b13[6], FIRST );
199  matMatAdd( temp, Q4, 1.0, b13[4], FIRST );
200  matMatAdd( temp, Q2, 1.0, b13[2], FIRST );
201  delete( V );
202  V = matEyeAdd( temp, b13[0] );
203  delete temp;
204 
205  delete Q2;
206  delete Q4;
207  delete Q6;
208  break;
209  }
210 
211  VplusU = matMatAdd( U, V, 1.0, 1.0 );
212  VminusU = matMatAdd( U, V, -1.0, 1.0 );
213 
214  invVminusU = matAlloc( n );
215  matInv( VminusU, swaps, invVminusU );
216  expQ = matMatMul( invVminusU, VplusU );
217 
218 
219  //Memory cleanup.
220  delete U;
221  delete V;
222  delete VplusU;
223  delete VminusU;
224  delete invVminusU;
225  delete swaps;
226 
227  return expQ;
228 }
#define DUMMY
Definition: MatrixOps.h:33
Matrix * matMatAdd(const Matrix *A, const Matrix *B, double alpha, double beta)
Definition: MatrixOps.cpp:111
static double b3[4]
Definition: MarkovSolver.h:76
#define SECOND
Definition: MatrixOps.h:31
Matrix * matScalShift(const Matrix *A, double mul, double add)
Definition: MatrixOps.cpp:175
static unsigned int mCandidates[5]
Definition: MarkovSolver.h:81
static double b9[10]
Definition: MarkovSolver.h:67
static double b13[14]
Definition: MarkovSolver.h:61
static double b5[6]
Definition: MarkovSolver.h:74
Matrix * matMatMul(Matrix *A, Matrix *B)
Definition: MatrixOps.cpp:36
Matrix * matEyeAdd(const Matrix *A, double k)
Definition: MatrixOps.cpp:147
void matInv(Matrix *A, vector< unsigned int > *swaps, Matrix *invA)
Definition: MatrixOps.cpp:348
vector< vector< double > > Matrix
Definition: MatrixOps.h:22
#define FIRST
Definition: MatrixOps.h:30
Matrix * matAlloc(unsigned int n)
Definition: MatrixOps.cpp:480
static double b7[8]
Definition: MarkovSolver.h:71

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

const Cinfo * MarkovSolver::initCinfo ( )
static

Definition at line 21 of file MarkovSolver.cpp.

References MarkovSolverBase::initCinfo(), markovSolverCinfo, process(), and reinit().

22 {
24  //DestFinfos
26 
27  static DestFinfo process( "process",
28  "Handles process call",
30 
31  static DestFinfo reinit( "reinit",
32  "Handles reinit call",
34 
35  static Finfo* processShared[] =
36  {
37  &process, &reinit
38  };
39 
40  static SharedFinfo proc( "proc",
41  "This is a shared message to receive Process message from the"
42  "scheduler. The first entry is a MsgDest for the Process "
43  "operation. It has a single argument, ProcInfo, which "
44  "holds lots of information about current time, thread, dt and"
45  "so on. The second entry is a MsgDest for the Reinit "
46  "operation. It also uses ProcInfo.",
47  processShared, sizeof( processShared ) / sizeof( Finfo* )
48  );
49 
50 
51  static Finfo* markovSolverFinfos[] =
52  {
53  &proc, //SharedFinfo
54  };
55 
56  static Dinfo < MarkovSolver > dinfo;
57  static Cinfo markovSolverCinfo(
58  "MarkovSolver",
60  markovSolverFinfos,
61  sizeof( markovSolverFinfos ) / sizeof( Finfo* ),
62  &dinfo
63  );
64 
65  return &markovSolverCinfo;
66 }
void process(const Eref &, ProcPtr)
void reinit(const Eref &, ProcPtr)
Definition: Dinfo.h:60
static const Cinfo * markovSolverCinfo
static const Cinfo * initCinfo()
Definition: Cinfo.h:18
Definition: Finfo.h:12

+ Here is the call graph for this function:

void MarkovSolver::process ( const Eref e,
ProcPtr  p 
)

Definition at line 291 of file MarkovSolver.cpp.

References MarkovSolverBase::process().

Referenced by initCinfo().

292 {
294 }
void process(const Eref &, ProcPtr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void MarkovSolver::reinit ( const Eref e,
ProcPtr  p 
)

Definition at line 286 of file MarkovSolver.cpp.

References MarkovSolverBase::reinit().

Referenced by initCinfo().

287 {
288  MarkovSolverBase::reinit( e, p );
289 }
void reinit(const Eref &, ProcPtr)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:


The documentation for this class was generated from the following files: