View broken_render.R
if (RUN_RAND_EST) { | |
tic(sprintf("Estimation with %d cores:", core_count)) | |
res3 = wrapper_rand(guess3, fun_xb=lklhd_statedep_xb_m, Xs=model_matrices, | |
choices=choice_matrices, eta=etas, eta_hh=eta_hh_indcs, | |
NS=NS, v2m=betas_rand_brand_v2m, cores=core_count, trace=1, | |
REPORT=5) | |
toc() # FAILS HERE | |
# error: | |
# label: unnamed-chunk-8 |
View jessica.jl
function getprobs(x, a, b) | |
ea = exp.(x * a) | |
eb = exp.(x * b) | |
denom = 1 .+ ea .+ eb | |
proba = ea ./ denom | |
probb = eb ./ denom | |
return proba, probb, 1 .- proba, 1 .- probb | |
end |
View dsetin.R
library(data.table) | |
dt = data.table(i=rep(1:5, each=10), t=rep(1:5, times=2), x=runif(50), key=c('i', 't')) | |
myfunc = function(x) { | |
return(data.frame(sum=sum(x), mean=mean(x))) | |
} | |
dt[, myfunc(x), by=.(i, t)] |
View stupid_query.jl
function get_tracks_structured(db, user, track_id, author_id, genre, ca, weeks; | |
random_type::Symbol=:fake, rand_pct=0.20, count_each=2, | |
nrepost=count_each, | |
nartist=count_each, nartist_repost=count_each, | |
nseen=count_each, nseen_repost=count_each, | |
nsameartist=count_each, nsartist_repost=count_each, | |
do_selection=false) | |
if random_type == :fake | |
do_random = "AND rand01() < $(rand_pct)" | |
elseif random_type == :sort |
View short_circuit.sql
/* | |
* table plays lists all plays by all users across time | |
* table affils lists who (fan) follows whom (contact) as of a given point of time | |
* table reposts lists who reposted what song at what time | |
* I want to know for each row in plays if the user was following someone who reposted the track | |
* I also want to know for each row in plays if the user followed someone who was the author of the track | |
* the author is frequently NULL | |
I think the below query is correct, but it looks like it realizes the full join of everyone who | |
may have reposted the track that the listener follows. I am wondering if there is a way to write it |
View parallel_iteration.jl
struct ChanWrap | |
iter_chan::RemoteChannel | |
end | |
Base.next(d::ChanWrap) = take!(d.iter_chan) | |
const rchan = RemoteChannel(() -> Channel{StructCompData}(args["max_channel_size"])) | |
@everywhere function produce_data(iter_chan, dbfile, nworkers, batch_size, | |
niters; kwargs...) | |
total_iters = batch_size * (niters + 2) |
View broken_benchmark.jl
function get_all_tracks_info(db, track_id, ca; num=49) | |
res = vcat(SQLite.query(db, sr""" | |
SELECT track_id, track_index, author_id, genre, 1 AS listened | |
FROM tracks | |
WHERE track_id = ?;""", | |
values=[track_id]), | |
SQLite.query(db, sr""" | |
SELECT track_id, track_index, author_id, genre, 0 AS listened | |
FROM tracks | |
WHERE created_at < ? AND track_id <> ? |
View gradient_scope_test.jl
using ReverseDiff | |
using Base.Test | |
mutable struct data | |
X::Array{Float64, 2} | |
end | |
const D = data(zeros(Float64, 2, 2)) |
View intset.jl
using BenchmarkTools | |
function _test(N, prods, pos_prods, maxseen) | |
z = 0 | |
for i in 1:N | |
neg = setdiff(prods, pos_prods[i]) | |
z += rand(1:maxseen) | |
end | |
return z | |
end |
View sd_weirdness.jl
function scale_sd!(A::SparseMatrixCSC; corrected=true) | |
n = size(A, 1) | |
if corrected | |
sdcall(v,n,mn) = sqrt(sum(vi^2 for vi in v) / (n - 1) - (n / (n - 1)) * mn^2) | |
else | |
sdcall(v,n,mn) = sqrt(sum(vi^2 for vi in v) / n - mn^2) | |
end | |
for j in 1:size(A, 2) | |
k = A.colptr[j]:(A.colptr[j+1] - 1) | |
if length(k) > 0 |
NewerOlder