Skip to content

Commit

Permalink
mcmc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bblais committed Mar 28, 2024
1 parent 0e5a29e commit ead8ad5
Show file tree
Hide file tree
Showing 74 changed files with 12,598 additions and 2,572 deletions.
87 changes: 62 additions & 25 deletions 00_core.ipynb

Large diffs are not rendered by default.

135 changes: 88 additions & 47 deletions 00_core.py

Large diffs are not rendered by default.

54 changes: 28 additions & 26 deletions 01_mcmc.ipynb

Large diffs are not rendered by default.

74 changes: 40 additions & 34 deletions 01_mcmc.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env python
# coding: utf-8

# In[1]:
# In[ ]:


#| default_exp mcmc


# # MCMC (using emcee package)

# In[2]:
# In[ ]:


#| export
Expand All @@ -24,7 +24,7 @@

# ## Useful Functions

# In[3]:
# In[ ]:


#| export
Expand Down Expand Up @@ -187,7 +187,7 @@ def dicttable(D):

# ## Distributions -- Defined for Speed

# In[4]:
# In[ ]:


#| export
Expand Down Expand Up @@ -274,7 +274,7 @@ def loglognormalpdf(x,mn,sig):

# ## Distribution Classes

# In[5]:
# In[ ]:


#| export
Expand Down Expand Up @@ -420,7 +420,7 @@ def __str__(self):

# ## Emcee functions

# In[6]:
# In[ ]:


#| export
Expand All @@ -431,7 +431,8 @@ def _lnprior(x):
return _lnprior


# In[17]:

# In[ ]:


#| export
Expand Down Expand Up @@ -1079,7 +1080,7 @@ def draw(self):



# In[18]:
# In[ ]:


#| export
Expand Down Expand Up @@ -1176,18 +1177,19 @@ def apply_regression(self,verbose=True):
self.model_results=model_results



# # A linear growth example
#
# Data from [http://www.seattlecentral.edu/qelp/sets/009/009.html](http://www.seattlecentral.edu/qelp/sets/009/009.html)
#

# In[19]:
# In[ ]:


from pyndamics3 import Simulation


# In[20]:
# In[ ]:


t=np.array([7,14,21,28,35,42,49,56,63,70,77,84],float)
Expand All @@ -1200,7 +1202,7 @@ def apply_regression(self,verbose=True):

# ## Run an initial (and bad) simulation

# In[21]:
# In[ ]:


sim=Simulation()
Expand All @@ -1212,9 +1214,13 @@ def apply_regression(self,verbose=True):

# ## Fitting $a$

# model=MCMCModel(sim,a=Uniform(-10,10))
# In[ ]:


# In[23]:
model=MCMCModel(sim,a=Uniform(-10,10))


# In[ ]:


result=model.run_mcmc(500)
Expand All @@ -1223,46 +1229,46 @@ def apply_regression(self,verbose=True):

# Although this looked converged, you might have situations where you want to repeat the mcmc-resample loop (i.e. resample parameters from the 95% CI of the current samples)

# In[26]:
# In[ ]:


result


# In[27]:
# In[ ]:


model.run_mcmc(100,repeat=3)
model.plot_chains()


# In[28]:
# In[ ]:


model.summary()


# In[30]:
# In[ ]:


model.best_estimates()


# In[31]:
# In[ ]:


sim.run(0,90)


# In[32]:
# In[ ]:


model.plot_distributions()


# ## Fitting with $a$ and the initial $h$

# In[33]:
# In[ ]:


model=MCMCModel(sim,
Expand All @@ -1271,34 +1277,34 @@ def apply_regression(self,verbose=True):
)


# In[34]:
# In[ ]:


model.run_mcmc(500,repeat=2)
model.plot_chains()


# In[35]:
# In[ ]:


sim.run(0,90)


# In[36]:
# In[ ]:


model.plot_distributions()


# In[37]:
# In[ ]:


model.plot_many(0,90,'h')


# # Logistic with the Same Data

# In[38]:
# In[ ]:


t=np.array([7,14,21,28,35,42,49,56,63,70,77,84],float)
Expand All @@ -1311,7 +1317,7 @@ def apply_regression(self,verbose=True):
sim.run(0,90)


# In[47]:
# In[ ]:


model=MCMCModel(sim,
Expand All @@ -1321,44 +1327,44 @@ def apply_regression(self,verbose=True):
)


# In[48]:
# In[ ]:


model.run_mcmc(500,repeat=3)
model.plot_chains()


# In[49]:
# In[ ]:


model.best_estimates()


# In[50]:
# In[ ]:


sim.run(0,90)


# In[51]:
# In[ ]:


model.plot_distributions()


# In[52]:
# In[ ]:


model.triangle_plot()


# In[53]:
# In[ ]:


model.plot_many(0,90,'h')


# In[54]:
# In[ ]:


sim.noplots=True # turn off the simulation plots
Expand All @@ -1373,7 +1379,7 @@ def apply_regression(self,verbose=True):
saved_h=np.array(saved_h)


# In[55]:
# In[ ]:


med=np.percentile(saved_h,50,axis=0)
Expand Down
60 changes: 30 additions & 30 deletions 02_tutorial.zombies.ipynb

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions 03_fit.ipynb

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions 04_stochastic.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions 05_chemical_equations.ipynb

Large diffs are not rendered by default.

622 changes: 622 additions & 0 deletions 06_stability.ipynb

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions 099_01_debug_stochastic_mcmc.ipynb

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions 099_02_debug_stochastic.ipynb

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions 099_debug.ipynb

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Pyndamics3
================
# Pyndamics3


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

Expand Down Expand Up @@ -27,6 +27,6 @@ sim.params(a=1,K=50)
sim.run(50)
```

![](index_files/figure-gfm/cell-3-output-1.png)
![](index_files/figure-commonmark/cell-3-output-1.png)

<Figure size 432x288 with 0 Axes>
Loading

0 comments on commit ead8ad5

Please sign in to comment.