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 <chrono> | |
#include <iostream> | |
#include <fstream> | |
#include <mutex> | |
class TimerLogger { | |
public: | |
TimerLogger(const std::string& label, const std::string& filename = "timelog.csv") | |
: label_(label), filename_(filename) { | |
start_ = std::chrono::high_resolution_clock::now(); |
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
data { | |
int<lower=0> N; | |
int<lower=0> D; | |
int<lower=0> R; | |
matrix[N,D] Y; | |
} | |
parameters { | |
row_vector[D] mu; | |
matrix[D,R] W; | |
real<lower=0> sig2; |
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 CairoMakie | |
#https://docs.makie.org/stable/ | |
xv = 0:0.1:20 | |
f = Figure() | |
ax = Axis(f[1, 1]) | |
l1 = lines!(ax, xv, pdf.(Gumbel(0,1), xv)) | |
l2 = lines!(ax, xv, pdf.(Gumbel(1,1), xv), linestyle=:dash) | |
l3 = lines!(ax, xv, pdf.(Gumbel(0,2), xv), linestyle=:dot) |
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 | |
using Distributions | |
using CairoMakie | |
using FileIO | |
beta = [1, 2] | |
rng = Random.default_rng(1234) | |
X = [ones(10) randn(rng, 10)] | |
y = X * beta + randn(rng, 10) |
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
makeLmat <- function (h){ | |
x = seq(0,1,by=h) | |
N=length(x) | |
invh2 <- 1/(h^2) | |
res = diag(invh2, N) | |
res[cbind(1:(N-1),2:N)] <- -0.5*invh2 | |
res[cbind(2:N,1:(N-1))] <- -0.5*invh2 | |
return(list(L=res,x=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
library(ggplot2) | |
library(dplyr) | |
library(mvtnorm) | |
set.seed(1) | |
x1 = rnorm(10, 0, 1) | |
x2 = x1+rnorm(10, 0, 0.1) | |
y = x1+x2 + rnorm(10, 0, 1) | |
print(cor(x1,x2)) |
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
library(deSolve) | |
SEIRmod <- function(Time, State, Pars) { | |
with(as.list(c(State, Pars)), { | |
dS <- - beta*I*S | |
dE <- beta*I*S - alpha*E | |
dI <- alpha*E - gamma*I | |
dR <- gamma*I | |
return(list(c(dS, dE, dI, dR))) | |
}) |
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
# Reference: | |
# Hoffman et al. "Stochastic Variational Inference" | |
# browseURL("https://arxiv.org/abs/1206.7051") | |
#### | |
# learning rate | |
lr <-function(t, lr_param){ | |
(t + lr_param[1])^(-lr_param[2]) | |
} |
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
#intensity function | |
lambda <- function(x, shape){ | |
shape*x^(shape-1) | |
} | |
#number of truncated observation | |
counttrunc <- function(tau, WS, weibull_param, | |
shape=1, maxit=10000){ | |
Et = 0 | |
count = 0L |
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
#install.packages('RcppPlanc', repos = c('https://welch-lab.r-universe.dev', 'https://cloud.r-project.org')) | |
library(rliger) | |
library(RcppPlanc) | |
library(bench) | |
pbmc <- normalize(pbmc) | |
pbmc <- selectGenes(pbmc) | |
pbmc <- scaleNotCenter(pbmc) | |
getOption("ligerVerbose", TRUE) | |
bm <- bench::mark({ |
NewerOlder