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 AMDB | |
| using DataStructures | |
| using GZip | |
| using UnicodePlots | |
| # replace this line with the path on your own machine | |
| records = GZip.open(deserialize, | |
| expanduser("~/research/AMDB/data/AMDB_subsample.jls.gz"), "r") | |
| long_samples = [data for (id,data) in records if length(data.AMP_spells) > 1000] |
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
| type ParseErrorLoc | |
| T | |
| string | |
| column | |
| line | |
| end | |
| function Base.show(io::IO, pel::ParseErrorLoc) | |
| print("could not parse \"$(pel.string)\" as $(pel.T)") | |
| if pel.column > 0 |
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
| module Foos | |
| type Foo{T <: Tuple} | |
| end | |
| m1{T}(f::Foo{Tuple{T}}, index::T...) = 42 # suggested by Bill Hart | |
| m2{T}(f::Foo{T}, index::T...) = 42 # what I thought would work | |
| _m3{T}(f::Foo{T}, index::T) = 42 # indirect solution | |
| m3{T}(f::Foo{T}, index...) = _m3(f, index) | |
| end | |
| f1 = Foos.Foo{Tuple{Int}}() |
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
| > stanmodelcode <- " | |
| data { | |
| int<lower=0> N; | |
| real y[N]; | |
| } | |
| parameters { | |
| real mu; | |
| } | |
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
| N <- 100 | |
| w <- rlnorm(N,0,1) | |
| a <- runif(N,0,1) | |
| m <- 2 | |
| keep <- w < a*m | |
| w_kept <- w[keep] | |
| a_kept <- a[keep] | |
| N_kept <- sum(keep) |
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
| @doc "All length `n` permutations of `v` in a matrix, with repetitions."-> | |
| function perm_matrix{T}(v::Vector{T}, n) | |
| l = length(v) | |
| m = l^n | |
| a = Array(T, m, n) | |
| for i = 1:m | |
| k = i-1 | |
| j = n | |
| while (j > 0) | |
| (d,r) = divrem(k,l) |
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 N; | |
| int a_N; // number of categories in a | |
| int b_N; // number of categories in b | |
| int c_N; // number of c coefficients (continuous) | |
| int<lower=1, upper=a_N> a[N]; | |
| int<lower=1, upper=b_N> b[N]; | |
| matrix[N, c_N] c; | |
| int<lower=0, upper=1> y[N]; | |
| } |
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 study in implementing univariate censoring | |
| library(rstan) | |
| ## simulated data | |
| m <- 1 # boundary | |
| z <- rlnorm(100) # latent variable | |
| z <- z[z > m] # only kept when above m | |
| N <- length(z) | |
| z_hat <- rlnorm(N, log(z), 0.1) # observed with noise |
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
| array_or_vector_p <- function(object) { | |
| ## Test if object is what we consider an array for the purposes of | |
| ## the code below. | |
| ## | |
| ## Lists are not arrays, but vectors are, even if they don't have a | |
| ## dim attribute. The following give an error: | |
| ## - objects which are neither lists, (non-list) vectors, or arrays | |
| ## - vectors and arrays with zero length | |
| ## - arrays with rank lower than 1 | |
| if (is.list(object)) |
NewerOlder