Instantly share code, notes, and snippets.

• Sort options

# Mike Lawrencemike-lawrence

View pulse.Rproj
 Version: 1.0 RestoreWorkspace: No SaveWorkspace: No AlwaysSaveHistory: No EnableCodeIndexing: Yes UseSpacesForTab: Yes NumSpacesForTab: 2 Encoding: UTF-8
View gp_regression.stan
 functions{ // GP: computes noiseless Gaussian Process vector GP(real volatility, real amplitude, vector normal01, int n_x, real[] x ) { matrix[n_x,n_x] cov_mat ; real amplitude_sq_plus_jitter ; amplitude_sq_plus_jitter = amplitude^2 + 1e-6 ; cov_mat = cov_exp_quad(x, amplitude, 1/volatility) ; for(i in 1:n_x){ cov_mat[i,i] = amplitude_sq_plus_jitter ; }
 fname = 'temp.txt' #wait for it to exist while(!file.exists(fname)){} old = 0 new = old while(T){ while(new==old){ new = file.size(fname) } f = file(
View find_last_line.R
 f = file(description='bigFile.txt',open='rb') n = 0 temp = 1 while(length(temp)<2){ n = n + 1 seek(con=f,origin='end',where=-(2^n)) temp <- scan(f,what='character',quiet=T) } last_line = temp[2]
View gp_regression.stan
 functions{ # GP: computes noiseless Gaussian Process given pre-computed unique distances vector GP(real volatility, real amplitude, vector normal01, int n_x, int n_dx, vector dx_unique, int [,] dx_index) { # covars: unique entries in covariance matrix vector[n_dx] covars ; # covMat: covariance matrix matrix[n_x,n_x] covMat ;
View crf_demo.R
 library(tidyverse) library(rstan) rstan_options(auto_write = TRUE) curve(dweibull(x,shape=1.75,scale=1e3),from=0,to=3e3) one_response = dweibull(x=1:3e3,shape=1.75,scale=1e3) one_response = one_response/max(one_response) # create a signal with pulses at t=2e3, t=4e3 & t=5e3 obs = rep(0,8e3)
View bigStan.R
 # Code below may not be up to date, see ezStan (https://github.com/mike-lawrence/ezStan/blob/master/R/bigStan.R) for latest version # todo: # during-sampling: effective sample size and rhat for each parameter # during-sampling: diagnostics? #usage: # #compile the model using rstan::stan_model:
View cfa.stan
 data{ # n_subj: number of subjects int n_subj ; # n_y: number of outcomes int n_y ; # y: matrix of outcomes matrix[n_subj,n_y] y ; # n_fac: number of latent factors int n_fac ; # y_fac: list of which factor is associated with each outcome
View compare_ceq_dx_udx.R
 #load packages library(tidyverse) library(rstan) rstan_options(auto_write = TRUE) # Make some fake data ---- #set random seed for reproducibility set.seed(1)
View gp_example.R