Skip to content

Commit 9740939

Browse files
authored
Merge pull request #355 from ICB-DCM/dw_misc
Fixes for #353, #350
2 parents acb0375 + 0f835f9 commit 9740939

File tree

12 files changed

+72
-49
lines changed

12 files changed

+72
-49
lines changed

matlab/@amimodel/generateMatlabWrapper.m

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,17 +196,10 @@ function generateMatlabWrapper(nx, ny, np, nk, nz, o2flag, amimodelo2, wrapperFi
196196
fprintf(fid,'if(isempty(options_ami.pscale))\n');
197197
fprintf(fid,[' options_ami.pscale = ''' pscale ''' ;\n']);
198198
fprintf(fid,'end\n');
199-
fprintf(fid,'switch (options_ami.pscale)\n');
200-
fprintf(fid,' case 1\n');
201-
fprintf(fid,' chainRuleFactor = exp(theta(options_ami.sens_ind));\n');
202-
fprintf(fid,' case 2\n');
203-
fprintf(fid,' chainRuleFactor = 10.^theta(options_ami.sens_ind)*log(10);\n');
204-
fprintf(fid,' otherwise\n');
205-
fprintf(fid,' chainRuleFactor = ones(size(options_ami.sens_ind));\n');
206-
fprintf(fid,'end\n\n');
207199

208200
if(o2flag == 2)
209201
fprintf(fid,'if(nargin>=6)\n');
202+
fprintf(fid,' chainRuleFactor = getChainRuleFactors(options_ami.pscale, theta, options_ami.sens_ind);\n');
210203
fprintf(fid,' v = varargin{6};\n');
211204
fprintf(fid,' v = v(:).*chainRuleFactor;\n');
212205
fprintf(fid,'else\n');
@@ -267,15 +260,15 @@ function generateMatlabWrapper(nx, ny, np, nk, nz, o2flag, amimodelo2, wrapperFi
267260
end
268261
fprintf(fid,'plist = options_ami.sens_ind-1;\n');
269262
fprintf(fid,['if(nargin>=4)\n']);
270-
fprintf(fid,[' if(isempty(varargin{4}));\n']);
263+
fprintf(fid,[' if(isempty(varargin{4}))\n']);
271264
fprintf(fid,[' data=[];\n']);
272265
fprintf(fid,[' else\n']);
273-
fprintf(fid,[' if(isa(varargin{4},''amidata''));\n']);
266+
fprintf(fid,[' if(isa(varargin{4},''amidata''))\n']);
274267
fprintf(fid,[' data=varargin{4};\n']);
275268
fprintf(fid,[' else\n']);
276269
fprintf(fid,[' data=amidata(varargin{4});\n']);
277270
fprintf(fid,[' end\n']);
278-
fprintf(fid,[' if(data.ne>0);\n']);
271+
fprintf(fid,[' if(data.ne>0)\n']);
279272
fprintf(fid,[' options_ami.nmaxevent = data.ne;\n']);
280273
fprintf(fid,[' else\n']);
281274
fprintf(fid,[' data.ne = options_ami.nmaxevent;\n']);
@@ -326,6 +319,7 @@ function generateMatlabWrapper(nx, ny, np, nk, nz, o2flag, amimodelo2, wrapperFi
326319
fprintf(fid,' if(size(options_ami.sx0,1)~=nxfull)\n');
327320
fprintf(fid,' error(''Number of rows in sx0 field does not agree with number of states!'');\n');
328321
fprintf(fid,' end\n');
322+
fprintf(fid,' chainRuleFactor = getChainRuleFactors(options_ami.pscale, theta, options_ami.sens_ind);\n');
329323
fprintf(fid,' init.sx0 = bsxfun(@times,options_ami.sx0,1./permute(chainRuleFactor(:),[2,1]));\n');
330324
fprintf(fid,'end\n');
331325

@@ -425,6 +419,28 @@ function generateMatlabWrapper(nx, ny, np, nk, nz, o2flag, amimodelo2, wrapperFi
425419
fprintf(fid,'else\n');
426420
fprintf(fid,' varargout{1} = sol;\n');
427421
fprintf(fid,'end\n');
422+
423+
fprintf(fid,'function chainRuleFactors = getChainRuleFactors(pscale, theta, sens_ind)\n');
424+
fprintf(fid,' if(length(pscale) == 1 && length(sens_ind) ~= length(pscale))\n');
425+
fprintf(fid,' chainRuleFactors = arrayfun(@(x, ip) getChainRuleFactor(x, theta(ip)), repmat(pscale, 1, length(sens_ind)), sens_ind);\n');
426+
fprintf(fid,' else\n');
427+
fprintf(fid,' chainRuleFactors = arrayfun(@(x, ip) getChainRuleFactor(x, theta(ip)), pscale, sens_ind);\n');
428+
fprintf(fid,' end\n');
429+
fprintf(fid,'end\n');
430+
fprintf(fid,'\n');
431+
432+
fprintf(fid,'function chainRuleFactor = getChainRuleFactor(pscale, parameterValue)\n');
433+
fprintf(fid,' switch (pscale)\n');
434+
fprintf(fid,' case 1\n');
435+
fprintf(fid,' chainRuleFactor = exp(parameterValue);\n');
436+
fprintf(fid,' case 2\n');
437+
fprintf(fid,' chainRuleFactor = 10.^parameterValue*log(10);\n');
438+
fprintf(fid,' otherwise\n');
439+
fprintf(fid,' chainRuleFactor = 1.0;\n');
440+
fprintf(fid,' end\n');
441+
fprintf(fid,'end\n');
442+
fprintf(fid,'\n');
443+
428444
fprintf(fid,'end\n');
429445

430446
fclose(fid);

matlab/@amioption/amioption.m

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@
5858
% mapping of event ouputs to events
5959
z2event = double.empty();
6060
% parameter scaling
61+
% Single value or vector matching sens_ind.
6162
% Valid options are "log","log10" and "lin" for log, log10 or
62-
% unscaled parameters p
63-
% use "" for default as specified in the model (fallback: 'lin')
64-
pscale = '';
63+
% unscaled parameters p.
64+
% Use [] for default as specified in the model (fallback: 'lin').
65+
pscale = [];
6566
end
6667

6768
methods
@@ -215,20 +216,12 @@
215216
function this = set.pscale(this,value)
216217
if(~isempty(value))
217218
if(isnumeric(value))
218-
assert(value == 0 || value == 1 || value == 2, ...
219-
'No valid parametrisation chosen! Valid integer options are 0 (lin), 1 (log), 2 (log10).');
219+
arrayfun(@(x) assert(x == 0 || x == 1 || x == 2, ...
220+
'No valid parametrisation chosen! Valid integer options are 0 (lin), 1 (log), 2 (log10).'), value);
221+
elseif(ischar(value))
222+
value = getIntegerPScale(value);
220223
else
221-
switch (value)
222-
case 'lin'
223-
value = 0;
224-
case 'log'
225-
value = 1;
226-
case 'log10'
227-
value = 2;
228-
otherwise
229-
assert(0, ...
230-
'No valid parametrisation chosen! Valid string options are "log", "log10" and "lin".')
231-
end
224+
value = arrayfun(@(x) getIntegerPScale(x), value);
232225
end
233226
end
234227
this.pscale = value;
@@ -257,4 +250,18 @@
257250
this.newton_preeq = value;
258251
end
259252
end
253+
end
254+
255+
function pscaleInt = getIntegerPScale(pscaleString)
256+
switch (pscaleString)
257+
case 'lin'
258+
pscaleInt = 0;
259+
case 'log'
260+
pscaleInt = 1;
261+
case 'log10'
262+
pscaleInt = 2;
263+
otherwise
264+
assert(0, ...
265+
'No valid parametrisation chosen! Valid string options are "log", "log10" and "lin".')
266+
end
260267
end

models/model_dirac/model_dirac.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifndef _amici_model_dirac_h
22
#define _amici_model_dirac_h
3-
/* Generated by amiwrap (R2017b) f1e875655d8b056a0adf3c71f583fe988f257a06 */
3+
/* Generated by amiwrap (R2017b) acb0375e4e0c93fb725d81b42e7e818c9ba7b65d */
44
#include <cmath>
55
#include <memory>
66
#include "amici/defines.h"
@@ -62,7 +62,7 @@ class Model_model_dirac : public amici::Model_ODE {
6262

6363
virtual amici::Model* clone() const override { return new Model_model_dirac(*this); };
6464

65-
const char* getAmiciVersion() const { return "f1e875655d8b056a0adf3c71f583fe988f257a06"; };
65+
const char* getAmiciVersion() const { return "acb0375e4e0c93fb725d81b42e7e818c9ba7b65d"; };
6666

6767
virtual void fJ(realtype *J, const realtype t, const realtype *x, const double *p, const double *k, const realtype *h, const realtype *w, const realtype *dwdx) override {
6868
J_model_dirac(J, t, x, p, k, h, w, dwdx);

models/model_events/model_events.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifndef _amici_model_events_h
22
#define _amici_model_events_h
3-
/* Generated by amiwrap (R2017b) f1e875655d8b056a0adf3c71f583fe988f257a06 */
3+
/* Generated by amiwrap (R2017b) acb0375e4e0c93fb725d81b42e7e818c9ba7b65d */
44
#include <cmath>
55
#include <memory>
66
#include "amici/defines.h"
@@ -76,7 +76,7 @@ class Model_model_events : public amici::Model_ODE {
7676

7777
virtual amici::Model* clone() const override { return new Model_model_events(*this); };
7878

79-
const char* getAmiciVersion() const { return "f1e875655d8b056a0adf3c71f583fe988f257a06"; };
79+
const char* getAmiciVersion() const { return "acb0375e4e0c93fb725d81b42e7e818c9ba7b65d"; };
8080

8181
virtual void fJ(realtype *J, const realtype t, const realtype *x, const double *p, const double *k, const realtype *h, const realtype *w, const realtype *dwdx) override {
8282
J_model_events(J, t, x, p, k, h, w, dwdx);

models/model_jakstat_adjoint/model_jakstat_adjoint.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifndef _amici_model_jakstat_adjoint_h
22
#define _amici_model_jakstat_adjoint_h
3-
/* Generated by amiwrap (R2017b) f1e875655d8b056a0adf3c71f583fe988f257a06 */
3+
/* Generated by amiwrap (R2017b) acb0375e4e0c93fb725d81b42e7e818c9ba7b65d */
44
#include <cmath>
55
#include <memory>
66
#include "amici/defines.h"
@@ -65,7 +65,7 @@ class Model_model_jakstat_adjoint : public amici::Model_ODE {
6565

6666
virtual amici::Model* clone() const override { return new Model_model_jakstat_adjoint(*this); };
6767

68-
const char* getAmiciVersion() const { return "f1e875655d8b056a0adf3c71f583fe988f257a06"; };
68+
const char* getAmiciVersion() const { return "acb0375e4e0c93fb725d81b42e7e818c9ba7b65d"; };
6969

7070
virtual void fJ(realtype *J, const realtype t, const realtype *x, const double *p, const double *k, const realtype *h, const realtype *w, const realtype *dwdx) override {
7171
J_model_jakstat_adjoint(J, t, x, p, k, h, w, dwdx);

models/model_jakstat_adjoint_o2/model_jakstat_adjoint_o2.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifndef _amici_model_jakstat_adjoint_o2_h
22
#define _amici_model_jakstat_adjoint_o2_h
3-
/* Generated by amiwrap (R2017b) f1e875655d8b056a0adf3c71f583fe988f257a06 */
3+
/* Generated by amiwrap (R2017b) acb0375e4e0c93fb725d81b42e7e818c9ba7b65d */
44
#include <cmath>
55
#include <memory>
66
#include "amici/defines.h"
@@ -65,7 +65,7 @@ class Model_model_jakstat_adjoint_o2 : public amici::Model_ODE {
6565

6666
virtual amici::Model* clone() const override { return new Model_model_jakstat_adjoint_o2(*this); };
6767

68-
const char* getAmiciVersion() const { return "f1e875655d8b056a0adf3c71f583fe988f257a06"; };
68+
const char* getAmiciVersion() const { return "acb0375e4e0c93fb725d81b42e7e818c9ba7b65d"; };
6969

7070
virtual void fJ(realtype *J, const realtype t, const realtype *x, const double *p, const double *k, const realtype *h, const realtype *w, const realtype *dwdx) override {
7171
J_model_jakstat_adjoint_o2(J, t, x, p, k, h, w, dwdx);

models/model_nested_events/model_nested_events.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifndef _amici_model_nested_events_h
22
#define _amici_model_nested_events_h
3-
/* Generated by amiwrap (R2017b) f1e875655d8b056a0adf3c71f583fe988f257a06 */
3+
/* Generated by amiwrap (R2017b) acb0375e4e0c93fb725d81b42e7e818c9ba7b65d */
44
#include <cmath>
55
#include <memory>
66
#include "amici/defines.h"
@@ -65,7 +65,7 @@ class Model_model_nested_events : public amici::Model_ODE {
6565

6666
virtual amici::Model* clone() const override { return new Model_model_nested_events(*this); };
6767

68-
const char* getAmiciVersion() const { return "f1e875655d8b056a0adf3c71f583fe988f257a06"; };
68+
const char* getAmiciVersion() const { return "acb0375e4e0c93fb725d81b42e7e818c9ba7b65d"; };
6969

7070
virtual void fJ(realtype *J, const realtype t, const realtype *x, const double *p, const double *k, const realtype *h, const realtype *w, const realtype *dwdx) override {
7171
J_model_nested_events(J, t, x, p, k, h, w, dwdx);

models/model_neuron/model_neuron.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifndef _amici_model_neuron_h
22
#define _amici_model_neuron_h
3-
/* Generated by amiwrap (R2017b) f1e875655d8b056a0adf3c71f583fe988f257a06 */
3+
/* Generated by amiwrap (R2017b) acb0375e4e0c93fb725d81b42e7e818c9ba7b65d */
44
#include <cmath>
55
#include <memory>
66
#include "amici/defines.h"
@@ -79,7 +79,7 @@ class Model_model_neuron : public amici::Model_ODE {
7979

8080
virtual amici::Model* clone() const override { return new Model_model_neuron(*this); };
8181

82-
const char* getAmiciVersion() const { return "f1e875655d8b056a0adf3c71f583fe988f257a06"; };
82+
const char* getAmiciVersion() const { return "acb0375e4e0c93fb725d81b42e7e818c9ba7b65d"; };
8383

8484
virtual void fJ(realtype *J, const realtype t, const realtype *x, const double *p, const double *k, const realtype *h, const realtype *w, const realtype *dwdx) override {
8585
J_model_neuron(J, t, x, p, k, h, w, dwdx);

models/model_neuron_o2/model_neuron_o2.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifndef _amici_model_neuron_o2_h
22
#define _amici_model_neuron_o2_h
3-
/* Generated by amiwrap (R2017b) f1e875655d8b056a0adf3c71f583fe988f257a06 */
3+
/* Generated by amiwrap (R2017b) acb0375e4e0c93fb725d81b42e7e818c9ba7b65d */
44
#include <cmath>
55
#include <memory>
66
#include "amici/defines.h"
@@ -81,7 +81,7 @@ class Model_model_neuron_o2 : public amici::Model_ODE {
8181

8282
virtual amici::Model* clone() const override { return new Model_model_neuron_o2(*this); };
8383

84-
const char* getAmiciVersion() const { return "f1e875655d8b056a0adf3c71f583fe988f257a06"; };
84+
const char* getAmiciVersion() const { return "acb0375e4e0c93fb725d81b42e7e818c9ba7b65d"; };
8585

8686
virtual void fJ(realtype *J, const realtype t, const realtype *x, const double *p, const double *k, const realtype *h, const realtype *w, const realtype *dwdx) override {
8787
J_model_neuron_o2(J, t, x, p, k, h, w, dwdx);

models/model_robertson/model_robertson.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#ifndef _amici_model_robertson_h
22
#define _amici_model_robertson_h
3-
/* Generated by amiwrap (R2017b) f1e875655d8b056a0adf3c71f583fe988f257a06 */
3+
/* Generated by amiwrap (R2017b) acb0375e4e0c93fb725d81b42e7e818c9ba7b65d */
44
#include <cmath>
55
#include <memory>
66
#include "amici/defines.h"
@@ -63,7 +63,7 @@ class Model_model_robertson : public amici::Model_DAE {
6363

6464
virtual amici::Model* clone() const override { return new Model_model_robertson(*this); };
6565

66-
const char* getAmiciVersion() const { return "f1e875655d8b056a0adf3c71f583fe988f257a06"; };
66+
const char* getAmiciVersion() const { return "acb0375e4e0c93fb725d81b42e7e818c9ba7b65d"; };
6767

6868
virtual void fJ(realtype *J, const realtype t, const realtype *x, const double *p, const double *k, const realtype *h, const realtype cj, const realtype *dx, const realtype *w, const realtype *dwdx) override {
6969
J_model_robertson(J, t, x, p, k, h, cj, dx, w, dwdx);

0 commit comments

Comments
 (0)