icb-dcm / lnaplusplus Goto Github PK
View Code? Open in Web Editor NEWLNA++: a Fast C++ Implementation of the Linear Noise Approximation with first- and second-order sensitivities
License: BSD 3-Clause "New" or "Revised" License
LNA++: a Fast C++ Implementation of the Linear Noise Approximation with first- and second-order sensitivities
License: BSD 3-Clause "New" or "Revised" License
@feigelman
Hey Justin,
I just run some additional test and realised that the sensitivities of the off-diagonal of the temporal covariance matrix are not correct. An example is provided in the revised version of Wang2010. The routines return a symmetric matrix for the sensitivity of cov(x(s),x(t)). The upper triangular fits the finite differences approximation but the lower doesn’t. There is also no reason why the matrix should be symmetric.
I tried to find the bug, but failed due to a missing overview over the code structure. I fear that you are the only person who can fix this. Could you please have a look? (Submission deadline is beginning of next week.)
Greetings,
Jan
Documentation.pdf currently contains detailed API documentation. The respective functions in the source files (e.g. LNA.py::generateLNA) does not contain any documentation. Might be better to move it to the code. This allows using help()
and integrates with most IDEs. Also it reduces chances of diverging code and documentation.
bug or feature?
This works with Matlab and can be expected to work with python too
Adapt in setupTemplate.py
For all the models I get warnings of the type
Building with 'Xcode with Clang'.
/usr/bin/xcrun -sdk macosx10.13 clang -c -DTARGET_API_VERSION=700 -DUSE_MEX_CMD -DMATLAB_MEX_FILE -Ichain3/C -I"/Applications/MATLAB_R2017a.app/extern/include" -I"/Applications/MATLAB_R2017a.app/simulink/include" -fno-common -arch x86_64 -mmacosx-version-min=10.9 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -O2 -fwrapv -DNDEBUG /Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/chain3/C/Afunc.c -o /Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/chain3/C/Afunc.o
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/chain3/C/Afunc.c:5:10: warning: incompatible pointer types initializing 'double (*)[3][3]' with an expression of type 'double *' [-Wincompatible-pointer-types]
double (*A0)[3][3] = &varOut[0];
^ ~~~~~~~~~~
1 warning generated.
/usr/bin/xcrun -sdk macosx10.13 clang -c -DTARGET_API_VERSION=700 -DUSE_MEX_CMD -DMATLAB_MEX_FILE -Ichain3/C -I"/Applications/MATLAB_R2017a.app/extern/include" -I"/Applications/MATLAB_R2017a.app/simulink/include" -fno-common -arch x86_64 -mmacosx-version-min=10.9 -fexceptions -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -O2 -fwrapv -DNDEBUG /Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/chain3/C/Efunc.c -o /Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/chain3/C/Efunc.o
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/chain3/C/Efunc.c:5:10: warning: incompatible pointer types initializing 'double (*)[6][3]' with an expression of type 'double *' [-Wincompatible-pointer-types]
double (*A0)[6][3] = &varOut[0];
^ ~~~~~~~~~~
1 warning generated.
Move application examples to examples/
leave to models
to LNA++-generated code.
git-ignore models/
.
Makes cleaning up much easier.
>> BirthDeath
Undefined function or variable 'generateLNA'.
>> generateLNA('BirthDeath/BirthDeath.xml', 'BirthDeath', 'BOTH');
Warning: Support of character vectors will be removed in a future release. Character vectors can be used only for variable names and numbers.
Instead, to create symbolic expressions first create symbolic variables using 'syms'. To evaluate character vectors and strings representing
symbolic expressions, use 'str2sym'.
> In sym>convertExpression (line 1581)
In sym>convertChar (line 1486)
In sym>tomupad (line 1236)
In sym (line 215)
In cell2sym (line 31)
In SBML2StoichProp (line 59)
In generateLNA (line 14)
[... many more as above ... ]
> In sym>convertExpression (line 1581)
In sym>convertChar (line 1486)
In sym>tomupad (line 1236)
In sym (line 215)
In sym/subs>@(x)sym(x) (line 206)
In sym/subs>normalize (line 206)
In sym/subs>mupadsubs (line 154)
In sym/subs (line 142)
In SBML2StoichProp (line 65)
In generateLNA (line 14)
Warning: Function 'Theta' not verified to be a valid MATLAB function.
Warning: Function 'phi' not verified to be a valid MATLAB function.
Computing symbolic derivatives
Warning: Solutions are valid under the following conditions: in((k_m*k_p^2 + g_m*k_p^2*phi01 + g_m^2*k_p*phi01 + g_m*g_p^2*phi02 +
g_m^2*g_p*phi02 + g_m*g_p*k_p*phi01)/(g_m*g_p*(g_m + g_p)), 'real') & in((k_p*(k_m + g_m*phi01))/(g_m*(g_m + g_p)), 'real') & in((k_m +
g_m*phi01)/g_m, 'real'). To include parameters and conditions in the solution, specify the 'ReturnConditions' value as 'true'.
> In solve>warnIfParams (line 508)
In solve (line 357)
In generateLNAComponents>solveSS_var (line 377)
In generateLNAComponents (line 109)
In generateLNA (line 25)
computing initial sensitivities
MEX completed successfully.
Compiling LNA code...
Building with 'Xcode Clang++'.
Error using mex
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:297:35: error:
non-constant-expression cannot be narrowed from type 'int' to 'mwSize' (aka 'unsigned long') in initializer
list [-Wc++11-narrowing]
const mwSize dims_Sigma[] = {nObsVar,nObsVar,N,N};
^~~~~~~
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:297:35: note: insert an
explicit cast to silence this issue
const mwSize dims_Sigma[] = {nObsVar,nObsVar,N,N};
^~~~~~~
static_cast<mwSize>( )
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:297:43: error:
non-constant-expression cannot be narrowed from type 'int' to 'mwSize' (aka 'unsigned long') in initializer
list [-Wc++11-narrowing]
const mwSize dims_Sigma[] = {nObsVar,nObsVar,N,N};
^~~~~~~
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:297:43: note: insert an
explicit cast to silence this issue
const mwSize dims_Sigma[] = {nObsVar,nObsVar,N,N};
^~~~~~~
static_cast<mwSize>( )
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:297:51: error:
non-constant-expression cannot be narrowed from type 'int' to 'mwSize' (aka 'unsigned long') in initializer
list [-Wc++11-narrowing]
const mwSize dims_Sigma[] = {nObsVar,nObsVar,N,N};
^
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:297:51: note: insert an
explicit cast to silence this issue
const mwSize dims_Sigma[] = {nObsVar,nObsVar,N,N};
^
static_cast<mwSize>( )
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:297:53: error:
non-constant-expression cannot be narrowed from type 'int' to 'mwSize' (aka 'unsigned long') in initializer
list [-Wc++11-narrowing]
const mwSize dims_Sigma[] = {nObsVar,nObsVar,N,N};
^
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:297:53: note: insert an
explicit cast to silence this issue
const mwSize dims_Sigma[] = {nObsVar,nObsVar,N,N};
^
static_cast<mwSize>( )
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:312:34: error:
non-constant-expression cannot be narrowed from type 'int' to 'mwSize' (aka 'unsigned long') in initializer
list [-Wc++11-narrowing]
const mwSize dims_Sens[] = {nObsVar,npar,N};
^~~~~~~
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:312:34: note: insert an
explicit cast to silence this issue
const mwSize dims_Sens[] = {nObsVar,npar,N};
^~~~~~~
static_cast<mwSize>( )
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:312:47: error:
non-constant-expression cannot be narrowed from type 'int' to 'mwSize' (aka 'unsigned long') in initializer
list [-Wc++11-narrowing]
const mwSize dims_Sens[] = {nObsVar,npar,N};
^
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:312:47: note: insert an
explicit cast to silence this issue
const mwSize dims_Sens[] = {nObsVar,npar,N};
^
static_cast<mwSize>( )
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:325:26: error:
non-constant-expression cannot be narrowed from type 'int' to 'mwSize' (aka 'unsigned long') in initializer
list [-Wc++11-narrowing]
const mwSize dims[] = {nObsVar,nObsVar,N,N,npar};
^~~~~~~
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:325:26: note: insert an
explicit cast to silence this issue
const mwSize dims[] = {nObsVar,nObsVar,N,N,npar};
^~~~~~~
static_cast<mwSize>( )
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:325:34: error:
non-constant-expression cannot be narrowed from type 'int' to 'mwSize' (aka 'unsigned long') in initializer
list [-Wc++11-narrowing]
const mwSize dims[] = {nObsVar,nObsVar,N,N,npar};
^~~~~~~
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:325:34: note: insert an
explicit cast to silence this issue
const mwSize dims[] = {nObsVar,nObsVar,N,N,npar};
^~~~~~~
static_cast<mwSize>( )
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:325:42: error:
non-constant-expression cannot be narrowed from type 'int' to 'mwSize' (aka 'unsigned long') in initializer
list [-Wc++11-narrowing]
const mwSize dims[] = {nObsVar,nObsVar,N,N,npar};
^
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:325:42: note: insert an
explicit cast to silence this issue
const mwSize dims[] = {nObsVar,nObsVar,N,N,npar};
^
static_cast<mwSize>( )
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:325:44: error:
non-constant-expression cannot be narrowed from type 'int' to 'mwSize' (aka 'unsigned long') in initializer
list [-Wc++11-narrowing]
const mwSize dims[] = {nObsVar,nObsVar,N,N,npar};
^
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:325:44: note: insert an
explicit cast to silence this issue
const mwSize dims[] = {nObsVar,nObsVar,N,N,npar};
^
static_cast<mwSize>( )
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:338:35: error:
non-constant-expression cannot be narrowed from type 'int' to 'mwSize' (aka 'unsigned long') in initializer
list [-Wc++11-narrowing]
const mwSize dims_Sens2[] = {nObsVar,npar,npar,N};
^~~~~~~
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:338:35: note: insert an
explicit cast to silence this issue
const mwSize dims_Sens2[] = {nObsVar,npar,npar,N};
^~~~~~~
static_cast<mwSize>( )
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:338:53: error:
non-constant-expression cannot be narrowed from type 'int' to 'mwSize' (aka 'unsigned long') in initializer
list [-Wc++11-narrowing]
const mwSize dims_Sens2[] = {nObsVar,npar,npar,N};
^
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:338:53: note: insert an
explicit cast to silence this issue
const mwSize dims_Sens2[] = {nObsVar,npar,npar,N};
^
static_cast<mwSize>( )
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:350:39: error:
non-constant-expression cannot be narrowed from type 'int' to 'mwSize' (aka 'unsigned long') in initializer
list [-Wc++11-narrowing]
const mwSize dims_Sens2_Var[] = {nObsVar,nObsVar,npar,npar,N,N};
^~~~~~~
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:350:39: note: insert an
explicit cast to silence this issue
const mwSize dims_Sens2_Var[] = {nObsVar,nObsVar,npar,npar,N,N};
^~~~~~~
static_cast<mwSize>( )
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:350:47: error:
non-constant-expression cannot be narrowed from type 'int' to 'mwSize' (aka 'unsigned long') in initializer
list [-Wc++11-narrowing]
const mwSize dims_Sens2_Var[] = {nObsVar,nObsVar,npar,npar,N,N};
^~~~~~~
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:350:47: note: insert an
explicit cast to silence this issue
const mwSize dims_Sens2_Var[] = {nObsVar,nObsVar,npar,npar,N,N};
^~~~~~~
static_cast<mwSize>( )
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:350:65: error:
non-constant-expression cannot be narrowed from type 'int' to 'mwSize' (aka 'unsigned long') in initializer
list [-Wc++11-narrowing]
const mwSize dims_Sens2_Var[] = {nObsVar,nObsVar,npar,npar,N,N};
^
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:350:65: note: insert an
explicit cast to silence this issue
const mwSize dims_Sens2_Var[] = {nObsVar,nObsVar,npar,npar,N,N};
^
static_cast<mwSize>( )
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:350:67: error:
non-constant-expression cannot be narrowed from type 'int' to 'mwSize' (aka 'unsigned long') in initializer
list [-Wc++11-narrowing]
const mwSize dims_Sens2_Var[] = {nObsVar,nObsVar,npar,npar,N,N};
^
/Users/jan.hasenauer/Documents/02_work/05_matlab/LNAplusplus/models/../src/mexLNA.cpp:350:67: note: insert an
explicit cast to silence this issue
const mwSize dims_Sens2_Var[] = {nObsVar,nObsVar,npar,npar,N,N};
^
static_cast<mwSize>( )
16 errors generated.
Error in compileLNA (line 38)
eval( cmd_compile_cpp )
Error in generateLNA (line 30)
compileLNA(model)
Error in BirthDeath (line 25)
generateLNA('BirthDeath/BirthDeath.xml', 'BirthDeath', 'BOTH')
No serious issue, but should be cleaned up.
cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
cc1plus: warning: command line option ‘-Wno-incompatible-pointer-types’ is valid for C/ObjC but not for C++
cc1plus: warning: unrecognized command line option ‘-Wno-c++11-compat-deprecated-writable-strings’
cc1plus: warning: unrecognized command line option ‘-Wno-header-guard’
cc1: warning: command line option ‘-Wno-reorder’ is valid for C++/ObjC++ but not for C
...
[MRE,Var,dMRE,dVar] = Wang2010_LNA(Theta,tspan,MRE0,Var0,0,1:5);
yields
SUNDIALS_ERROR: CVodefailed with flag = -4
CVode
Error using Wang2010_LNA_mex
Caught LNA++ Error
Error in Wang2010_LNA (line 32)
[Y Sigma Sens_MRE Sens_Var] = Wang2010_LNA_mex(Theta, timepoints, varargin);
Works on Ubuntu, fails on OSX:
[CVODES ERROR] CVode
At t = 1.51964e-13, mxstep steps taken before reaching tout.
SUNDIALS_ERROR: CVodefailed with flag = -1
Traceback (most recent call last):
File "models/BirthDeath.py", line 221, in <module>
MRE, Var, Sens_MRE, Sens_Var,Sens2_MRE,Sens2_Var = BirthDeathLNA.LNA(Theta, tspan, Y0=MRE0, V0=Var0, merr=VarNoise, obsVar=ObsIndex, computeSens2=True)
BirthDeath.error: Error encountered during computation.
See https://travis-ci.org/ICB-DCM/LNAplusplus/jobs/369133949
The tutorial model BirthDeath/BirthDeath.xml
is missing:
python3 BirthDeath.py
Invalid file specified
Traceback (most recent call last):
File "BirthDeath.py", line 13, in <module>
generateLNA('BirthDeath/BirthDeath.xml', 'BirthDeath', computeSS='BOTH')
File "../python/LNA.py", line 38, in generateLNA
S, species, parameters, fHandle = SBML2StoichProp(fileName)
TypeError: 'NoneType' object is not iterable
If you suspect this is an IPython bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at [email protected]
You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.
Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
%config Application.verbose_crash=True
E: Package 'libblitz0-dev' has no installation candidate
E: Unable to locate package libblitz0ldbl
E: Unable to locate package libblitz-doc
Add to requirements list
Traceback (most recent call last):
File "BirthDeath.py", line 11, in <module>
from LNA import generateLNA
File "../python/LNA.py", line 11, in <module>
from SBML2StoichProp import SBML2StoichProp
File "../python/SBML2StoichProp.py", line 9, in <module>
from parse_sbml_stoichiometry import parse_file
File "../python/parse_sbml_stoichiometry.py", line 4, in <module>
import ipdb
ModuleNotFoundError: No module named 'ipdb'
It would be nice to support this for parameter estimation.
... otherwise it fails when trying to open files provided with relative paths inside LNA.py.
I think this is not what the user would except.
@feigelman I did not find the original publication of the model. could you maybe give me a hint?
... the latter expects basic float, but the former returns sympy float.
warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
The ordering of dimensions in the code differs from what's reported in the documentation. Furthermore, it is inconsistent:
sMRE: state x parameter x time
sVar: state x state x time x time x parameter x parameter
s2MRE: state x parameter x parameter x time
s2Var: state x state x parameter x parameter x time x time
The ordering of sVar should be adapted and the documentation modified.
@JanHasenauer Are the figures in the documentation intentionally placed at the end of the document? Would increase readability if we integrated them at their first reference.
@feigelman The documentation says that the dimension of the sensitivity output dMRE is N × T × d, with "d is the number of model parameters + the number of species". For dSigma it is N × N × T × d.
Is it correct that the first length(theta) sensitivities are the sensitivities with respect to the parameters? Then I would expected that length(theta)+1:d are the sensitivities with respect to the initial mean, correct?
What happens of the mean determined by the steady state?
Is the sensitivity with respect to the initial covariances calculated?
/bin/bash ../libtool --tag=CXX --mode=compile c++ -DHAVE_CONFIG_H -I.. -I.. -MT globals.lo -MD -MP -MF .deps/globals.Tpo -c -o globals.lo `test -f '../src/globals.cpp' || echo './'`../src/globals.cpp
libtool: compile: c++ -DHAVE_CONFIG_H -I.. -I.. -MT globals.lo -MD -MP -MF .deps/globals.Tpo -c ../src/globals.cpp -o globals.o
In file included from ../blitz/array/asexpr.cc:38:0,
from ../blitz/array.cc:9,
from ../blitz/array-impl.h:2559,
from ../blitz/array.h:37,
from ../src/globals.cpp:12:
../blitz/array/expr.h: In instantiation of 'class blitz::_bz_ArrayExpr<blitz::FastTV2Iterator<int, 2> >':
../blitz/array/asexpr.h:224:10: required from 'struct blitz::BzBinaryExprResult<blitz::Subtract, blitz::TinyVector<int, 2>, std::complex<long double> >'
../blitz/array/ops.h:127:1: required by substitution of 'template<class T> typename blitz::BzBinaryExprResult<blitz::Subtract, T, std::complex<long double> >::T_result blitz::operator-(const blitz::ETBase<T>&, std::complex<long double>) [with T = blitz::TinyVector<int, 2>]'
../blitz/tinymat2.h:197:21: required from here
../blitz/array/expr.h:111:44: error: invalid use of incomplete type 'blitz::_bz_ArrayExpr<blitz::FastTV2Iterator<int, 2> >::T_expr {aka class blitz::FastTV2Iterator<int, 2>}'
typedef _bz_typename T_expr::T_numtype T_numtype;
^~~~~~~~~
[ many more errors omitted ]
Blitz++ has moved to https://github.com/blitzpp/blitz
Need to update documentation and test with newer versions
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.