Skip to content

Instantly share code, notes, and snippets.

@zaxtax
zaxtax / figexampledata.txt
Created January 16, 2013 13:24
The problem present in DPGMM
-2.844059489096403048e+00 -3.390078096791193651e+00
-2.246556725692058443e+00 -4.134951453470232963e+00
-2.882040217945443406e+00 -2.989992710367860074e+00
-3.557989559969744420e+00 -4.874133498203447878e+00
-4.276468588458921083e+00 -4.949100415222556393e+00
-4.063084646541525125e+00 -4.965449471424126848e+00
-4.149768316170935556e+00 -4.304566658733071982e+00
-3.397283783389075218e+00 -2.450041447189784449e+00
-6.116576211048087686e+00 -4.566201068837830945e+00
-4.549464218962874895e+00 -4.120424270357679220e+00
@zaxtax
zaxtax / json_transformer.py
Created May 3, 2013 17:00
Exploring more internet friendly formats for loading data into scikit-learn
from itertools import chain
class JsonFlatten:
"""Flattens nested dictionaries into a flat key/value mapping.
This encoding is designed to be used with DictVectorizer
See also
--------
:class:`sklearn.feature_extraction.DictVectorizer` to pass for
@zaxtax
zaxtax / finite_mixture.py
Last active October 3, 2016 05:09
Mixture modeling example in pymc
import numpy as np
from pymc import Model, Gamma, Normal, Dirichlet
from pymc import Categorical
from pymc import sample, Metropolis
k = 3
ndata = 500
v = np.random.randint(0, k, ndata)
data = ((v == 0)*(50 + np.random.randn(ndata))
@zaxtax
zaxtax / DDP Regression.ipynb
Created September 27, 2016 20:27 — forked from AustinRochford/DDP Regression.ipynb
Dependent Dirichlet Process Regression
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@zaxtax
zaxtax / xor.py
Created February 12, 2017 03:39 — forked from stewartpark/xor.py
Simple XOR learning with keras
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation
from keras.optimizers import SGD
import numpy as np
X = np.array([[0,0],[0,1],[1,0],[1,1]])
y = np.array([[0],[1],[1],[0]])
model = Sequential()
model.add(Dense(8, input_dim=2))
@zaxtax
zaxtax / ProgrammaticNotebook.ipynb
Created February 23, 2017 02:28 — forked from fperez/ProgrammaticNotebook.ipynb
Creating an IPython Notebook programatically
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@zaxtax
zaxtax / XPS-15 9560 Getting Nvidia To Work on KDE Neon
Created March 2, 2017 07:54 — forked from whizzzkid/XPS-15 9560 Getting Nvidia To Work on KDE Neon
Making Nvidia Drivers + CUDA 8 + Bumblebee work together on XPS 15 Early 2017 9560 kabylake.
# Update to 4.9 kernel do not delete the old kernel as it will be your failsafe if something happens to this one
# Install KabyLake graphics patches
cd /tmp;
wget https://01.org/sites/default/files/downloads/intelr-graphics-linux/kbldmcver101.tar.bz2;
tar xjvf kbldmcver101.tar.bz2; cd kbl_dmc_ver1_01/; sudo ./install.sh
cd /tmp;
wget https://01.org/sites/default/files/downloads/intelr-graphics-linux/kblgucver914.tar.gz;
tar xvzf kblgucver914.tar.gz; cd firmware/kbl/guc/kbl_guc_ver/; sudo ./install.sh
class BayesianModel(object):
samples = 2000
def __init__(self, cache_model=True):
self.cached_model = None
self.cached_start = None
self.cached_sampler = None
self.shared_vars = {}
def cache_model(self, **inputs):
self.shared_vars = self._create_shared_vars(**inputs)
@zaxtax
zaxtax / ner_tagger.py
Created April 11, 2017 18:10
NER Tagger
import numpy as np
from keras.models import Sequential
from keras.layers.core import Activation
from keras.layers.wrappers import TimeDistributed
from keras.preprocessing.sequence import pad_sequences
from keras.layers import Embedding, LSTM, Dense
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix, accuracy_score, precision_recall_fscore_support
raw = open('wikigold.conll.txt', 'r').readlines()
{-# LANGUAGE FlexibleInstances #-}
-- | An implementation of Section 3, Local Type Argument Synthesis, from the
-- paper /Local Type Inference/ by Pierce and Turner.
module Infer where
import Control.Monad (foldM, join, zipWithM)
import Data.Function (on)
import Data.List (foldl', groupBy, intercalate, intersect, nub)