Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
""" | |
A matplotlib-based image viewer utility function. | |
""" | |
import matplotlib.pyplot as plt | |
def image_view(arr, fig=None, frame_on=True, *args, **kwargs): | |
""" | |
Sensibly display an image in a plot window. | |
Parameters |
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 theano | |
import functools | |
def cached_theano_function(fn): | |
@functools.wraps(fn) | |
def wrapped(self): | |
if not hasattr(self, '_function_cache'): | |
self._function_cache = {} | |
if fn.func_name not in self._function_cache: |
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
""" | |
Example of how to read a partial NumPy array stored in NPY | |
format off of disk. | |
""" | |
__author__ = "David Warde-Farley" | |
__copyright__ = "Copyright (c) 2012 by " + __author__ | |
__license__ = "3-clause BSD" | |
__email__ = "dwf@dwf.name" | |
import struct |
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 | |
# Copyright (c) 2009, David Warde-Farley | |
# All rights reserved. | |
# | |
# Redistribution and use in source and binary forms, with or without | |
# modification, are permitted provided that the following conditions | |
# are met: | |
# 1. Redistributions of source code must retain the above copyright | |
# notice, this list of conditions and the following disclaimer. |
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
""" | |
L1-penalized minimization using the feature sign search algorithm. | |
""" | |
import logging | |
import numpy as np | |
log = logging.getLogger("feature_sign") | |
log.setLevel(logging.INFO) | |
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 theano.tensor as tensor | |
from theano import function | |
import numpy as np | |
value = np.array([ 0.992827313923019039165751564724, | |
0.118152792712208978831434080803, | |
-0.008531793400639134036800292904, | |
0.016157066691618496290239193058]) | |
aa = tensor.vector('aa') | |
bb = tensor.vector('bb') | |
ee = tensor.scalar() |
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
"""Demo of how to pop up plots asynchronously using separate processes.""" | |
from multiprocessing import Process | |
import time | |
import sys | |
import matplotlib.pyplot as plt | |
import numpy as np | |
def demo(): | |
i = 0 | |
processes = [] |