Skip to content

Instantly share code, notes, and snippets.

View syadlowsky's full-sized avatar

Steve Yadlowsky syadlowsky

View GitHub Profile
@article{Neyman23,
title={Pr\'{o}ba uzasadnienia zastosowa\'{n} rachunku prawdopodobie\'{n}stwa do doswiadcze\'{n} polowych},
author={Neyman, Jerzy},
journal={Roczniki Nauk Rolniczych Tom X},
volume={10},
pages={1--51},
url = {https://digitalassets.lib.berkeley.edu/sdtr/ucb/text/235.pdf},
year={1923}
}
# Idea thanks to https://scottclowe.com/2016-03-19-stratified-regression-partitions/
# Adapted for right censored survival outcomes by applying the above procedure
# separately for censored and uncensored observations.
# Copyright 2019 Steve Yadlowsky
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
simple.logistic = function(x, y, w, iters=30, l1_penalty=0) {
d = ncol(x)
n = nrow(x)
x_c = colMeans(x)
x = (x - matrix(rep(x_c, n), nrow=n, byrow = T))
x_s = sqrt(colMeans(x^2))
x = (x / matrix(rep(x_s, n), nrow=n, byrow = T))
beta = rep(0,d)
p = weighted.mean(y, w = w)
beta_0 = log(p) - log(1-p)
SIGMA = args.sigma
NUM_RAND_FEATURES = args.num_rand_features
data_hdf5 = h5py.File(args.filename,'r+')
d = data_hdf5['train']['x'][0].shape[0]
n = len(data_hdf5['train']['x'])
train_y = np.array(data_hdf5['train']['t'])
features = np.array(data_hdf5['train']['x'])
class foo:
def __init__(self, a={}):
self.a = a
one = foo()
two = foo()
two.a["a"] = 2
print one.a
c_0 = -0.969474842881623111168210
c_2 = 4.364528972627628178315717
c_4 = -2.422793242101592081638728
function fast_cos(t::Real)
# Computes cos(pi*t) using a Chebyshev approximation.
# This approximation is minimax optimal on [-1, 1].
# By scaling by pi, we find an optimal approximation on
# the entire range of cos(x). Because cos(x - pi) = -cos(x),
# we can take the remainder with 2, and shift [0, 2] |-> [-1, 1],
@syadlowsky
syadlowsky / The plan
Last active August 29, 2015 14:19
Migrating to Emacs
The plan
========
1. [http://www.jesshamrick.com/2012/09/10/absolute-beginners-guide-to-emacs/](http://www.jesshamrick.com/2012/09/10/absolute-beginners-guide-to-emacs/)
2. [http://www.gnu.org/software/emacs/manual/](http://www.gnu.org/software/emacs/manual/) (just the main section)
3. [http://bling.github.io/blog/2013/10/27/emacs-as-my-leader-vim-survival-guide/](http://bling.github.io/blog/2013/10/27/emacs-as-my-leader-vim-survival-guide/)
4. [http://www.gnu.org/software/emacs/manual/eintr.html](http://www.gnu.org/software/emacs/manual/eintr.html)
5. [https://github.com/ronuchit/Settings/blob/master/.emacs](https://github.com/ronuchit/Settings/blob/master/.emacs)
6. [http://www.jesshamrick.com/2012/09/18/emacs-as-a-python-ide/](http://www.jesshamrick.com/2012/09/18/emacs-as-a-python-ide/)
postgres=# CREATE LANGUAGE plpythonu;
ERROR: language "plpythonu" already exists
postgres=# \q
postgres@xxxxxx:/home/ubuntu/xxxxxxx/django_utils$ psql geodjango -f voronoi_python.sql
psql:voronoi_python.sql:826: ERROR: language "plpythonu" does not exist
@syadlowsky
syadlowsky / gist:3836797
Created October 4, 2012 22:09
ruby debug
mongo-problem.rb:42
video_group.update!({ 'videos.video_id' => 'video1', :multi => true }, '$set' => {
(rdb:1) s
/home/steve/.rvm/gems/ruby-1.9.3-p194/gems/mongomatic-0.8.2/lib/mongomatic/base.rb:265
update(opts.merge(:safe => true),update_doc)
(rdb:1) s
/home/steve/.rvm/gems/ruby-1.9.3-p194/gems/mongomatic-0.8.2/lib/mongomatic/base.rb:243
if opts[:raise] == true
(rdb:1) s
/home/steve/.rvm/gems/ruby-1.9.3-p194/gems/mongomatic-0.8.2/lib/mongomatic/base.rb:248
@syadlowsky
syadlowsky / gist:2040953
Created March 15, 2012 01:10
CALLOC FREE weirdness
#include<stdlib.h>
// number of floats that fit in L1 cache
#define L1_SIZE 1024
#define L1_MATRIX_ALLOT 512
// number of floats that fit in L2 cache
#define L2_SIZE 8192
// number of floats that fit in L2 cache
#define L3_SIZE 8192