Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for observable-dependent sigmas #1692

Merged
merged 24 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions include/amici/abstract_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -561,20 +561,37 @@ class AbstractModel {
* @param t current time
* @param p parameter vector
* @param k constant vector
* @param y model output at timepoint t
*/
virtual void fsigmay(realtype *sigmay, const realtype t, const realtype *p,
const realtype *k);
const realtype *k, const realtype *y);

/**
* @brief Model-specific implementation of fsigmay
* @brief Model-specific implementation of fdsigmaydp
* @param dsigmaydp partial derivative of standard deviation of measurements
* @param t current time
* @param p parameter vector
* @param k constant vector
* @param y model output at timepoint t
* @param ip sensitivity index
*/
virtual void fdsigmaydp(realtype *dsigmaydp, const realtype t,
const realtype *p, const realtype *k, int ip);
const realtype *p, const realtype *k,
const realtype *y, int ip);
/**
* @brief Model-specific implementation of fsigmay
* @param dsigmaydy partial derivative of standard deviation of measurements
* w.r.t. model outputs
* @param t current time
* @param p parameter vector
* @param k constant vector
* @param y model output at timepoint t
* @param ip sensitivity index
*/
virtual void fdsigmaydy(realtype *dsigmaydy, const realtype t,
const realtype *p, const realtype *k,
const realtype *y, int ip);


/**
* @brief Model-specific implementation of fsigmaz
Expand Down
11 changes: 11 additions & 0 deletions include/amici/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class Model : public AbstractModel, public ModelDimensions {
using AbstractModel::fdrzdp;
using AbstractModel::fdrzdx;
using AbstractModel::fdsigmaydp;
using AbstractModel::fdsigmaydy;
using AbstractModel::fdsigmazdp;
using AbstractModel::fdwdp;
using AbstractModel::fdwdp_colptrs;
Expand Down Expand Up @@ -851,11 +852,13 @@ class Model : public AbstractModel, public ModelDimensions {
* Total derivative (can be used with both adjoint and forward sensitivity).
*
* @param ssigmay Buffer (shape `ny` x `nplist`, row-major)
* @param sy Sensitivity of time-resolved observables for current timepoint
* @param it Timepoint index
* @param edata Pointer to experimental data instance (optional, pass
* `nullptr` to ignore)
*/
void getObservableSigmaSensitivity(gsl::span<realtype> ssigmay,
gsl::span<const realtype> sy,
const int it, const ExpData *edata);

/**
Expand Down Expand Up @@ -1396,6 +1399,14 @@ class Model : public AbstractModel, public ModelDimensions {
*/
void fdsigmaydp(int it, const ExpData *edata);

/**
* @brief Compute partial derivative of standard deviation of measurements
* w.r.t. model outputs.
* @param it Timepoint index
* @param edata pointer to `amici::ExpData` data instance holding sigma values
*/
void fdsigmaydy(int it, const ExpData *edata);

/**
* @brief Compute negative log-likelihood of measurements \f$ y \f$.
*
Expand Down
7 changes: 6 additions & 1 deletion include/amici/model_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,16 @@ struct ModelStateDerived {
/** data standard deviation for current timepoint (dimension: ny) */
std::vector<realtype> sigmay_;

/** temporary storage for parameter derivative of data standard deviation,
/** temporary storage for parameter derivative of data standard deviation,
* (dimension: ny x nplist, row-major)
*/
std::vector<realtype> dsigmaydp_;

/** temporary storage for observable derivative of data standard deviation,
* (dimension: ny x ny, row-major)
*/
std::vector<realtype> dsigmaydy_;

/** temporary storage for event-resolved observable (dimension: nz) */
std::vector<realtype> z_;

Expand Down
4 changes: 2 additions & 2 deletions matlab/@amifun/getArgs.m
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@
case 'dxdotdp'
this.argstr = ['(realtype *dxdotdp, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const int ip' dx ', const realtype *w, const realtype *dwdp)'];
case 'sigma_y'
this.argstr = '(double *sigmay, const realtype t, const realtype *p, const realtype *k)';
this.argstr = '(double *sigmay, const realtype t, const realtype *p, const realtype *k, const realtype *y)';
case 'dsigma_ydp'
this.argstr = '(double *dsigmaydp, const realtype t, const realtype *p, const realtype *k, const int ip)';
this.argstr = '(double *dsigmaydp, const realtype t, const realtype *p, const realtype *k, const realtype *y, const int ip)';
case 'sigma_z'
this.argstr = '(double *sigmaz, const realtype t, const realtype *p, const realtype *k)';
case 'dsigma_zdp'
Expand Down
12 changes: 6 additions & 6 deletions models/model_calvetti/model_calvetti.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef _amici_model_calvetti_h
#define _amici_model_calvetti_h
/* Generated by amiwrap (R2017b) 9212bbdaf5712727ff284cc475f16d2a983f9bf2 */
/* Generated by amiwrap (R2017b) e8e46ac8ec0c895549703eace15f2135fdb1747b */
#include <cmath>
#include <memory>
#include "amici/defines.h"
Expand All @@ -22,7 +22,7 @@ extern void dJydy_model_calvetti(double *dJydy, const int iy, const realtype *p,
extern void dwdx_model_calvetti(realtype *dwdx, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *w, const realtype *tcl);
extern void dydx_model_calvetti(double *dydx, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *w, const realtype *dwdx);
extern void root_model_calvetti(realtype *root, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *dx);
extern void sigmay_model_calvetti(double *sigmay, const realtype t, const realtype *p, const realtype *k);
extern void sigmay_model_calvetti(double *sigmay, const realtype t, const realtype *p, const realtype *k, const realtype *y);
extern void w_model_calvetti(realtype *w, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *tcl);
extern void x0_model_calvetti(realtype *x0, const realtype t, const realtype *p, const realtype *k);
extern void xdot_model_calvetti(realtype *xdot, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *dx, const realtype *w);
Expand Down Expand Up @@ -67,7 +67,7 @@ class Model_model_calvetti : public amici::Model_DAE {

amici::Model* clone() const override { return new Model_model_calvetti(*this); };

std::string getAmiciCommit() const override { return "9212bbdaf5712727ff284cc475f16d2a983f9bf2"; };
std::string getAmiciCommit() const override { return "e8e46ac8ec0c895549703eace15f2135fdb1747b"; };

void fJSparse(SUNMatrixContent_Sparse JSparse, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype cj, const realtype *dx, const realtype *w, const realtype *dwdx) override {
JSparse_model_calvetti(JSparse, t, x, p, k, h, cj, dx, w, dwdx);
Expand Down Expand Up @@ -125,7 +125,7 @@ class Model_model_calvetti : public amici::Model_DAE {
void fdrzdx(double *drzdx, const int ie, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h) override {
}

void fdsigmaydp(double *dsigmaydp, const realtype t, const realtype *p, const realtype *k, const int ip) override {
void fdsigmaydp(double *dsigmaydp, const realtype t, const realtype *p, const realtype *k, const realtype *y, const int ip) override {
}

void fdsigmazdp(double *dsigmazdp, const realtype t, const realtype *p, const realtype *k, const int ip) override {
Expand Down Expand Up @@ -161,8 +161,8 @@ class Model_model_calvetti : public amici::Model_DAE {
void frz(double *rz, const int ie, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h) override {
}

void fsigmay(double *sigmay, const realtype t, const realtype *p, const realtype *k) override {
sigmay_model_calvetti(sigmay, t, p, k);
void fsigmay(double *sigmay, const realtype t, const realtype *p, const realtype *k, const realtype *y) override {
sigmay_model_calvetti(sigmay, t, p, k, y);
}

void fsigmaz(double *sigmaz, const realtype t, const realtype *p, const realtype *k) override {
Expand Down
2 changes: 1 addition & 1 deletion models/model_calvetti/model_calvetti_sigmay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace amici {

namespace model_model_calvetti{

void sigmay_model_calvetti(double *sigmay, const realtype t, const realtype *p, const realtype *k) {
void sigmay_model_calvetti(double *sigmay, const realtype t, const realtype *p, const realtype *k, const realtype *y) {
sigmay[0] = 1.0;
sigmay[1] = 1.0;
sigmay[2] = 1.0;
Expand Down
12 changes: 6 additions & 6 deletions models/model_dirac/model_dirac.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef _amici_model_dirac_h
#define _amici_model_dirac_h
/* Generated by amiwrap (R2017b) 9212bbdaf5712727ff284cc475f16d2a983f9bf2 */
/* Generated by amiwrap (R2017b) e8e46ac8ec0c895549703eace15f2135fdb1747b */
#include <cmath>
#include <memory>
#include "amici/defines.h"
Expand All @@ -23,7 +23,7 @@ extern void deltax_model_dirac(double *deltax, const realtype t, const realtype
extern void dxdotdp_model_dirac(realtype *dxdotdp, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const int ip, const realtype *w, const realtype *dwdp);
extern void dydx_model_dirac(double *dydx, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *w, const realtype *dwdx);
extern void root_model_dirac(realtype *root, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *tcl);
extern void sigmay_model_dirac(double *sigmay, const realtype t, const realtype *p, const realtype *k);
extern void sigmay_model_dirac(double *sigmay, const realtype t, const realtype *p, const realtype *k, const realtype *y);
extern void stau_model_dirac(double *stau, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *tcl, const realtype *sx, const int ip, const int ie);
extern void xdot_model_dirac(realtype *xdot, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *w);
extern void y_model_dirac(double *y, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *w);
Expand Down Expand Up @@ -67,7 +67,7 @@ class Model_model_dirac : public amici::Model_ODE {

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

std::string getAmiciCommit() const override { return "9212bbdaf5712727ff284cc475f16d2a983f9bf2"; };
std::string getAmiciCommit() const override { return "e8e46ac8ec0c895549703eace15f2135fdb1747b"; };

void fJSparse(SUNMatrixContent_Sparse JSparse, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *w, const realtype *dwdx) override {
JSparse_model_dirac(JSparse, t, x, p, k, h, w, dwdx);
Expand Down Expand Up @@ -123,7 +123,7 @@ class Model_model_dirac : public amici::Model_ODE {
void fdrzdx(double *drzdx, const int ie, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h) override {
}

void fdsigmaydp(double *dsigmaydp, const realtype t, const realtype *p, const realtype *k, const int ip) override {
void fdsigmaydp(double *dsigmaydp, const realtype t, const realtype *p, const realtype *k, const realtype *y, const int ip) override {
}

void fdsigmazdp(double *dsigmazdp, const realtype t, const realtype *p, const realtype *k, const int ip) override {
Expand Down Expand Up @@ -159,8 +159,8 @@ class Model_model_dirac : public amici::Model_ODE {
void frz(double *rz, const int ie, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h) override {
}

void fsigmay(double *sigmay, const realtype t, const realtype *p, const realtype *k) override {
sigmay_model_dirac(sigmay, t, p, k);
void fsigmay(double *sigmay, const realtype t, const realtype *p, const realtype *k, const realtype *y) override {
sigmay_model_dirac(sigmay, t, p, k, y);
}

void fsigmaz(double *sigmaz, const realtype t, const realtype *p, const realtype *k) override {
Expand Down
2 changes: 1 addition & 1 deletion models/model_dirac/model_dirac_sigmay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace amici {

namespace model_model_dirac{

void sigmay_model_dirac(double *sigmay, const realtype t, const realtype *p, const realtype *k) {
void sigmay_model_dirac(double *sigmay, const realtype t, const realtype *p, const realtype *k, const realtype *y) {
sigmay[0] = 1.0;
}

Expand Down
12 changes: 6 additions & 6 deletions models/model_events/model_events.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#ifndef _amici_model_events_h
#define _amici_model_events_h
/* Generated by amiwrap (R2017b) 9212bbdaf5712727ff284cc475f16d2a983f9bf2 */
/* Generated by amiwrap (R2017b) e8e46ac8ec0c895549703eace15f2135fdb1747b */
#include <cmath>
#include <memory>
#include "amici/defines.h"
Expand Down Expand Up @@ -32,7 +32,7 @@ extern void dydx_model_events(double *dydx, const realtype t, const realtype *x,
extern void dzdx_model_events(double *dzdx, const int ie, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h);
extern void root_model_events(realtype *root, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *tcl);
extern void rz_model_events(double *rz, const int ie, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h);
extern void sigmay_model_events(double *sigmay, const realtype t, const realtype *p, const realtype *k);
extern void sigmay_model_events(double *sigmay, const realtype t, const realtype *p, const realtype *k, const realtype *y);
extern void sigmaz_model_events(double *sigmaz, const realtype t, const realtype *p, const realtype *k);
extern void srz_model_events(double *srz, const int ie, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *sx, const int ip);
extern void stau_model_events(double *stau, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *tcl, const realtype *sx, const int ip, const int ie);
Expand Down Expand Up @@ -81,7 +81,7 @@ class Model_model_events : public amici::Model_ODE {

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

std::string getAmiciCommit() const override { return "9212bbdaf5712727ff284cc475f16d2a983f9bf2"; };
std::string getAmiciCommit() const override { return "e8e46ac8ec0c895549703eace15f2135fdb1747b"; };

void fJSparse(SUNMatrixContent_Sparse JSparse, const realtype t, const realtype *x, const realtype *p, const realtype *k, const realtype *h, const realtype *w, const realtype *dwdx) override {
JSparse_model_events(JSparse, t, x, p, k, h, w, dwdx);
Expand Down Expand Up @@ -143,7 +143,7 @@ class Model_model_events : public amici::Model_ODE {
drzdx_model_events(drzdx, ie, t, x, p, k, h);
}

void fdsigmaydp(double *dsigmaydp, const realtype t, const realtype *p, const realtype *k, const int ip) override {
void fdsigmaydp(double *dsigmaydp, const realtype t, const realtype *p, const realtype *k, const realtype *y, const int ip) override {
}

void fdsigmazdp(double *dsigmazdp, const realtype t, const realtype *p, const realtype *k, const int ip) override {
Expand Down Expand Up @@ -182,8 +182,8 @@ class Model_model_events : public amici::Model_ODE {
rz_model_events(rz, ie, t, x, p, k, h);
}

void fsigmay(double *sigmay, const realtype t, const realtype *p, const realtype *k) override {
sigmay_model_events(sigmay, t, p, k);
void fsigmay(double *sigmay, const realtype t, const realtype *p, const realtype *k, const realtype *y) override {
sigmay_model_events(sigmay, t, p, k, y);
}

void fsigmaz(double *sigmaz, const realtype t, const realtype *p, const realtype *k) override {
Expand Down
2 changes: 1 addition & 1 deletion models/model_events/model_events_sigmay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace amici {

namespace model_model_events{

void sigmay_model_events(double *sigmay, const realtype t, const realtype *p, const realtype *k) {
void sigmay_model_events(double *sigmay, const realtype t, const realtype *p, const realtype *k, const realtype *y) {
sigmay[0] = 1.0;
}

Expand Down
Loading