15 #include "../builtins/Interpol2D.h"
28 "Handles process call",
32 "Handles reinit call",
35 static Finfo* processShared[] =
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* )
51 static Finfo* markovSolverFinfos[] =
61 sizeof( markovSolverFinfos ) /
sizeof(
Finfo* ),
81 unsigned int degreeIndex )
84 Matrix *U, *VplusU, *VminusU, *invVminusU, *Qpower;
85 vector< unsigned int >* swaps =
new vector< unsigned int >;
86 unsigned int n = Q1->size();
88 double *padeCoeffs = NULL;
92 vector< Matrix* > QevenPowers;
135 QevenPowers.push_back( Q1 );
137 for(
unsigned int i = 1; i < (degree + 1)/2 ; ++i )
139 Qpower = QevenPowers.back();
140 QevenPowers.push_back(
matMatMul( Qpower, Qpower ) );
144 for (
int i = degree; i > 1; i -= 2 )
152 for (
int i = degree - 1; i > 0; i -= 2 )
158 while (!QevenPowers.empty())
160 delete QevenPowers.back();
161 QevenPowers.pop_back();
215 matInv( VminusU, swaps, invVminusU );
233 unsigned int n =
Q_->size();
247 for (
unsigned int i = 0; i < 4; ++i )
260 double sf = ceil(
log( norm /
thetaM[4] ) /
log( (
double)2 ) );
265 s =
static_cast< unsigned int >( sf );
274 for (
unsigned int i = 0; i < s; ++i )
297 void assignMat(
Matrix* A,
double testMat[3][3] )
299 for (
unsigned int i = 0; i < 3; ++i )
301 for (
unsigned int j = 0; j < 3; ++j )
302 (*A)[i][j] = testMat[i][j];
309 void testMarkovSolver()
317 double testMats[5][3][3] = {
319 { 0.003859554140797, 0.003828667792972, 0.000567545354509 },
320 { 0.000630452326710, 0.001941502594891, 0.001687045130505 },
321 { 0.003882371127042, 0.003201121875555, 0.003662942100756 }
324 { 0.009032772098686, 0.000447799046538, 0.009951718245937 },
325 { 0.004122293240791, 0.005703676675533, 0.010337598714782 },
326 { 0.012352886634899, 0.004960259942209, 0.002429343859207 }
329 { 0.249033679156721, 0.026663192545146, 0.193727616177876 },
330 { 0.019543882188296, 0.240474520213763, 0.204325805163358 },
331 { 0.110669567443862, 0.001158556033517, 0.217173676340877 }
334 { 0.708590392291234, 0.253289557366033, 0.083402066470341 },
335 { 0.368148069351060, 0.675040384813246, 0.585189051240853 },
336 { 0.366939478800014, 0.276935085840161, 0.292304127720940 },
339 { 5.723393958255834, 2.650265678621879, 2.455089725038183 },
340 { 5.563819918184171, 5.681063207977340, 6.573010933999208 },
341 { 4.510226911355842, 3.729779121596184, 6.131599680450886 }
345 double correctExps[5][3][3] = {
347 { 1.003869332885896, 0.003840707339656, 0.000572924780299 },
348 { 0.000635569997632, 1.001947309951925, 0.001691961742250 },
349 { 0.003898019965821, 0.003217566115560, 1.003673477658833 }
352 { 1.009136553319587, 0.000475947724581, 0.010011555682222 },
353 { 0.004217120071231, 1.005746704105642, 0.010400661735110 },
354 { 0.012434554824033, 0.004983402186283, 1.002519822649746 }
357 { 1.296879503336410, 0.034325768324765, 0.248960074106229 },
358 { 0.039392602584525, 1.272463533413523, 0.260228538022164 },
359 { 0.140263068698347, 0.003332731847933, 1.256323839764616 }
362 { 2.174221102665550, 0.550846463313377, 0.279203836454105 },
363 { 0.963674962388503, 2.222317715620410, 1.033020817699738 },
364 { 0.733257221615105, 0.559435366776953, 1.508376826849517 }
367 { 3.274163243250245e5, 2.405867301580962e5, 3.034390382218154e5 },
368 { 5.886803379935408e5, 4.325844111569120e5, 5.456065763194024e5 },
369 { 4.671930521670584e5, 3.433084310645007e5, 4.330101744194682e5 }
373 double correctColumnNorms[5] = {
378 1.383289714485624e+06
381 for (
unsigned int i = 0; i < 5; ++i )
383 assignMat( solver.
Q_, testMats[i] );
388 for(
unsigned int j = 0; j < 3; ++j )
390 for(
unsigned int k = 0; k < 3; ++k )
391 assert(
doubleEq( (*expQ)[j][k], correctExps[i][j][k] ) );
405 vector< DimInfo > single;
414 ObjId eRateTable2d =
Element( rateTable2dId, rateTableCinfo,
415 "rateTable2d", single, 1,
true );
416 Element *eRateTable1d =
new Element( rateTable1dId, rateTableCinfo,
417 "rateTable1d", single, 1,
true );
418 Element *eInt2d =
new Element( int2dId, interpol2dCinfo,
"int2d", single, 1 );
419 Element *eVecTable =
new Element( vecTableId, vectorTableCinfo,
"vecTable",
422 "solver2d", single, 1,
true );
424 "solver1d", single, 1,
true );
426 Eref rateTable2dEref( eRateTable2d, 0 );
427 Eref rateTable1dEref( eRateTable1d, 0 );
428 Eref int2dEref( eInt2d, 0 );
429 Eref vecTableEref( eVecTable, 0 );
430 Eref solver2dEref( eSolver2d, 0 );
431 Eref solver1dEref( eSolver1d, 0 );
433 vector< double > table1d;
434 vector< vector< double > > table2d;
438 ( rateTable2dEref.data() );
440 ( rateTable1dEref.data() );
442 ( vecTableEref.data() );
444 ( int2dEref.data() );
446 ( solver2dEref.data() );
448 ( solver1dEref.data() );
450 rateTable2d->
init( 3 );
451 rateTable1d->
init( 3 );
453 vecTable->
setMin( -0.10 );
458 for (
unsigned int i = 0; i < 201; ++i )
460 table1d.push_back( 1e3 * exp( 9 * v - 0.45 ) );
475 table2d.resize( 201 );
476 for (
unsigned int i = 0; i < 201; ++i )
479 for (
unsigned int j = 0; j < 50; ++j )
481 table2d[i].push_back( 1e3 * conc * exp( -45 * v + 0.65 ) );
497 markovSolver2d->
init( rateTable2dId, 0.1 );
498 markovSolver1d->
init( rateTable1dId, 0.1 );
500 markovSolver2d->setVm( 0.0533 );
501 markovSolver2d->setLigandConc( 3.41e-6 );
503 markovSolver1d->setVm( 0.0533 );
507 initState.push_back( 0.2 );
508 initState.push_back( 0.4 );
509 initState.push_back( 0.4 );
523 cout <<
"." << flush;
Matrix * matMatAdd(const Matrix *A, const Matrix *B, double alpha, double beta)
void process(const Eref &, ProcPtr)
void reinit(const Eref &, ProcPtr)
void setXmin(double value)
Matrix * computePadeApproximant(Matrix *, unsigned int)
Matrix * computeMatrixExponential()
Matrix * matScalShift(const Matrix *A, double mul, double add)
static unsigned int mCandidates[5]
void setVtChildTable(unsigned int, unsigned int, Id, unsigned int)
void setInitialState(Vector)
void setTable(vector< double >)
static const Cinfo * vectorTableCinfo
static const Cinfo * markovSolverCinfo
void log(string msg, serverity_level_ type=debug, bool redirectToConsole=true, bool removeTicks=true)
Log to console (and to a log-file)
static const Cinfo * initCinfo()
bool doubleEq(double x, double y)
Matrix * matMatMul(Matrix *A, Matrix *B)
void setTableVector(vector< vector< double > > value)
static const Cinfo * initCinfo()
static const Cinfo * initCinfo()
void setYmax(double value)
static const Cinfo * initCinfo()
Matrix * matEyeAdd(const Matrix *A, double k)
void matInv(Matrix *A, vector< unsigned int > *swaps, Matrix *invA)
vector< vector< double > > Matrix
void setConstantRate(unsigned int, unsigned int, double)
void reinit(const Eref &, ProcPtr)
double matColNorm(Matrix *A)
static const Cinfo * initCinfo()
void setYmin(double value)
void setInt2dChildTable(unsigned int, unsigned int, Id)
double matTrace(Matrix *A)
void setDiv(unsigned int)
Matrix * matAlloc(unsigned int n)
void setXmax(double value)
void process(const Eref &, ProcPtr)