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
#define a function to generate a random vector | |
makeNewVector = function(vectorLength){ | |
#random normal | |
x = rnorm(vectorLength) | |
#normalize to length 1 | |
x/(sqrt(sum(x^2))) | |
} | |
#define a function to compute cosine similarity between two vectors | |
cosine <- function( x, y) { |
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
Version: 1.0 | |
RestoreWorkspace: No | |
SaveWorkspace: No | |
AlwaysSaveHistory: No | |
EnableCodeIndexing: Yes | |
UseSpacesForTab: Yes | |
NumSpacesForTab: 2 | |
Encoding: UTF-8 |
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{ | |
// 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 ; | |
} |
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
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( |
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
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] |
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{ | |
# 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 ; |
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(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) |
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
# 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: |
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
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 |
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
#load packages | |
library(tidyverse) | |
library(rstan) | |
rstan_options(auto_write = TRUE) | |
# Make some fake data ---- | |
#set random seed for reproducibility | |
set.seed(1) |