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
""" | |
pip install outlines torch==2.4.0 transformers accelerate typing-extensions pillow pdf2image rich requests | |
may need to install tkinter: https://stackoverflow.com/questions/25905540/importerror-no-module-named-tkinter | |
sudo apt-get install poppler-utils | |
""" | |
from enum import Enum | |
from io import BytesIO |
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
--- | |
title: "Appendix: Responses to improving conditions for outbreak modelling" | |
date: "2024" | |
output: html_document | |
--- | |
```{r setup, include=FALSE} | |
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE) | |
library(knitr) | |
library(googlesheets4) |
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
# Example code for simulation recovery of infection dynamics from deaths for COVID ----------------------------------------- | |
# Load libraries: | |
# install.packages("EpiNow2", repos = "https://epiforecasts.r-universe.dev") | |
library(EpiNow2) | |
# Simulate data and delays ----------------------------------------- | |
# Simulate infections with a sharp drop |
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
#' Aggregate daily forecasts to weekly forecasts | |
#' | |
#' Aggregate daily case forecasts from regional_epinow2 to weekly forecasts. | |
#' | |
#' @param inf List output from `EpiNow2::regional_epinow()`. No default. | |
#' @param week_start Week start day. Default is 1 (Monday). | |
#' @param summary_quantiles Quantiles for forecast summary. Default is median, plus upper and lower bound for 20\%, 50\% and 90\% forecasts. | |
#' @importFrom dplyr group_by summarise filter mutate select case_when contains | |
#' @importFrom tidyr pivot_wider | |
#' @importFrom purrr map_df |
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
functions { | |
vector convolve(vector a, vector b) { | |
int na = num_elements(a); // Vector lengths | |
int nb = num_elements(b); | |
int n_zero_a = nb - 1; // Zero padding lengths | |
int n_zero_b = na - 1; | |
vector[nb] b_rev = reverse(b); // The reversed b vector | |
vector[na + n_zero_a] a_pad; // Instantiate zero padded vectors |
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
import polars as pl | |
# Making data frames ------------------------------------------ | |
# with dictionary | |
df = pl.DataFrame({ | |
'name': ['foo', 'bar', 'baz'], | |
'bar': [0, 1, 2], | |
'qux': [0.0, 1.0, 2.0] | |
}) |
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
wd <- system("echo $(git rev-parse --show-toplevel)", intern = TRUE) | |
setwd(wd) | |
source(paste0(wd, "/influenza/scripts/depends.R")) | |
output_dir <- fs::path(paste0(wd, "/influenza/papers/univariate/outputs")) | |
# nhs_data path for getting population sizes: | |
nhs_data_path <- "" # Removed path to influenza data + population catchments per trust |
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
# Purpose: This is just a play model to think about time spent on large and big grants/opportunities and | |
# overall likelihood of a successful result (undefined, just general feel). | |
# 2080 is the hours in a year if working 40 hours (because everyone does that...) | |
using JuMP | |
using Ipopt | |
model = Model(Ipopt.Optimizer) | |
p1 = .05 # Probability of winning grant 1 | |
sx1 = .4 # Probability of successful work (class 1) |
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
##' Get estimates shown at \url{https://epiforecasts.io/covid} for all times | |
##' | |
##' Nowcasts at \url{https://epiforecasts.covid} and the related github repository at | |
##' \url{https://github.com/epiforecasts/covid-rt-estimates} only cover the last 3 | |
##' months. This function downloads all available estimates and applies a median | |
##' average to the provided quantiles to provide an estimate of a time series | |
##' covering all times available | |
##' | |
##' @param dataset character; data set corresponding to directories at | |
##' \url{https://github.com/epiforecasts/covid-rt-estimates}. Default is |
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
library("gh") | |
library("vroom") | |
owner <- "epiforecasts" | |
repo <- "covid-rt-estimates" | |
path <- "subnational/united-kingdom-local/cases/summary/rt.csv" | |
rt_commits <- | |
gh("/repos/{owner}/{repo}/commits?path={path}", | |
owner = owner, |
NewerOlder