Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
39 changes: 39 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,42 @@ venv.bak/
*.aux
*.out
*.pdf


# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so

# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Logs and databases #
######################
*.log
*.sql
*.sqlite

# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
115 changes: 90 additions & 25 deletions notebooks/biochemical_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 79,
"metadata": {},
"outputs": [],
"source": [
"from math import exp\n",
"\n",
"from pyro.distributions import LogNormal\n",
"from pyro.distributions import LogNormal,Normal\n",
"from pyro.primitives import iarange\n",
"from pyro import condition, do, infer, sample\n",
"from pyro.infer import EmpiricalMarginal\n",
"from torch import tensor\n",
"\n",
"import sys\n",
"sys.path.append('../')\n",
"from causal_demon.inference import infer_dist\n",
"from causal_demon.transmitters import cancer_signaling\n",
"\n",
Expand All @@ -65,27 +68,58 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 82,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"tensor(0.1904)\n"
]
}
],
"source": [
"noise_vars = ['N_egf', 'N_igf', 'N_sos', 'N_ras', 'N_pi3k', 'N_akt', 'N_raf', 'N_mek', 'N_erk']\n",
"noise_prior = {N: LogNormal(0, 10) for N in noise_vars}"
"noise_prior = {N: LogNormal(0, 10) for N in noise_vars}\n",
"\n",
"print(noise_prior['N_egf'].sample())"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 83,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"{'akt': tensor(405643.),\n",
" 'egf': tensor(44953.8320),\n",
" 'erk': tensor(3115.5735),\n",
" 'igf': tensor(0.1029),\n",
" 'mek': tensor(162.8303),\n",
" 'pi3k': tensor(119770.7422),\n",
" 'raf': tensor(4.5652),\n",
" 'ras': tensor(176.5171),\n",
" 'sos': tensor(28.5478)}"
]
},
"execution_count": 83,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cancer_signaling(noise_prior)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"execution_count": 84,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# Experimental use only, please ignore\n",
Expand Down Expand Up @@ -127,12 +161,19 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 213,
"metadata": {},
"outputs": [],
"source": [
"evidence = {'egf': tensor(800.), 'igf': tensor(0.), 'erk': tensor(800.)}\n",
"cancer_obs = condition(cancer_signaling, data=evidence)"
"evidence = {'egf': tensor([800.]), 'igf': tensor([0.,0.]), 'erk': tensor([800.])}\n",
"\n",
"cancer_obs = condition(cancer_signaling, data= evidence)\n",
"\n",
"#evidence = [{'egf': tensor([800.]), 'igf': tensor([0.]), 'erk': tensor([800.])},{'egf': tensor([800.]), 'igf': tensor([0.]), 'erk': tensor([800.])},{'egf': tensor([600.]), 'igf': tensor([0.]), 'erk': tensor([600.])},{'egf': tensor([800.]), 'igf': tensor([0.]), 'erk': tensor([800.])},{'egf': tensor([600.]), 'igf': tensor([0.]), 'erk': tensor([600.])}]\n",
"\n",
"#with iarange('data',len(evidence)) as ind:\n",
"# print(ind)\n",
"# cancer_obs = condition(cancer_signaling, data= evidence)"
]
},
{
Expand All @@ -144,7 +185,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 180,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -160,8 +201,10 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"execution_count": 181,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"noise_marginals = {\n",
Expand All @@ -179,11 +222,11 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 204,
"metadata": {},
"outputs": [],
"source": [
"cancer_do = do(cancer_signaling, data={'igf': tensor(800.)})"
"cancer_do = do(cancer_signaling, data={'igf': tensor([800.,600.])})"
]
},
{
Expand All @@ -195,21 +238,43 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 207,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<pyro.infer.importance.Importance object at 0x152ad7df98>\n"
]
}
],
"source": [
"cancer_do_dist = infer_dist(cancer_do, noise_marginals)\n",
"print(cancer_do_dist)\n",
"erk_cf_marginal = EmpiricalMarginal(cancer_do_dist, sites = 'erk')"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 201,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[tensor([90.9036, 90.9029])]\n"
]
}
],
"source": [
"hist(erk_cf_marginal, 'Erk')"
"#hist(erk_cf_marginal, 'Erk')\n",
"\n",
"print(erk_cf_marginal())\n",
"#\n",
"#plt.hist([erk_cf_marginal().item() for _ in range(100)])\n",
"#plt.title(\"Erk\")"
]
},
{
Expand All @@ -226,9 +291,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"display_name": "Python 3",
"language": "python",
"name": "venv"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -240,7 +305,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.6.3"
}
},
"nbformat": 4,
Expand Down
Loading