Skip to content

Instantly share code, notes, and snippets.

Code & Data
@lucktroy
lucktroy / py.gitignore
Last active October 24, 2017 01:24
py.gitignore
# data file
*.h5
*.pkl
# log file
*.log
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
@lucktroy
lucktroy / numpy.i
Created October 19, 2014 12:55
numpy swig
/* -*- C -*- (not really, but good for syntax highlighting) */
/* numpy 1.9 */
#ifdef SWIGPYTHON
%{
#ifndef SWIG_FILE_WITH_INIT
#define NO_IMPORT_ARRAY
#endif
#include "stdio.h"
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
@lucktroy
lucktroy / id3.py
Last active August 29, 2015 14:05 — forked from cmdelatorre/id3.py
"""
http://en.wikipedia.org/wiki/ID3_algorithm
http://www.cise.ufl.edu/~ddd/cap6635/Fall-97/Short-papers/2.htm
"""
from collections import namedtuple, Counter, defaultdict
from math import log2
@lucktroy
lucktroy / sort_list.py
Created August 11, 2014 07:07
Sort a list by multiple attributes
"""
url: http://stackoverflow.com/questions/4233476/sort-a-list-by-multiple-attributes
"""
s=[[12, 'tall', 'blue', 1],
[15, 'tall', 'black', 3],
[13, 'tall', 'blue', 8],
[9, 'short', 'blue', 3],
[1, 'short', 'black', 2],
[2, 'short', 'red', 9],
@lucktroy
lucktroy / chmod.sh
Created August 9, 2014 14:34
chmod dirs and files
#!/bin/sh
# files
find . -type f -exec chmod 644 {} \;
# dirs
find . -type d -exec chmod 755 {} \;
#coding: utf8
"""
1. Download this gist.
2. Get the MNIST data.
wget http://deeplearning.net/data/mnist/mnist.pkl.gz
3. Run this code.
python autoencoder.py 100 -e 1 -b 20 -v
Wait about a minute ... and get a vialization of weights.
"""
"""Parallel grid search for sklearn's GradientBoosting.
This script uses IPython.parallel to run cross-validated
grid search on an IPython cluster. Each cell on the parameter grid
will be evaluated ``K`` times - results are stored in MongoDB.
The procedure tunes the number of trees ``n_estimators`` by averaging
the staged scores of the GBRT model averaged over all K folds.
You need an IPython ipcluster to connect to - for local use simply
import numpy as np
from scipy import linalg
from sklearn.utils import array2d, as_float_array
from sklearn.base import TransformerMixin, BaseEstimator
class ZCA(BaseEstimator, TransformerMixin):
def __init__(self, regularization=10**-5, copy=False):
self.regularization = regularization
@lucktroy
lucktroy / cuda-convnet-13pct.sh
Last active January 2, 2016 01:58
A simple script for the example in https://code.google.com/p/cuda-convnet/wiki/Methodology Please add two params cfgs 'layer-params-conv-local-13pct-pw1.cfg' and 'layer-params-conv-local-13pct-pw2.cfg' in $CUDA_CONVNET/example-layers/ Just copy layer-params-conv-local-13pct.cfg to layer-params-conv-local-13pct-pw1.cfg and layer-params-conv-local…
# A simple script for the example in https://code.google.com/p/cuda-convnet/wiki/Methodology
# Please add two params cfgs 'layer-params-conv-local-13pct-pw1.cfg' and 'layer-params-conv-local-13pct-pw2.cfg' in $CUDA_CONVNET/example-layers/
# Just copy layer-params-conv-local-13pct.cfg to layer-params-conv-local-13pct-pw1.cfg and layer-params-conv-local-13pct-pw2.cfg,
# and reduce all learning rates (the epsW parameters) to 0.001 and 0.0001, respectively
# Result: training error 5.80% and testing error 12.90% (NVIDIA Tesla C2075)
# Junbo Zhang: zjb2046<at>gmail<dot>com
# Jan. 3, 2014
#set the output dir, which is used for `--save-path`
export OUTPUT=$HOME/RET/cuda-convnet/cifar10_13pct