Skip to content

Instantly share code, notes, and snippets.

View nmatzke's full-sized avatar

Nicholas J. Matzke nmatzke

View GitHub Profile
require("ape")
# print tree in hierarchical format
#######################################################
# prt
#######################################################
#' Print tree in table format
#'
#' Learning and using APE's tree structure can be difficult and confusing because much of the information is
#' implicit. This function prints the entire
@nmatzke
nmatzke / _ex_Eulers_WORKS.jl
Created April 18, 2019 02:31
Revising Chris Rackauckas's "exp_euler_test.jl" from Julia 0.6 so it works in Julia 1.1
########################################################
# Revising Chris Rackauckas's "exp_euler_test.jl" from
# Julia 0.6 so it works in Julia 1.1
########################################################
#
# Original 0.6 code from:
#
# ChrisRackauckas/exp_euler_test.jl
# https://gist.github.com/ChrisRackauckas/cf91f4575b0587a45c72620384612b82
@nmatzke
nmatzke / BDQ.jl
Created April 22, 2019 02:32
BDQ
import Pkg
using Pkg # for Pkg.add, Pkg.PackageSpec
using DifferentialEquations
using Plots
using BenchmarkTools # for @benchmark
using LSODA # for lsoda()
#Pkg.resolve()
using Sundials # for CVODE_BDF() e.g.
@nmatzke
nmatzke / BDQ_v5.jl
Created April 22, 2019 23:06
BDQ v5 w help from Chris
using DifferentialEquations
using BenchmarkTools # for @benchmark
using LSODA # for lsoda()
using Sundials # for CVODE_BDF()
# State-dependent birth-death process:
# Problem setup
n = 500 # Number of states
two = 2.0 # Constant (but missing in some published equations)
@nmatzke
nmatzke / BDQ_time_results.jl
Last active April 24, 2019 04:52
time results
# Time results posted to:
# https://gist.github.com/nmatzke/34ba6b3f8b548af92724bcb3f41bbf3d
#
# ODE problem setup here:
# https://gist.github.com/nmatzke/b6332845747d7452b6e3b45564f460e8
@benchmark sol_CVODE = solve(prob, CVODE_BDF(linear_solver=:GMRES), dense=false, save_everystep=false, save_end=true, save_start=true)
# memory estimate: 2.72 GiB
# allocs estimate: 5711652
# --------------
@nmatzke
nmatzke / exp_example.jl
Created February 27, 2020 01:03
Takes 4.6 seconds for 2000 exp operations
using LinearAlgebra
tmpstr = "Any[2 9 0.08; 2 10 0.15; 2 11 0.22; 2 12 0.29; 2 13 0.36; 2 14 0.43; 3 9 0.02; 3 15 0.16; 3 16 0.23; 3 17 0.3; 3 18 0.37; 3 19 0.44; 4 10 0.03; 4 15 0.1; 4 20 0.24; 4 21 0.31; 4 22 0.38; 4 23 0.45; 5 11 0.04; 5 16 0.11; 5 20 0.18; 5 24 0.32; 5 25 0.39; 5 26 0.46; 6 12 0.05; 6 17 0.12; 6 21 0.19; 6 24 0.26; 6 27 0.4; 6 28 0.47; 7 13 0.06; 7 18 0.13; 7 22 0.2; 7 25 0.27; 7 27 0.34; 7 29 0.48; 8 14 0.07; 8 19 0.14; 8 23 0.21; 8 26 0.28; 8 28 0.35; 8 29 0.42; 9 30 0.31; 9 31 0.45; 9 32 0.59; 9 33 0.73; 9 34 0.87; 10 30 0.18; 10 35 0.45999999999999996; 10 36 0.6; 10 37 0.74; 10 38 0.88; 11 31 0.19; 11 35 0.32999999999999996; 11 39 0.61; 11 40 0.75; 11 41 0.89; 12 32 0.2; 12 36 0.33999999999999997; 12 39 0.48; 12 42 0.76; 12 43 0.8999999999999999; 13 33 0.21000000000000002; 13 37 0.35; 13 40 0.49; 13 42 0.63; 13 44 0.9099999999999999; 14 34 0.22000000000000003; 14 38 0.36; 14 41 0.5; 14 43 0.6399999999999999; 14 44 0.78; 15 30 0.05; 15 45 0.47; 15 46 0.61; 15 47 0.75; 15 48 0.89; 16 3
@nmatzke
nmatzke / lab04_exercise_v5.R
Last active March 30, 2020 07:28
BIOSCI220: Lab 4 exercise and questions
# Module 2: "Model-based Inference"
# https://canvas.auckland.ac.nz/courses/48087/pages/module-2-model-based-inference?module_item_id=747842
# You can find the Lab 4 Worksheet questions at:
#
# Canvas -> BIOSCI 220 -> Quizzes -> Lab 4 Worksheet
# The below Lab 4 code is posted at:
#
@nmatzke
nmatzke / week_05_exercise_v3.R
Last active April 6, 2020 09:46
BIOSCI220: Week 5 lab exercise
#######################################################
# BIOSCI220: Week 5 Lab Exercise: Modelling epidemics
#######################################################
#######################################################
# Setup
#######################################################
#
@nmatzke
nmatzke / week_06_Discussion_example_option2.R
Last active May 2, 2020 06:52
week_06_Discussion_example_option2.R
#######################################################
# DISCUSSION ASSIGNMENT: FIT R0s FOR A COUNTRY OF INTEREST
#
# For the final part of your assignment, you will
# pretend you are an epidemiologist writing a report
# on the spread of Covid-19 in a particular country,
# and commenting on what you can tell about the effectiveness
# of interventions at this point.
#
@nmatzke
nmatzke / week_06_Discussion_example_option1_v2.R
Last active April 30, 2020 22:30
week_06_Discussion_example_option1_v2.R
#######################################################
# DISCUSSION ASSIGNMENT: FIT R0s FOR A COUNTRY OF INTEREST
#
# For the final part of your assignment, you will
# pretend you are an epidemiologist writing a report
# on the spread of Covid-19 in a particular country,
# and commenting on what you can tell about the effectiveness
# of interventions at this point.
#