Skip to content

Local objective and prediction

Download the notebook (executed for this page) · source

The prediction is alpha times the sum of protein and phosphosite beta effects, clipped at zero. The same function is used for fitting and reporting. Seven losses retain their original constants; gradients use JAX float64.

from pathlib import Path
import os, sys
ROOT = next(p for p in [Path.cwd(), *Path.cwd().parents] if (p / 'pixi.toml').exists())
os.environ['TFOPT_CONFIG'] = str(ROOT / 'notebooks/data/toy.toml')
os.environ.setdefault('MPLBACKEND', 'Agg')
if str(ROOT) not in sys.path:
    sys.path.insert(0, str(ROOT))
import tfopt
import numpy as np
import pandas as pd
from notebooks.tutorial import build_problem, optimize, OUTPUT
p = build_problem()
import jax
from tfopt.local.objfn.minfn import objective_,compute_predictions
args=p['args']
obs,regs,protein,sites,nr,T,ng,starts,counts,loss=args
pred=compute_predictions(p['known'],regs,protein,sites,nr,T,ng,starts,counts)
np.testing.assert_allclose(pred,obs,atol=1e-12)
assert pred.dtype.name=='float64'
for loss in range(7):
    print(loss,float(objective_(p['known'],*args[:-1],loss)))
grad=jax.grad(lambda x:objective_(x,*args))(p['x0'])
assert np.isfinite(grad).all()
0 4.8276643939306716e-32
1 9.992007221626409e-17
2 0.0
3 4.8276643939306716e-32
4 4.8276643939306716e-32
5 6.259999999999999e-06
6 2.8599999999999997e-06

Interpretation

Check both fit and feasibility. For biological data, identifiability, scaling and regulatory coverage need domain review. Results and figures belong only in notebooks/outputs/.