Skip to content

Instantly share code, notes, and snippets.

Avatar

Steve Yadlowsky syadlowsky

View GitHub Profile
View partition_survival_data.R
# 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
View gist:19cf07030959654d2857f4b9a608e1b9
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)
View gist:dd1d95e1754f3760f3d989e36c7c1e70
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'])
View python fail
class foo:
def __init__(self, a={}):
self.a = a
one = foo()
two = foo()
two.a["a"] = 2
print one.a
View fast_cos_cheby.jl
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 Aug 29, 2015
Migrating to Emacs
View The plan
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/)
View gist:2cf68013cc3102eaaf26
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
View gist:3836797
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 Mar 15, 2012
CALLOC FREE weirdness
View gist:2040953
#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
@syadlowsky
syadlowsky / bridge
Created Mar 14, 2012
Ruby standards
View bridge
Bridge::initialize :api_key => 'abcdefgh' do |bridge|
puts 'connected!'
bridge.get_service("adder") do |service|
service.add(3, 5) do |ret_value|
puts ret_value
end
end
end
You can’t perform that action at this time.