Skip to content

Instantly share code, notes, and snippets.

@shackenberg
shackenberg / forward.py
Created September 9, 2013 11:54
Profile results for forward function in Theano using scan
from numpy import zeros, dot, exp, tanh, array, allclose
from numpy.random import randn
from copy import deepcopy
from time import time
from theano import tensor as T
from theano import function, shared, config, scan
FLOAT_PRECISION = config.floatX
class Network:
import numpy
import theano
import theano.tensor as TT
# number of hidden units
n = 50
# number of input units
nin = 5
# number of output units
nout = 5
@shackenberg
shackenberg / minimal.forward.example.theano.py
Last active December 21, 2015 22:39
Comparison of a forward function written in theano with the numpy version.
from numpy import zeros, dot, exp, tanh, array, allclose
from numpy.random import randn
from copy import deepcopy
from time import time
from theano import tensor as T
from theano import function, shared, config
"""Flags:
export THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32
ludwig@serv8:~/Theano$ theano-nose -v
/home/ludwig/Theano/theano/misc/pycuda_init.py:34: UserWarning: PyCUDA import failed in theano.misc.pycuda_init
warnings.warn("PyCUDA import failed in theano.misc.pycuda_init")
Using gpu device 0: GeForce GTX 670
test_grad (theano.compile.tests.test_builders.T_OpFromGraph) ... ok
test_size_changes (theano.compile.tests.test_builders.T_OpFromGraph) ... ok
test_straightforward (theano.compile.tests.test_builders.T_OpFromGraph) ... ok
test_aliased_outputs_bad (theano.compile.tests.test_debugmode.Test_ViewMap) ... ok
test_aliased_outputs_ok (theano.compile.tests.test_debugmode.Test_ViewMap) ... ok
test_aliased_outputs_ok_output (theano.compile.tests.test_debugmode.Test_ViewMap) ... ok
>>> theano.test()
Theano version 0.6.0rc3
theano is installed in /usr/local/lib/python2.7/dist-packages/theano
NumPy version 1.6.1
NumPy is installed in /usr/lib/python2.7/dist-packages/numpy
Python version 2.7.3 (default, Aug 1 2012, 05:14:39) [GCC 4.6.3]
nose version 1.1.2
Using gpu device 0: GeForce GTX 670
.........................................K.............../usr/local/lib/python2.7/dist-packages/theano/compile/tests/test_inplace_opt_for_value.py:170: UserWarning: theano modules are deprecated and will be removed in release 0.7
super(ExampleRNN, self).__init__()
THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32,exception_verbosity=high python jointest.py
Using gpu device 0: Quadro FX 580
WARNING (theano.sandbox.cuda): You are probably using an old GPU, that Theano does not support. This means GPU code will most likely be slow AND may crash when we try to use features that your GPU does not support.
1 #include <Python.h>
2 #include <iostream>
3 #include <numpy/arrayobject.h>
4 #include <math.h>
5 #include <numpy/arrayscalars.h>
6 #include "cuda_ndarray.cuh"
7 //////////////////////
#!/usr/bin/env python
"""
call this to run the code:
export CUDA_LAUNCH_BLOCKING=1
THEANO_FLAGS=mode=FAST_RUN,device=gpu,floatX=float32,exception_verbosity=high python jointest.py
"""
import theano
import theano.tensor as T
from numpy import *
@shackenberg
shackenberg / TimelineSpammers.py
Created December 6, 2012 17:44
Script to find the twitterer who are responsible for the most tweets in your timeline
from collections import Counter
from twython import Twython
import operator
app_key = 'XXX'
app_secret = 'XXX'
## init OAuth
t = Twython(app_key=app_key,
app_secret=app_secret)
@shackenberg
shackenberg / soupdownloader.py
Created September 19, 2012 21:23
soup.io image downloader / backup script
import feedparser
import urllib
d = feedparser.parse(XXX) # link to the soup.io rss feed
PATH = 'old_soup/'
print len(d.entries)
for entry in d.entries:
print entry['links'][0]['href']
if entry['links'][0]['type'] == u'image/jpeg':
@shackenberg
shackenberg / pbar
Last active October 10, 2015 16:07
super minimal progress bar (Python)
Code now at https://github.com/shackenberg/pbar.py