This repository contains two examples demonstrating how to use the R-POMP package for parameter optimization on Azure Batch. The examples cover trajectory mapping and iterative filtering, each detailed in its own Jupyter notebook.
Both examples share the ./app directory for storing scripts and assets. The necessary Azure resources are listed in the Prerequisites section below. For more details, refer to the documentation and notebook overviews provided below.
- Python 3.12
- Ideally, you already have a Python environment set up or are working on a machine with a single Python environment. If not, I would recommend using a GitHub Codespace built from this repository's devcontainer.)
- An azure resource group
- An azure batch account
- A default compute pool named
default
- A default compute pool named
- A storage account w/ storage account container named
output - An azure container registry
- A user assigned managed identity
- This will be used by the batch compute pool to access azure resources.
- This identity should be assigned
STORAGE_BLOB_DATA_OWNERon the azure storage account - This identity should be assigned
ACR_PULLon the azure container registry
- An azure batch account
- Access to the resources via your Entra Id account.
AZURE_BATCH_ACCOUNT_CONTRIBUTORon the azure batch accountACR_PUSHon the azure container registrySTORAGE_BLOB_DATA_OWNERon the storage account
- Using these newly created resources, replace these values in this repository:
<subscriptionId>,<resourceGroupName>,<batchAccountName>,<region>,<storageAccountName>,<azureContainerRegistryName>,<region>
![]() |
|---|
| Reference Diagram for Azure Resources |
Notebook: r-pomp-trajectory-mapping.ipynb
Goal: The notebook aims to estimate the parameters of a Verhulst-Pearl population dynamics model using trajectory mapping. Specifically, by optimizing the negative log-likelihood of the model using the subplex algorithm. The focus is on determining the carrying capacity (K) and initial population size (N_0) that best fit the observed data, using Azure Batch to distribute and parallelize the computational workload. Code in this notebook is based off of Trajectory Mapping by Aaron A. King, retrofit to leverage azure batch.
Model: The model is based on the Verhulst-Pearl (logistic growth) equation, with both stochastic and deterministic components:
- Stochastic Process: The population dynamics are simulated using a stochastic differential equation (
vpstepC), which introduces random fluctuations around the logistic growth curve. - Deterministic Skeleton: A deterministic version of the model is also defined using a vector field, which describes the central tendency of the population without stochastic noise.
- Objective Function: The notebook uses
traj_objfunto create an objective function that quantifies the mismatch between the model's predictions and the observed data, focusing on the parametersKandN_0.
Overview of Steps:
- Generating the Objective Function: The
generate_ofun.Rscript creates a POMP object for the Verhulst-Pearl model, incorporating both the stochastic process and deterministic skeleton. An objective function (ofun) is generated, which will be used to estimate the parameters by minimizing the negative log-likelihood. This function is saved asofun.rds. - Running Parameter Optimization: The
run_optimization.Rscript loads the saved objective function and uses thesubplexalgorithm to optimizeKandN_0. The optimization is run for different initial values of these parameters, and the results are saved as.RDatafiles. - Azure Batch Setup and Execution: The notebook configures and sets up an Azure Batch environment, uploads the necessary files, and creates a Batch job. Multiple tasks are dispatched, each running the
run_optimization.Rscript with different initial values ofKandN_0, allowing the parameter space to be explored in parallel. - Downloading and Analyzing Results: After the Batch tasks complete, the notebook downloads the
.RDatafiles containing the optimized parameters and their corresponding negative log-likelihoods. These results are aggregated and analyzed to identify the parameter values that best fit the data. - Visualization: The notebook creates visualizations of the aggregated simulation outcomes, giving insights to the parameter estimation.
Notebook: r-pomp-iterative-filtering.ipynb
Goal: The notebook aims to estimate the parameters of a Verhulst-Pearl population dynamics model using the iterated filtering (mif2) algorithm from the r-pomp package, leveraging Azure Batch for distributed computation. The objective is to maximize the likelihood of observed data by refining parameter estimates for the Verhulst-Pearl (logistic growth) model with stochastic components. Code in this notebook based off of Maximizing liklihood by Iterative Filtering by Aaron A. King, retrofit to leverage azure batch.
Model: The POMP object in this notebook is generated using a stochastic version of the Verhulst-Pearl model, which simulates population dynamics over time. This model incorporates logistic growth with random noise, defined by a stochastic differential equationin the vpstepC C snippet. Key parameters include the growth rate (r), carrying capacity (K), noise (sigma), and initial population size (N_0).
Overview of Steps:
- Parameter Guess Generation: The notebook begins by generating initial parameter guesses using a Sobol sequence, which explores a wide range of potential values for the model parameters (r, K, sigma, N_0).
- Iterated Filtering (mif2): For each parameter guess, the mif2 algorithm refines the parameter estimates by maximizing the likelihood of the observed data, simulating the stochastic dynamics of the Verhulst-Pearl model. Results from these optimizations are saved as .RData files.
- Refinement via Particle Filtering: After mif2, the notebook uses particle filtering (pfilter) to further refine the estimates and compute log-likelihood values, ensuring the parameters best fit the observed data.
- Azure Batch Execution: The notebook distributes the computations across Azure Batch, creating tasks that run mif2 and pfilter in parallel for each parameter guess. This enables efficient scaling for larger computational tasks.
- Result Analysis: Upon completion of the batch tasks, the notebook downloads and analyzes the results, generating trace plots to visualize parameter convergence and pair plots to explore relationships between the parameters.
