Created
July 12, 2016 21:56
-
-
Save fonnesbeck/7d3ed7234e27159359424202175a95ff to your computer and use it in GitHub Desktop.
Manatee Mortality.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"metadata": { | |
"collapsed": true, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "%matplotlib inline\nimport pymc3 as pm\nimport numpy as np\nimport pandas as pd\nimport theano.tensor as tt\nfrom theano import shared, config\n\nfrom theano.tensor.shared_randomstreams import RandomStreams\nsrng = RandomStreams(seed=20090425)", | |
"execution_count": 1, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true, | |
"collapsed": true | |
}, | |
"cell_type": "code", | |
"source": "config.exception_verbosity='high'", | |
"execution_count": 23, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"collapsed": false, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "data15 = pd.read_csv('mortalities.15km.dword.1996.2013.csv')\ndata30 = pd.read_csv('mortalities.30km.dword.1996.2013.csv')", | |
"execution_count": 3, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"collapsed": true, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "# FL regions\nregions = ['ATL', 'USJ', 'NW', 'SW']\nATL, USJ, NW, SW = range(4)\n\n# Winter habitat quality\nhabitats = ['Low', 'Medium', 'High']\nLOW, MED, HIGH = range(3)\n\n# Causes of death\ncauses = ['watercraft', 'wcs', 'debris', 'cold', 'redtide', 'other']\nlong_causes = causes + ['undetermined']\nWATERCRAFT, WCS, DEBRIS, COLD, REDTIED, OTHER, UNDETERMINED = range(7)\n\n# Age classes\nclasses = ['Calves', 'Subadults', 'Adults']\n\nSTARTYEAR, ENDYEAR = 1996, 2013\n\n# Unusual mortality event red tide years\ntide_years = (1996, 2002, 2003, 2005, 2006, 2012, 2013)\n# Moderately unusual red tide years\ntide_years0 = (2002, 2003, 2005, 2006, 2012)\n# Intense red tide years\ntide_years_intense = (1996, 2013)\n# Atlantic unusual mortality event red tide years\natl_tide_years = (2007, 2008)\n\n# Severe cold years\nsevere_years = {ATL: range(2010, 2011), USJ: range(2010, 2011), NW: (2003, 2010), SW: range(2010, 2011)} \n\n# Cold years\ncold_years = {ATL: (1996, 2001, 2003), USJ: (1996, 2001, 2009, 2011), \n NW: (1996, 1998, 2001, 2011), SW: (1996, 2001)}", | |
"execution_count": 4, | |
"outputs": [] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "Uninformative priors for unknown proportions" | |
}, | |
{ | |
"metadata": { | |
"collapsed": true, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "ncauses = len(causes), len(causes)-1, len(causes), len(causes)\nprior0 = [np.ones(k) for k in ncauses]\n", | |
"execution_count": 5, | |
"outputs": [] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "From Langtimm et al. 2004 (mortality ratios from USJ)" | |
}, | |
{ | |
"metadata": { | |
"collapsed": true, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "calf1_mort_ratio = 0.190/0.031\ncalf2_mort_ratio = 0.085/0.031", | |
"execution_count": 6, | |
"outputs": [] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "Adult baseline mortalities and se from Langtimm et al. unpublished (2015).\n\nChanged this to a tuple, so that you can just index with the appropriate constant" | |
}, | |
{ | |
"metadata": { | |
"collapsed": false, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "adult_mort_base = 0.027417, 0.020739, 0.022355, 0.023073\n\nadult_mort_base[SW]", | |
"execution_count": 7, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": "0.023073" | |
}, | |
"metadata": {}, | |
"execution_count": 7 | |
} | |
] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "Generate survival rates and variances on logit scale" | |
}, | |
{ | |
"metadata": { | |
"collapsed": true, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "calf1_mort_base = np.array(adult_mort_base) * calf1_mort_ratio\ncalf2_mort_base = np.array(adult_mort_base) * calf2_mort_ratio\ncalf_mort_base = 1 - np.sqrt((1 - calf1_mort_base)*(1 - calf2_mort_base))\n\nwcs_protect_year = 2001", | |
"execution_count": 8, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"collapsed": false, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "calf_mort_base", | |
"execution_count": 9, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": "array([ 0.12283572, 0.09266703, 0.09995114, 0.1031908 ])" | |
}, | |
"metadata": {}, | |
"execution_count": 9 | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"collapsed": false, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "analysis_subset = (data30[(data30.year >= STARTYEAR) & (data30.year <= ENDYEAR) & (data30.age == 'Calves')]\n .replace({'area': dict(zip(regions, range(4))),\n 'habitat': dict(zip(habitats, range(3)))}))", | |
"execution_count": 10, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"collapsed": false, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "analysis_subset.head()", | |
"execution_count": 11, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/html": "<div>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr style=\"text-align: right;\">\n <th></th>\n <th>year</th>\n <th>age</th>\n <th>area</th>\n <th>habitat</th>\n <th>watercraft</th>\n <th>wcs</th>\n <th>debris</th>\n <th>cold</th>\n <th>redtide</th>\n <th>other</th>\n <th>undetermined</th>\n <th>total</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>1996</td>\n <td>Calves</td>\n <td>0</td>\n <td>0</td>\n <td>4</td>\n <td>0</td>\n <td>0</td>\n <td>3</td>\n <td>0</td>\n <td>5</td>\n <td>3</td>\n <td>15</td>\n </tr>\n <tr>\n <th>1</th>\n <td>1997</td>\n <td>Calves</td>\n <td>0</td>\n <td>0</td>\n <td>6</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>0</td>\n <td>3</td>\n <td>7</td>\n <td>16</td>\n </tr>\n <tr>\n <th>2</th>\n <td>1998</td>\n <td>Calves</td>\n <td>0</td>\n <td>0</td>\n <td>3</td>\n <td>0</td>\n <td>0</td>\n <td>6</td>\n <td>0</td>\n <td>5</td>\n <td>14</td>\n <td>28</td>\n </tr>\n <tr>\n <th>3</th>\n <td>1999</td>\n <td>Calves</td>\n <td>0</td>\n <td>0</td>\n <td>4</td>\n <td>1</td>\n <td>0</td>\n <td>2</td>\n <td>0</td>\n <td>2</td>\n <td>11</td>\n <td>20</td>\n </tr>\n <tr>\n <th>4</th>\n <td>2000</td>\n <td>Calves</td>\n <td>0</td>\n <td>0</td>\n <td>4</td>\n <td>0</td>\n <td>0</td>\n <td>5</td>\n <td>0</td>\n <td>7</td>\n <td>9</td>\n <td>25</td>\n </tr>\n </tbody>\n</table>\n</div>", | |
"text/plain": " year age area habitat watercraft wcs debris cold redtide other \\\n0 1996 Calves 0 0 4 0 0 3 0 5 \n1 1997 Calves 0 0 6 0 0 0 0 3 \n2 1998 Calves 0 0 3 0 0 6 0 5 \n3 1999 Calves 0 0 4 1 0 2 0 2 \n4 2000 Calves 0 0 4 0 0 5 0 7 \n\n undetermined total \n0 3 15 \n1 7 16 \n2 14 28 \n3 11 20 \n4 9 25 " | |
}, | |
"metadata": {}, | |
"execution_count": 11 | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"collapsed": false, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "def mortality_model(data, prior=prior0, verbose=0):\n # Jeff: simplifying by getting rid of ATL red tide, I'm not really planning to use that anymore.\n with pm.Model(verbose=verbose) as model:\n \n # Red tide effect factors\n a_mort = pm.Uniform('a_mort', lower=0, upper=1-calf_mort_base[SW])\n a = a_mort / calf_mort_base[SW]\n \n b_mort = pm.Uniform('b_mort', lower=0, upper=1-calf_mort_base[SW])\n b = b_mort / calf_mort_base[SW]\n \n # Winter effect factors for each habitat type\n sev_mort = pm.Uniform('sev_mort', lower=0, upper=1-max(calf_mort_base), \n shape=(3,4))\n \n cold_mort_upper = np.resize(1-max(calf_mort_base), (3,4))\n cold_mort_upper[HIGH] = 0.0001\n cold_mort = pm.Uniform('cold_mort', lower=0, upper=cold_mort_upper, shape=(3,4))\n \n norm_mort_upper = np.resize(1-max(calf_mort_base), (3,4))\n norm_mort_upper[HIGH] = 0.0001\n norm_mort = pm.Uniform('norm_mort', lower=0, upper=norm_mort_upper, shape=(3,4))\n \n sev = sev_mort / np.resize(calf_mort_base, (3,4))\n cold = cold_mort / np.resize(calf_mort_base, (3,4))\n norm = norm_mort / np.resize(calf_mort_base, (3,4))\n \n p = [pm.Dirichlet('p_{}'.format(a), t) for t,a in zip(prior, regions)]\n \n π = [pm.Dirichlet('π_{}'.format(a), np.ones(k)) for k,a in zip(ncauses, regions)]\n \n for (area, year, habitat), data in data.groupby(['area', 'year', 'habitat']):\n \n undetermined = data.undetermined.values\n\n Z = (data[causes].drop('redtide', axis=1).values if area==USJ else data[causes].values).squeeze()\n \n # Only moderately unusual red tide (no cold effects)\n if ((year in tide_years0) and (area==SW) and (habitat==HIGH)):\n \n # theta varies from pi based on red tide UME \n θ = tt.set_subtensor(π[area][4], π[area][4] + a) / (1+a) \n η = p[area]\n\n # Moderately unusual red tide and normal cold\n elif ((year in tide_years0) and (area==SW)):\n \n no = norm[habitat, area]\n\n # theta varies from pi based on winter severity and on red tide UME \n θ = tt.set_subtensor(π[area][4], π[area][4] + a) \n θ = tt.set_subtensor(θ[3], θ[3] + no) / (1 + a + no) \n\n # eta varies from p based on winter severity\n η = tt.set_subtensor(p[area][3], p[area][3] + no) / (1 + no)\n\n\n # Intense unusual red tide and cold year\n elif ((year in tide_years_intense) and (area==SW) and (year in cold_years[area])):\n \n co = cold[habitat, area]\n \n # theta varies from pi based on winter severity and on red tide UME \n θ = tt.set_subtensor(π[area][4], π[area][4] + b) \n θ = tt.set_subtensor(θ[3], θ[3] + co) / (1 + b + co) \n\n # eta varies from p based on winter severity\n η = tt.set_subtensor(p[area][3], p[area][3] + co) / (1 + co)\n\n\n # Intense unusual red tide and severe cold year\n elif ((year in tide_years_intense) and (area==SW) and (year in severe_years[area])):\n\n sv = sev[habitat, area]\n \n # theta varies from pi based on red tide UME \n θ = tt.set_subtensor(π[area][4], π[area][4] + b) \n θ = tt.set_subtensor(θ[3], θ[3] + sv) / (1 + b + sv) \n\n # eta varies from p based on winter severity\n η = tt.set_subtensor(p[area][3], p[area][3] + sv) / (1 + sv)\n\n\n # Intense unusual red tide only\n elif ((year in tide_years_intense) and (area==SW) and (habitat==HIGH)):\n \n # theta varies from pi based on red tide UME \n θ = tt.set_subtensor(π[area][4], π[area][4] + b) / (1+b) \n \n η = p[area]\n\n # Intense unusual red tide and normal cold\n elif (year in tide_years_intense) and (area==SW):\n \n no = norm[habitat, area]\n\n # theta varies from pi based on winter severity and on red tide UME \n θ = tt.set_subtensor(π[area][4], π[area][4] + b) \n θ = tt.set_subtensor(θ[3], θ[3] + no) / (1 + b + no) \n\n # eta varies from p based on winter severity\n η = tt.set_subtensor(p[area][3], p[area][3] + no) / (1 + no)\n \n\n # Severe cold year\n elif (year in severe_years[area]):\n \n \n sv = sev[habitat, area]\n \n # theta varies from pi based on winter severity \n θ = tt.set_subtensor(π[area][3], π[area][3] + sv) / (1 + sv)\n\n # eta varies from p based on winter severity\n η = tt.set_subtensor(p[area][3], p[area][3] + sv) / (1 + sv)\n \n\n # Cold year, low or medium habitat quality\n elif (year in cold_years[area]) and (habitat<HIGH):\n \n \n co = cold[habitat, area]\n \n # theta varies from pi based on winter severity \n θ = tt.set_subtensor(π[area][3], π[area][3] + co) / (1 + co)\n\n # eta varies from p based on winter severity\n η = tt.set_subtensor(p[area][3], p[area][3] + co) / (1 + co)\n \n\n # Normal cold year, low or medium habitat quality\n elif (habitat<HIGH):\n \n \n no = norm[habitat, area]\n\n # theta varies from pi based on winter severity \n θ = tt.set_subtensor(π[area][3], π[area][3] + no) / (1 + no) \n\n # eta varies from p based on winter severity\n η = tt.set_subtensor(p[area][3], p[area][3] + no) / (1 + no)\n \n\n # Normal year, high habitat quality\n else: \n # No adjustment to proportions\n θ = π[area]\n η = p[area]\n \n tt.printing.Print('θ')(θ)\n if undetermined:\n# U = pm.Multinomial('U_{}_{}_{}'.format(area, year, habitat), n=undetermined, p=η, shape=ncauses[area])\n U = srng.multinomial(n=undetermined, pvals=η).squeeze()\n \n deaths = Z + U\n \n else:\n \n deaths = Z\n \n if Z.sum() or undetermined:\n \n pm.Potential('X_like_{}_{}_{}'.format(area, year, habitat), \n pm.Multinomial.dist(n=deaths.sum(), p=θ).logp(deaths))\n \n \n return(model)", | |
"execution_count": 24, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"scrolled": false, | |
"collapsed": false, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "calf_model = mortality_model(data=analysis_subset, prior=prior0, verbose=1)", | |
"execution_count": 25, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "Applied interval-transform to a_mort and added transformed a_mort_interval to model.\nApplied interval-transform to b_mort and added transformed b_mort_interval to model.\nApplied interval-transform to sev_mort and added transformed sev_mort_interval to model.\nApplied interval-transform to cold_mort and added transformed cold_mort_interval to model.\nApplied interval-transform to norm_mort and added transformed norm_mort_interval to model.\nApplied stickbreaking-transform to p_ATL and added transformed p_ATL_stickbreaking to model.\nApplied stickbreaking-transform to p_USJ and added transformed p_USJ_stickbreaking to model.\nApplied stickbreaking-transform to p_NW and added transformed p_NW_stickbreaking to model.\nApplied stickbreaking-transform to p_SW and added transformed p_SW_stickbreaking to model.\nApplied stickbreaking-transform to π_ATL and added transformed π_ATL_stickbreaking to model.\nApplied stickbreaking-transform to π_USJ and added transformed π_USJ_stickbreaking to model.\nApplied stickbreaking-transform to π_NW and added transformed π_NW_stickbreaking to model.\nApplied stickbreaking-transform to π_SW and added transformed π_SW_stickbreaking to model.\n", | |
"name": "stdout" | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"collapsed": false, | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "with calf_model:\n \n trace = pm.sample(5000, step=pm.Metropolis())\n #means, sds, elbo = pm.variational.advi(n=50000)", | |
"execution_count": 26, | |
"outputs": [ | |
{ | |
"output_type": "error", | |
"ename": "MissingInputError", | |
"evalue": "An input of the graph, used to compute Elemwise{exp,no_inplace}(cold_mort_interval_), was not provided and not given a value.Use the Theano flag exception_verbosity='high',for more information on this error.", | |
"traceback": [ | |
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[0;31mMissingInputError\u001b[0m Traceback (most recent call last)", | |
"\u001b[0;32m<ipython-input-26-4cf7dc9675fe>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;32mwith\u001b[0m \u001b[0mcalf_model\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mtrace\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msample\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m5000\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstep\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mpm\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mMetropolis\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0;31m#means, sds, elbo = pm.variational.advi(n=50000)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/Users/fonnescj/Repositories/pymc3/pymc3/step_methods/arraystep.py\u001b[0m in \u001b[0;36m__new__\u001b[0;34m(cls, *args, **kwargs)\u001b[0m\n\u001b[1;32m 56\u001b[0m \u001b[0;31m# If we don't return the instance we have to manually\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 57\u001b[0m \u001b[0;31m# call __init__\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 58\u001b[0;31m \u001b[0mstep\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__init__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mvar\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m*\u001b[0m\u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 59\u001b[0m \u001b[0;31m# Hack for creating the class correctly when unpickling.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 60\u001b[0m \u001b[0mstep\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__newargs\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mvar\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m)\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0margs\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkwargs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/Users/fonnescj/Repositories/pymc3/pymc3/step_methods/metropolis.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, vars, S, proposal_dist, scaling, tune, tune_interval, model, **kwargs)\u001b[0m\n\u001b[1;32m 99\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 100\u001b[0m \u001b[0mshared\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmake_shared_replacements\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvars\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmodel\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 101\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdelta_logp\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdelta_logp\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlogpt\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvars\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mshared\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 102\u001b[0m \u001b[0msuper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mMetropolis\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__init__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvars\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mshared\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 103\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/Users/fonnescj/Repositories/pymc3/pymc3/step_methods/metropolis.py\u001b[0m in \u001b[0;36mdelta_logp\u001b[0;34m(logp, vars, shared)\u001b[0m\n\u001b[1;32m 294\u001b[0m \u001b[0mlogp1\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mCallableTensor\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlogp0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minarray1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 295\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 296\u001b[0;31m \u001b[0mf\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtheano\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfunction\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0minarray1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minarray0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mlogp1\u001b[0m \u001b[0;34m-\u001b[0m \u001b[0mlogp0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 297\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtrust_input\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 298\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mf\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/Users/fonnescj/anaconda3/lib/python3.5/site-packages/theano/compile/function.py\u001b[0m in \u001b[0;36mfunction\u001b[0;34m(inputs, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input)\u001b[0m\n\u001b[1;32m 320\u001b[0m \u001b[0mon_unused_input\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mon_unused_input\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 321\u001b[0m \u001b[0mprofile\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mprofile\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 322\u001b[0;31m output_keys=output_keys)\n\u001b[0m\u001b[1;32m 323\u001b[0m \u001b[0;31m# We need to add the flag check_aliased inputs if we have any mutable or\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 324\u001b[0m \u001b[0;31m# borrowed used defined inputs\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/Users/fonnescj/anaconda3/lib/python3.5/site-packages/theano/compile/pfunc.py\u001b[0m in \u001b[0;36mpfunc\u001b[0;34m(params, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input, output_keys)\u001b[0m\n\u001b[1;32m 478\u001b[0m \u001b[0maccept_inplace\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0maccept_inplace\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 479\u001b[0m \u001b[0mprofile\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mprofile\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mon_unused_input\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mon_unused_input\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 480\u001b[0;31m output_keys=output_keys)\n\u001b[0m\u001b[1;32m 481\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 482\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/Users/fonnescj/anaconda3/lib/python3.5/site-packages/theano/compile/function_module.py\u001b[0m in \u001b[0;36morig_function\u001b[0;34m(inputs, outputs, mode, accept_inplace, name, profile, on_unused_input, output_keys)\u001b[0m\n\u001b[1;32m 1821\u001b[0m \u001b[0mprofile\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mprofile\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1822\u001b[0m \u001b[0mon_unused_input\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mon_unused_input\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 1823\u001b[0;31m \u001b[0moutput_keys\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0moutput_keys\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcreate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1824\u001b[0m defaults)\n\u001b[1;32m 1825\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/Users/fonnescj/anaconda3/lib/python3.5/site-packages/theano/compile/function_module.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, inputs, outputs, mode, accept_inplace, function_builder, profile, on_unused_input, fgraph, output_keys)\u001b[0m\n\u001b[1;32m 1473\u001b[0m \u001b[0;31m# OUTPUT VARIABLES)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1474\u001b[0m fgraph, additional_outputs = std_fgraph(inputs, outputs,\n\u001b[0;32m-> 1475\u001b[0;31m accept_inplace)\n\u001b[0m\u001b[1;32m 1476\u001b[0m \u001b[0mfgraph\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprofile\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mprofile\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1477\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/Users/fonnescj/anaconda3/lib/python3.5/site-packages/theano/compile/function_module.py\u001b[0m in \u001b[0;36mstd_fgraph\u001b[0;34m(input_specs, output_specs, accept_inplace)\u001b[0m\n\u001b[1;32m 175\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 176\u001b[0m fgraph = gof.fg.FunctionGraph(orig_inputs, orig_outputs,\n\u001b[0;32m--> 177\u001b[0;31m update_mapping=update_mapping)\n\u001b[0m\u001b[1;32m 178\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 179\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mnode\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mfgraph\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply_nodes\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/Users/fonnescj/anaconda3/lib/python3.5/site-packages/theano/gof/fg.py\u001b[0m in \u001b[0;36m__init__\u001b[0;34m(self, inputs, outputs, features, clone, update_mapping)\u001b[0m\n\u001b[1;32m 180\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 181\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0moutput\u001b[0m \u001b[0;32min\u001b[0m \u001b[0moutputs\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 182\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__import_r__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moutput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreason\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\"init\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 183\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moutput\u001b[0m \u001b[0;32min\u001b[0m \u001b[0menumerate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moutputs\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 184\u001b[0m \u001b[0moutput\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mclients\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mappend\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'output'\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mi\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/Users/fonnescj/anaconda3/lib/python3.5/site-packages/theano/gof/fg.py\u001b[0m in \u001b[0;36m__import_r__\u001b[0;34m(self, variable, reason)\u001b[0m\n\u001b[1;32m 369\u001b[0m \u001b[0;31m# Imports the owners of the variables\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 370\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mvariable\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mowner\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mvariable\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mowner\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply_nodes\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 371\u001b[0;31m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__import__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvariable\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mowner\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mreason\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mreason\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 372\u001b[0m if (variable.owner is None and\n\u001b[1;32m 373\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0misinstance\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mvariable\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mgraph\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mConstant\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mand\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;32m/Users/fonnescj/anaconda3/lib/python3.5/site-packages/theano/gof/fg.py\u001b[0m in \u001b[0;36m__import__\u001b[0;34m(self, apply_node, check, reason)\u001b[0m\n\u001b[1;32m 411\u001b[0m \u001b[0;34m\"for more information on this error.\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 412\u001b[0m % str(node)),\n\u001b[0;32m--> 413\u001b[0;31m variable=r)\n\u001b[0m\u001b[1;32m 414\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 415\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mnode\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mnew_nodes\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", | |
"\u001b[0;31mMissingInputError\u001b[0m: An input of the graph, used to compute Elemwise{exp,no_inplace}(cold_mort_interval_), was not provided and not given a value.Use the Theano flag exception_verbosity='high',for more information on this error." | |
] | |
} | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3", | |
"language": "python" | |
}, | |
"language_info": { | |
"file_extension": ".py", | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"pygments_lexer": "ipython3", | |
"name": "python", | |
"mimetype": "text/x-python", | |
"nbconvert_exporter": "python", | |
"version": "3.5.1" | |
}, | |
"gist": { | |
"id": "", | |
"data": { | |
"description": "Manatee Mortality.ipynb", | |
"public": true | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment