Skip to content

Instantly share code, notes, and snippets.

@syhw
syhw / dropout_simple_models.py
Created July 17, 2014 14:55
Trying dropout with simple off-the-selves scikit-learn models. Not really working.
from sklearn.datasets import fetch_20newsgroups, load_digits
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.cross_validation import train_test_split
import numpy as np
from sklearn.naive_bayes import MultinomialNB, BernoulliNB
from sklearn.linear_model import LogisticRegression, SGDClassifier
from sklearn import metrics
newsgroups_train = fetch_20newsgroups(subset='train')
vectorizer = TfidfVectorizer(encoding='latin-1', max_features=10000)
@syhw
syhw / dnn_compare_optims.py
Created July 16, 2014 19:21
to compare plain SGD vs. SAG vs. Adagrad vs. Adadelta
"""
A deep neural network with or w/o dropout in one file.
"""
import numpy
import theano
import sys
import math
from theano import tensor as T
from theano import shared
@syhw
syhw / dnn.py
Created July 13, 2014 20:55
Deep learning in one file.
"""
A deep neural network with or w/o dropout in one file.
"""
import numpy
import theano
import sys
from theano import tensor as T
from theano import shared
from theano.tensor.shared_randomstreams import RandomStreams
@syhw
syhw / naive_Bayes_Gibbs.py
Created April 24, 2014 08:30
Very old implementation of mine of "Gibbs Sampling for the Uninitiated" (Philip Resnik, Eric Hardisty)
# -*- coding: utf-8 -*-
import os, re, random, math
from collections import Counter
""" Naive Bayes with Gibbs sampling, so it can deal with unlabeled data """
# as from "Gibbs Sampling for the Uninitiated" Philip Resnik, Eric Hardisty
def Dirichlet(v):
""" takes a vector of counts v and returns a Multinomial ~ Dirichlet(v) """
y = []
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@syhw
syhw / RBM_checkers.py
Last active December 22, 2015 07:09
Encoding a checkerboard with an RBM
import numpy as np
import matplotlib.pyplot as plt
from sklearn.neural_network import BernoulliRBM
from sklearn import linear_model, metrics
from sklearn.pipeline import Pipeline
X = np.array([[0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,
0,1,0,1,0,1,0,1,
1,0,1,0,1,0,1,0,
@syhw
syhw / gist:5909833
Created July 2, 2013 14:36
Gaussian processes for threshold finding / response curve fitting, to eliminate the staircase in psycho experiments.
from sklearn.gaussian_process import GaussianProcess
import numpy as np
import copy
from matplotlib import pyplot as pl
np.random.seed(1)
def f(x, alpha=5., beta=10.):
"""The function to predict: Weibull centered on 5, ranging from 1 to 2."""
#return x * np.sin(x)
@syhw
syhw / gist:5128969
Created March 10, 2013 15:20
A collapsed Gibbs sampler for Dirichlet process Gaussian mixture models.
# -*- coding: utf-8 -*-
import itertools, random
import numpy as np
from scipy import linalg
import pylab as pl
import matplotlib as mpl
import math
epsilon = 10e-8