Skip to content

Instantly share code, notes, and snippets.

View 3inar's full-sized avatar

Einar Holsbø 3inar

View GitHub Profile
@3inar
3inar / untitled-2017-10-18.R
Created October 18, 2017 13:34
2017-10-18 untitled from rstudio
library(boot)
library(plyr)
set.seed(22042017) # for reproducibility
generate_data <- function(nsamples=100) {
x <- rnorm(nsamples,mean=.75, sd=.5)
y <- 4 + 5*x -3*x^2 + rnorm(length(x), mean=0, sd = 1)
data.frame(x,y)
}
@3inar
3inar / untitled-2017-10-18.R
Created October 18, 2017 13:34
2017-10-18 untitled from rstudio
library(plyr)
# some very tight high-dimensional data vs some less tight HD data
big <- raply(75, rnorm(50))
small <- raply(75, rnorm(50, sd=1/50))
datas <- rbind(big, small)
colrs <- c(rep("black", 75), rep("red", 75))
@3inar
3inar / untitled-2017-10-18.R
Created October 18, 2017 13:32
2017-10-18 untitled from rstudio
# regression to the mean
n <- 10000
base <- runif(n, 0,10)
dat <- data.frame(x=base+rnorm(n), y=base+rnorm(n))
plot(dat)
abline(0,1, col="grey")
abline(lm(y~x, data=dat))
@3inar
3inar / untitled-2017-10-18.R
Created October 18, 2017 13:31
2017-10-18 untitled from rstudio
library(plyr)
experiment <- raply(10000, function() {
x <- runif(100, -1, 5)
y <- 1 + 2* x + rnorm(100,sd = 16)
split_x <- split(x, ceiling(seq_along(x)/5))
split_y <- split(y, ceiling(seq_along(y)/5))
@3inar
3inar / untitled-2017-10-18.R
Created October 18, 2017 13:23
2017-10-18 untitled from rstudio
library(plyr)
set.seed(2017-06-08)
l=0.5
# this distribution has mean and variance both = l above
# importantly it never produces values < 0
plot(table(rpois(100, lambda=l)))
@3inar
3inar / example_rscript.R
Created April 11, 2017 17:46
Example R script for stallo batch jobs
# This is my experiment that I want to run many times
x <- rnorm(500)
y <- rnorm(500)
my_model <- lm(y~x)
# I usually like to write my results to a randomly named file. I recommend using an absolute path
# so you're 100% sure where the file ends up
random_output_file <-paste0("/home/einar/my_experiments/linear_model", as.character(sample(1:999999, 1)), ".RData")
save(my_model, file = random_output_file)
@3inar
3inar / jobscript.sh
Created April 11, 2017 17:31
Example of job script for stallo
#!/usr/bin/env bash
# commands to the batch system start with '#SBATCH '
# pick a name for your job
#SBATCH --job-name=my_job
# I want 500 duplicate jobs that use a single cpu each
#----------------------------------------------------------------
# one machine per job:
@3inar
3inar / cputrack.sh
Created October 27, 2014 15:57
A thing for tracking cpu+mem usage for a single process. I don't remember where it's from
#!/bin/bash
# --- Version history ---
# 0.4: added variable to store file path, and $2 for base file name
# added variable to store desired reporting interval
# 0.3: added $1 to send in process ID at run time.
# 0.2: switched to $SECONDS for the loop. works.
# 0.1: didn't work well at all.
# --- Version history ---
# Usage: cputrack [PID] [filename]