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
""" | |
Python Script to extract code blocks from tex files for CS281 | |
input: a file in current working directory with suffix *.tex | |
output: the same file with suffix *.py, with everything except the python parts removed | |
""" | |
#import pdb | |
from sys import argv | |
import os | |
def convert(ifile,ofile): |
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
""" | |
Testing python multiprocessing speed. Based on | |
http://blogs.warwick.ac.uk/dwatkins/entry/benchmarking_parallel_python_1_2/ | |
""" | |
import time | |
import math | |
import multiprocessing as mp | |
def isprime(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
library(mgcv) | |
#library(modules) #devtools::install_github(klmr/modules) | |
#mgcv<-import_package("mgcv") | |
mspline<-function(x,y,k=10,lower=NA,upper=NA){ | |
#fits a monotonic spline to data | |
#small values of k= more smoothing (flatter curves) | |
#large values of k= more flexible (wiggly curves) | |
#k is related to effective degrees of freedom and number of knots | |
#use unconstrained gam to get rough parameter estimates |
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
### Adaptive Rejection Sampling | |
# by Will Townes | |
rexp_trunc<-function(n,slope=-1,lo=0,hi=Inf){ | |
#draw n samples from the truncated exponential distribution | |
#the distribution is proportional to exp(slope*x) | |
#default is standard exponential | |
#slope cannot equal zero | |
#lo is lower truncation point, can be -Inf | |
#hi is upper truncation point, can be +Inf |
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
#compositional analysis | |
library(compositions) | |
x<-c(.1,.5,.4) | |
V<-t(ilrBase(x)) | |
D<-rbind(c(1,0,-1),c(0,1,-1)) | |
x_alr<-D%*%log(x) | |
x_ilr<-V%*%log(x) | |
x_alr | |
alr(x) | |
x_ilr |
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
#splatter experimenting with cell-specific dropouts | |
#pertains to https://github.com/Oshlack/splatter/issues/25 | |
#devtools::install_github("Oshlack/splatter@dropout") | |
library(splatter) | |
data("sc_example_counts") | |
# Estimate parameters from example data | |
params <- splatEstimate(sc_example_counts) | |
# Simulate data using estimated parameters | |
sim1 <- splatSimulate(params, dropout.type = "experiment") | |
assay(sim1,"logcounts")<-log2(1+assay(sim1,"counts")) |
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
#gradient descent probabilistic PCA with missing data | |
#Will Townes | |
L<-2 #number of latent dimensions, more dims=more complexity | |
#tune these hyperparameters until get good results | |
penalty<- 1e-8 | |
learn_rate<- .1 | |
niter<-100000 #number of iterations | |
data(iris) |
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
#Fuzzy version of Jaccard and Rand Indices | |
#based on Suleman: "Assessing a Fuzzy Extension of Rand Index and Related Measures" | |
L<-4 #number of clusters | |
N<-50 #number of objects | |
X<-gtools::rdirichlet(N,rep(.01,L)) #NxL soft random clustering | |
y<-apply(X,1,which.max) #hard cluster version of X | |
table(y) | |
Y<-model.matrix(~factor(y)-1) #hard cluster version of X | |
Z<-matrix(1/L,nrow=N,ncol=L) #perfect uncertainty soft clustering |
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
#include <omp.h> | |
#include <stdio.h> | |
//clang++ -Xpreprocessor -fopenmp -lomp omptest.cpp -o omptest | |
int main() { | |
#pragma omp parallel | |
printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads()); | |
} |
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
library(pdist) | |
n<-200 | |
X<-matrix(10*runif(n),ncol=1) | |
y<-sin(X[,1])#+rnorm(n,sd=.2) | |
#plot(X[,1],y) | |
#xnew<-3 | |
#span<-1 | |
my_loess<-function(xnew,X,y,span=.75){ |