This file contains hidden or 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 DifferentialEquations as DE | |
| using DataFrames | |
| using Distributions | |
| using LinearAlgebra, Statistics | |
| using SciMLSensitivity | |
| using Optimization, OptimizationLBFGSB | |
| using Mooncake | |
| # ------------------------------------------------------------ |
This file contains hidden or 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
| # paper at https://doi.org/10.1016/j.ejor.2005.10.060 | |
| using Catlab, AlgebraicPetri | |
| using JuMP, HiGHS | |
| to_graphviz(Presentation(LabelledPetriNet)) | |
| pn = @acset LabelledPetriNet begin | |
| S=6 | |
| sname=Symbol.("p" .* string.(1:6)) |
This file contains hidden or 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
| using StochasticAD, Distributions, StaticArrays, Plots | |
| using Zygote, ForwardDiff | |
| # map rates to probabilities | |
| function rate_to_proportion(r, t) | |
| 1-exp(-r*t) | |
| end | |
| # dynamic part of SIR model | |
| function sir_dyn_mod(x, u0, p, δt) |
This file contains hidden or 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
| rm(list=ls());gc() | |
| ad <- function(x,diff = c(1,1)) { | |
| ## create class "ad" object. diff[1] is length of grad | |
| ## diff[2] is element of grad to set to 1. | |
| grad <- rep(0,diff[1]) | |
| if (diff[2]>0 && diff[2]<=diff[1]) grad[diff[2]] <- 1 | |
| attr(x,"grad") <- grad | |
| class(x) <- "ad" | |
| x |
This file contains hidden or 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
| using Distributions | |
| using ForwardDiff | |
| using Optim | |
| using LineSearches # https://github.com/JuliaNLSolvers/Optim.jl/issues/713 | |
| # logdet | |
| using LinearAlgebra | |
| # get the data |
This file contains hidden or 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
| using Random, Distributions | |
| using LinearAlgebra | |
| using Statistics | |
| using Plots | |
| using JuMP, Ipopt | |
| using RCall | |
| # initial fixup and optional (not here) scaling https://github.com/cran/mgcv/blob/a534170c82ce06ccd8d76b1a7d472c50a2d7bbd2/R/smooth.r#L1602 | |
| # scaling here: https://github.com/cran/mgcv/blob/a534170c82ce06ccd8d76b1a7d472c50a2d7bbd2/R/smooth.r#L3757 | |
| function penalty_cr(D,B) |
This file contains hidden or 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
| using JuMP | |
| using HiGHS | |
| using LinearAlgebra | |
| using RCall | |
| using Plots | |
| # example from pcls help, see https://stat.ethz.ch/R-manual/R-devel/library/mgcv/html/pcls.html | |
| R""" | |
| library(mgcv) |
This file contains hidden or 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
| #include <vector> | |
| #include <list> | |
| #include <iostream> | |
| #include <algorithm> | |
| // if we needed containers that took > 2 template args (set?) we could use variadic templates. | |
| template<typename T, template<typename, typename> class C> | |
| struct MyVariable { | |
| std::vector<C<T, std::allocator<T>>> values; | |
This file contains hidden or 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
| using Random, Distributions, Plots | |
| # the parent type | |
| abstract type ricker end | |
| # derived, concrete types | |
| mutable struct ricker_deterministic <: ricker | |
| x::Float64 | |
| r::Float64 | |
| k::Float64 |
This file contains hidden or 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
| # a simple Ricker model, which may be stochastic if you provide `sd` or deterministic if not | |
| setup_ricker <- function(x0, r, k, sd = NULL) { | |
| type <- c("ricker") | |
| if (is.null(sd)) { | |
| type <- c(type, "ricker_deterministic") | |
| } else { | |
| type <- c(type, "ricker_stochastic") | |
| } | |
| mod <- structure(new.env(), class = type) | |
| mod$x <- x0 |
NewerOlder