This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class KeyAwareDefaultDict(dict): | |
""" | |
Like a standard library defaultdict, but pass the key | |
to the default factory. | |
""" | |
def __init__(self, default_factory=None): | |
self.default_factory = default_factory | |
def __getitem__(self, key): | |
if key not in self and self.default_factory is not None: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Parallelized k-means module. | |
By David Warde-Farley, February 2012. Licensed under the 3-clause BSD. | |
""" | |
cimport cython | |
from cython.parallel import prange | |
import numpy as np | |
cimport numpy as np | |
from numpy.random import normal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scipy as S | |
def coo_submatrix_pull(matr, rows, cols): | |
""" | |
Pulls out an arbitrary i.e. non-contiguous submatrix out of | |
a sparse.coo_matrix. | |
""" | |
if type(matr) != S.sparse.coo_matrix: | |
raise TypeError('Matrix must be sparse COOrdinate format') | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Take in a CoventryBS grid card as a text file, output regex custom fields for | |
Bitwarden to autofill your grid card challenge for you. | |
""" | |
from __future__ import print_function | |
import fileinput | |
import itertools | |
import sys | |
COLS = 'ABCDEFGHIJ' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
Draws Hinton diagrams using matplotlib ( http://matplotlib.sf.net/ ). | |
Hinton diagrams are a handy way of visualizing weight matrices, using | |
colour to denote sign and area to denote magnitude. | |
By David Warde-Farley -- user AT cs dot toronto dot edu (user = dwf) | |
with thanks to Geoffrey Hinton for providing the MATLAB code off of | |
which this is modeled. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from theano import tensor | |
def binary_crossentropy_from_logits(logits, targets): | |
"""Binary cross-entropy computed from model logits. | |
Parameters | |
---------- | |
predictions : TensorVariable | |
The unnormalized log probabilities of a probabilistic binary | |
classifier. | |
targets : TensorVariable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Simple implementation of ROC curve plotting with NumPy and matplotlib. | |
No bells and whistles, no fancy data structures, just one function and | |
a (hopefully) very gentle learning curve. | |
""" | |
__author__ = "David Warde-Farley <dwf AT cs.toronto.edu>" | |
__copyright__ = "(c) 2010 David Warde-Farley" | |
__license__ = "3-clause BSD license" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A proof-of-concept multi-threaded chunked NPY format reader. | |
""" | |
__author__ = "David Warde-Farley" | |
__credits__ = ["David Warde-Farley"] | |
__license__ = "3-clause BSD" | |
__email__ = 'd dot warde dot farley at gmail DOT com" | |
import threading | |
from numpy.lib.format import read_magic, read_array_header_1_0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import OrderedDict | |
from blocks.algorithms import GradientDescent, Momentum | |
from blocks.bricks import ( | |
MLP, Rectifier, Logistic, Linear, LinearMaxout, Sequence, Random | |
) | |
from blocks.extensions import Printing, Timing | |
from blocks.extensions.training import SharedVariableModifier | |
from blocks.extensions.monitoring import (DataStreamMonitoring, | |
TrainingDataMonitoring) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Reverses a hex dump (of the format shown in the Firefox cache). | |
The format is as follows: | |
<OFFSET> <BYTE> [<BYTE> [<BYTE> [...]]] [render] | |
Where | |
- <OFFSET> is 8 hex digits, possibly followed by a colon | |
- each <BYTE> is (maximum 16 per line) |