Skip to content

Instantly share code, notes, and snippets.

View bayerj's full-sized avatar

Justin Bayer bayerj

View GitHub Profile
In [87]: A, B = np.ones((1, 2)), np.random.random((3, 3, 1))
In [88]: B
Out[88]:
array([[[ 0.02738198],
[ 0.23332334],
[ 0.12513209]],
[[ 0.48753864],
[ 0.45401342],
#! /usr/bin/env python
import numpy
import time
try:
import numpy.core._dotblas
print 'Using ATLAS:'
except ImportError:
print 'No ATLAS:'
print numpy.__version__
#! /usr/bin/env python
import numpy
import time
import sys
N = int(sys.argv[1])
try:
import numpy.core._dotblas
print 'Using ATLAS:'
X = predicted position
Z = true position
lds = our learned lds on [X, Z]
# Get marginal LDS
marginal_lds = marginal(lds, (7, 8, 9, 10, 11, 12, 13)) #
# Compile a function to calculate hidden state given position predictions.
f = marginal_lds.function(['inpt'], ['filtered_means'])
import spearmint
exp = spearmint.Experiment()
exp.add_variable('n_hiddens', min=1, max=100, type=int)
for i in range(100): # Do 100 trials.
id, args = exp.draw() # Get a new candidate; id is used as a handle for later pushing back results into the experiment.
cost = f(args) # Evaluate objective.
exp.push(id, cost) # Push results into the experiment so we get a new candidate based on those results in the next iteration.
import theano.tensor as T
x = T.matrix()
c = T.matrix()
s = T.switch(c, x, 0)
l = s.sum()
T.grad(l, x) # Assertion error...
@bayerj
bayerj / gist:4131398
Created November 22, 2012 14:19
ipython save image with pillow and display
from IPython.core.display import Image as image
from PIL import Image
def save_and_display(arr, fname):
pilimg = Image.fromarray(arr)
pilimg.save(fname)
return image(filename=fname, width=600)
In [1]: from collections import namedtuple
In [3]: p = namedtuple('p', ['bla'])
In [4]: pp = p(2)
In [5]: pp
Out[5]: p(bla=2)
In [6]: import pickle
In [7]: pickle.dumps(pp)
Out[7]: 'ccopy_reg\n_reconstructor\np0\n(c__main__\np\np1\nc__builtin__\ntuple\np2\n(I2\ntp3\ntp4\nRp5\n.'
@bayerj
bayerj / gist:4513419
Created January 11, 2013 19:45
This is unexpected behaviour when compiling a moving average function with numba. Not compiling it and using python+numpy works fine.
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-4-f143d352e435> in <module>()
----> 1 filtered = mean_filter(X, 10)
/Users/bayerj/anaconda/lib/python2.7/site-packages/numba/decorators.pyc in __call__(self, *args, **kwargs)
162 raise error.NumbaError("Expected %d arguments, got %d" % (
163 nargs, len(args)))
--> 164 return self.wrapper(self, *args, **kwargs)
165
tmp ❯❯❯ py importtheano.py
Vendor: continuumProduct: anacondapro
Message: trial mode expires in 27 days
WARNING (theano.gof.compilelock): Overriding existing lock by dead process '82054' (I am process '82104')
> /Users/bayerj/devel/Theano/theano/gof/cmodule.py(264)dlimport()
-> try:
(Pdb) s
> /Users/bayerj/devel/Theano/theano/gof/cmodule.py(265)dlimport()
-> print module_name
(Pdb) s