提交 fb8ac54c authored 作者: Razvan Pascanu's avatar Razvan Pascanu

tests from paper + font changed to the numexpr plot

上级 8f094db5
...@@ -150,38 +150,35 @@ def execs_timeit_2vector(exprs, fname=None): ...@@ -150,38 +150,35 @@ def execs_timeit_2vector(exprs, fname=None):
assert len(colors)>=len(times) assert len(colors)>=len(times)
fig = pylab.figure() fig = pylab.figure()
for idx,(time,expr) in enumerate(zip(times,str_expr)): for idx,(time,expr) in enumerate(zip(times,str_expr)):
###
###
###
# Creating each subplot
###
###
###
###
pylab.subplot(220+idx+1) pylab.subplot(220+idx+1)
pylab.subplots_adjust(wspace=0.25, hspace=0.25) pylab.subplots_adjust(wspace=0.25, hspace=0.25)
#legend=[] #legend=[]
#plot = fig.add_subplot(1,len(exprs),idx) #plot = fig.add_subplot(1,len(exprs),idx)
speedup = [t[0].min()/t[1].min() for t in time] speedup = [t[0].min()/t[1].min() for t in time]
pylab.semilogx(nb_calls, speedup, linewidth=1.0, linestyle = '--', color='r') pylab.semilogx(nb_calls, speedup, linewidth=1.0, linestyle = '--', color='r')
speedup = [t[0].min()/t[2].min() for t in time] speedup = [t[0].min()/t[2].min() for t in time]
pylab.semilogx(nb_calls, speedup, linewidth=1.0, color = 'b') pylab.semilogx(nb_calls, speedup, linewidth=1.0, color = 'b')
pylab.grid(True) pylab.grid(True)
if (idx == 2) or (idx == 3): if (idx == 2) or (idx == 3):
pylab.xlabel('Dimension of vectors a and b') pylab.xlabel('Dimension of vectors a and b', fontsize = 15)
if (idx == 0) or (idx == 2): if (idx == 0) or (idx == 2):
pylab.ylabel('Speed up vs NumPy') pylab.ylabel('Speed up vs NumPy', fontsize = 15)
pylab.axhline(y=1, linewidth=1.0, color='black') pylab.axhline(y=1, linewidth=1.0, color='black')
pylab.xlim(1e3,1e7) pylab.xlim(1e3,1e7)
pylab.xticks([1e3,1e5,1e7],['1e3','1e5','1e7']) pylab.xticks([1e3,1e5,1e7],['1e3','1e5','1e7'])
pylab.title(expr) pylab.title(expr)
#for time,expr,color in zip(times,str_expr,colors):
# speedup = [t[0].min()/t[1].min() for t in time]
# plot.semilogx(nb_calls, speedup, linewidth=1.0, linestyle='--', color=color)
# speedup = [t[0].min()/t[2].min() for t in time]
# plot.semilogx(nb_calls, speedup, linewidth=1.0, color=color)
#legend += ["Numexpr "+expr,"Theano "+expr]
#pylab.title('Speed up Numexpr and Theano vs NumPy')
#pylab.grid(True)
#pylab.xlabel('Nb element')
#pylab.ylabel('Speed up vs NumPy')
#pylab.legend(legend,loc='upper left')
# fig.legend(legend,loc='upper left')
if fname: if fname:
fig.savefig(fname) fig.savefig(fname)
......
from nose.plugins.skip import SkipTest
import unittest
import theano
import numpy
import random
import numpy.random
from theano.tests import unittest_tools as utt
'''
Different tests that are not connected to any particular Op, or functionality of
Theano. Here will go for example code that we will publish in papers, that we
should ensure that it will remain operational
'''
class T_diverse(unittest.TestCase):
def setUp(self):
utt.seed_rng()
def scipy_paper_example1(self):
a = theano.tensor.vector('a') # declare variable
b = a + a**10 # build expression
f = theano.function([a], b) # compile function
assert numpy.all(f([0,1,2]) == numpy.array([0,2,1026]))
def scipy_papaer_example2(self):
''' This just sees if things compile well and if they run '''
x = T.matrix()
y = T.vector()
w = shared(rng.randn(100))
b = shared(numpy.zeros(()))
# Construct Theano expression graph
p_1 = 1 / (1 + T.exp(-T.dot(x, w)-b))
xent = -y*T.log(p_1) - (1-y)*T.log(1-p_1)
prediction = p_1 > 0.5
cost = xent.mean() + 0.01*(w**2).sum()
gw,gb = T.grad(cost, [w,b])
# Compile expressions to functions
train = function(
inputs=[x,y],
outputs=[prediction, xent],
updates={w:w-0.1*gw, b:b-0.1*gb})
predict = function(inputs=[x], outputs=prediction)
N = 4
feats = 100
D = (rng.randn(N, feats), rng.randint(size=4,low=0, high=2))
training_steps = 10
for i in range(training_steps):
pred, err = train(D[0], D[1])
if __name__ == '__main__':
unittest.main()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论