Skip to content

Instantly share code, notes, and snippets.

Avatar

Hao Ye ha0ye

View GitHub Profile
@ha0ye
ha0ye / partition function calculator.R
Last active Mar 29, 2017
Compute the Partition Function Q: the number of ways of writing n as a sum of positive integers, disregarding order, but with the constraint that all integers are distinct.
View partition function calculator.R
# For more info, see http://mathworld.wolfram.com/PartitionFunctionQ.html
# This uses the 2nd recurrence relation defined therein.
max_n <- 1000
# helper function
s <- integer(length = max_n)
for(j in 1:sqrt((2*max_n+1)/3))
{
n <- j * (3 * j + 1) / 2
View keybase.md

Keybase proof

I hereby claim:

  • I am ha0ye on github.
  • I am hao_and_y (https://keybase.io/hao_and_y) on keybase.
  • I have a public key ASALs4BLGzLmT9iU4H5GOc11WPPLg9KQvuwvbLG8MntrQwo

To claim this, I am signing this object:

@ha0ye
ha0ye / log.txt
Created May 11, 2018
Travis Erroring on R package install
View log.txt
travis_fold:start:worker_info
Worker information
hostname: 12607e0a-d790-494c-abc0-33bec19d51ab@1.production-1-worker-org-a-4-gce
version: v3.6.0 https://github.com/travis-ci/worker/tree/170b2a0bb43234479fd1911ba9e4dbcc36dadfad
instance: travis-job-a2fd8785-6b65-4c56-b87e-cbd4d1016e0f travis-ci-garnet-trusty-1512502259-986baf0 (via amqp)
startup: 26.186769693s
travis_fold:end:worker_info
travis_fold:start:system_info
Build system information
Build language: ruby
View lavaan to visNetwork
library(lavaan)
library(visNetwork)
model <- '
# measurement model
ind60 =~ x1 + x2 + x3
dem60 =~ y1 + y2 + y3 + y4
dem65 =~ y5 + y6 + y7 + y8
# regressions
dem60 ~ ind60
@ha0ye
ha0ye / drake-parallel.R
Created Jun 21, 2019
parallelization within drake targets
View drake-parallel.R
library(drake)
library(furrr)
future::plan(future::multiprocess)
tictoc::tic()
params = data.frame(t = c(1, 2, 3, 1, 2, 3))
out = purrr::pmap(params, Sys.sleep)
tictoc::toc()
View change legend labels in "likert" package
library(likert)
data(pisaitems)
##### Item 24: Reading Attitudes
items24 <- pisaitems[,substr(names(pisaitems), 1,5) == 'ST24Q']
head(items24); ncol(items24)
names(items24) <- c(
ST24Q01="I read only if I have to.",
ST24Q02="Reading is one of my favorite hobbies.",
View dplyr-timing-test.R
library(dplyr)
library(microbenchmark)
set.seed(42)
n <- 10000
df <- data.frame(a = rep(seq(n), 2),
x = rnorm(2 * n))
group_summarize_mutate <- function(df)
{
@ha0ye
ha0ye / script.R
Created Feb 18, 2020
read in param output from text file
View script.R
full_text <- readLines(file, warn = FALSE)
start_par_line <- grep("^\\$par", full_text)
start_objective_line <- grep("^\\$objective", full_text)
param_lines <- seq(from = start_par_line,
to = start_objective_line - 3,
by = 2)
params <- purrr::map_dfc(param_lines, function(line_idx)
{
readr::read_delim(file, delim = " ",
View gist:d62b33b1d735b09610852a7113f6bda3
library(rEDM)
#### Example 1: a single forward prediction
# Assume we have already done the analysis, finding that the best embedding
# dimension is 2. Our objective is to make multiple 1-step ahead forecasts
# using simplex and E = 2.
dat <- data.frame(yr = as.numeric(time(sunspot.year)),
sunspot_count = as.numeric(sunspot.year))
E <- 3
@ha0ye
ha0ye / gist:197de5797df1d4e2b14a8bff4fb99c95
Created Mar 28, 2020
pairwise overlap calculations
View gist:197de5797df1d4e2b14a8bff4fb99c95
calc3 <- function(sets)
{
sets <- check_sets(sets)
set_lengths <- vapply(sets, length, 0)
set_order <- order(set_lengths)
sets <- sets[set_order]
set_lengths <- set_lengths[set_order]
n_sets <- length(sets)
set_names <- names(sets)
You can’t perform that action at this time.