提交 9b9602c6 authored 作者: James Bergstra's avatar James Bergstra

merge

...@@ -8,7 +8,7 @@ Release Notes ...@@ -8,7 +8,7 @@ Release Notes
Theano 0.1 Theano 0.1
========== ==========
*Release date: 2009-04-01* *Release date: 2009-04-02*
What works What works
---------- ----------
......
...@@ -42,7 +42,7 @@ What needs to be defined ...@@ -42,7 +42,7 @@ What needs to be defined
In order to be C-compatible, a Type must define several additional In order to be C-compatible, a Type must define several additional
methods, which all start with the ``c_`` prefix. The complete list can methods, which all start with the ``c_`` prefix. The complete list can
be found in the documentation for :api:`gof.Type`. Here, we'll focus on be found in the documentation for :api:`gof.type.Type`. Here, we'll focus on
the most important ones: the most important ones:
......
...@@ -146,7 +146,7 @@ Automatic wrapping ...@@ -146,7 +146,7 @@ Automatic wrapping
All nodes in the graph must be instances of ``Apply`` or ``Result``, but All nodes in the graph must be instances of ``Apply`` or ``Result``, but
``<Op subclass>.make_node()`` typically wraps constants to satisfy those ``<Op subclass>.make_node()`` typically wraps constants to satisfy those
constraints. For example, the :api:`tensor.add <theano.tensor.add>` constraints. For example, the :api:`tensor.add <theano.tensor.basic.add>`
Op instance is written so that: Op instance is written so that:
.. code-block:: python .. code-block:: python
......
...@@ -8,7 +8,6 @@ Contents ...@@ -8,7 +8,6 @@ Contents
.. toctree:: .. toctree::
:maxdepth: 2 :maxdepth: 2
index
introduction introduction
LICENSE LICENSE
install install
......
...@@ -125,7 +125,7 @@ Mac ...@@ -125,7 +125,7 @@ Mac
- Install some kind of BLAS library (TODO: how?) - Install some kind of BLAS library (TODO: how?)
- Set ``THEANO_BLAS_LDFLAGS to something which will link against said BLAS - Set ``THEANO_BLAS_LDFLAGS`` to something which will link against said BLAS
library. E.g., ``THEANO_BLAS_LDFLAGS='-lcblas -latlas -lgfortran'``. library. E.g., ``THEANO_BLAS_LDFLAGS='-lcblas -latlas -lgfortran'``.
This advice has not been tested recently, so please inform us of your results. This advice has not been tested recently, so please inform us of your results.
......
...@@ -23,6 +23,7 @@ Edit ``doc/index.txt`` to contain a link to what will be the download URL:: ...@@ -23,6 +23,7 @@ Edit ``doc/index.txt`` to contain a link to what will be the download URL::
Tag the release. The syntax is something like the following:: Tag the release. The syntax is something like the following::
hg tag Theano-0.X hg tag Theano-0.X
hg push
Now, package the release and move it to the static theano directory:: Now, package the release and move it to the static theano directory::
...@@ -30,7 +31,6 @@ Now, package the release and move it to the static theano directory:: ...@@ -30,7 +31,6 @@ Now, package the release and move it to the static theano directory::
cd .. cd ..
tar cvf Theano-0.X.tar Theano-0.X tar cvf Theano-0.X.tar Theano-0.X
gzip -9 Theano-0.X.tar gzip -9 Theano-0.X.tar
rm -Rf Theano-0.X
mv Theano-0.X.tar.gz www/theano_static/downloads/ mv Theano-0.X.tar.gz www/theano_static/downloads/
~/repos/theano/.hg/refresh-epydoc.sh ~/repos/theano/.hg/refresh-epydoc.sh
...@@ -42,7 +42,13 @@ directory:: ...@@ -42,7 +42,13 @@ directory::
Finally, use setuptools to register and upload the release:: Finally, use setuptools to register and upload the release::
cd Theano-0.X
python setup.py register sdist bdist_egg upload python setup.py register sdist bdist_egg upload
# If you get an error message about needing to be identified, then store
# your pypi information in ~/.pypirc
# You can remove this file after upload.
cd ..
rm -Rf Theano-0.X
I wrote the above without actually running it. This needs to be I wrote the above without actually running it. This needs to be
scrutinized when you are actually do a release. scrutinized when you are actually do a release.
......
...@@ -393,6 +393,12 @@ Here is an example showing how to use verify_grad: ...@@ -393,6 +393,12 @@ Here is an example showing how to use verify_grad:
>>> # ... >>> # ...
>>> tensor.verify_grad(Flatten(), [a_val]) >>> tensor.verify_grad(Flatten(), [a_val])
.. note::
Although ``verify_grad`` is defined in ``theano.tensor.basic``, unittests
should use the version of ``verify_grad`` defined in ``theano.tests.unittest_tools``.
This is simply a wrapper function which takes care of seeding the random
number generator appropriately before calling ``theano.tensor.basic.verify_grad``
makeTester and makeBroadcastTester makeTester and makeBroadcastTester
================================== ==================================
......
...@@ -11,7 +11,7 @@ from theano import gof ...@@ -11,7 +11,7 @@ from theano import gof
from theano.sparse.basic import _is_dense, _is_sparse, _is_dense_variable, _is_sparse_variable from theano.sparse.basic import _is_dense, _is_sparse, _is_dense_variable, _is_sparse_variable
from theano.sparse.basic import _mtypes, _mtype_to_str from theano.sparse.basic import _mtypes, _mtype_to_str
from theano.tests import unittest_tools from theano.tests import unittest_tools as utt
def eval_outputs(outputs): def eval_outputs(outputs):
...@@ -19,7 +19,7 @@ def eval_outputs(outputs): ...@@ -19,7 +19,7 @@ def eval_outputs(outputs):
class T_transpose(unittest.TestCase): class T_transpose(unittest.TestCase):
def setUp(self): def setUp(self):
unittest_tools.seed_rng() utt.seed_rng()
def test_transpose_csc(self): def test_transpose_csc(self):
sp = sparse.csc_matrix(sparse.eye(5,3)) sp = sparse.csc_matrix(sparse.eye(5,3))
...@@ -126,7 +126,7 @@ class T_Add(unittest.TestCase): ...@@ -126,7 +126,7 @@ class T_Add(unittest.TestCase):
class T_conversion(unittest.TestCase): class T_conversion(unittest.TestCase):
def setUp(self): def setUp(self):
unittest_tools.seed_rng() utt.seed_rng()
def test0(self): def test0(self):
a = tensor.as_tensor_variable(numpy.random.rand(5)) a = tensor.as_tensor_variable(numpy.random.rand(5))
...@@ -157,7 +157,7 @@ class T_conversion(unittest.TestCase): ...@@ -157,7 +157,7 @@ class T_conversion(unittest.TestCase):
import scipy.sparse as sp import scipy.sparse as sp
class test_structureddot(unittest.TestCase): class test_structureddot(unittest.TestCase):
def setUp(self): def setUp(self):
unittest_tools.seed_rng() utt.seed_rng()
def test_structuredot(self): def test_structuredot(self):
bsize = 2 bsize = 2
...@@ -193,7 +193,7 @@ class test_structureddot(unittest.TestCase): ...@@ -193,7 +193,7 @@ class test_structureddot(unittest.TestCase):
assert _is_dense(c) assert _is_dense(c)
assert numpy.all(outvals == c) assert numpy.all(outvals == c)
tensor.verify_grad(buildgraphCSC, [kernvals,imvals]) utt.verify_grad(buildgraphCSC, [kernvals,imvals])
## ##
# Test compressed-sparse row matrices ### # Test compressed-sparse row matrices ###
...@@ -215,7 +215,7 @@ class test_structureddot(unittest.TestCase): ...@@ -215,7 +215,7 @@ class test_structureddot(unittest.TestCase):
assert _is_dense(c) assert _is_dense(c)
assert numpy.all(outvals == c) assert numpy.all(outvals == c)
tensor.verify_grad( buildgraphCSR, [kernvals,imvals]) utt.verify_grad( buildgraphCSR, [kernvals,imvals])
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -20,7 +20,6 @@ from ..gof.python25 import partial ...@@ -20,7 +20,6 @@ from ..gof.python25 import partial
from .. import compile, printing from .. import compile, printing
from ..printing import pprint, Print from ..printing import pprint, Print
from ..tests import unittest_tools
### set up the external interface ### set up the external interface
from elemwise import Elemwise, DimShuffle, CAReduce, Sum from elemwise import Elemwise, DimShuffle, CAReduce, Sum
......
...@@ -5,86 +5,86 @@ from theano import tensor as T ...@@ -5,86 +5,86 @@ from theano import tensor as T
from theano import gof from theano import gof
import test_basic as TT import test_basic as TT
import numpy import numpy
from theano.tests import unittest_tools from theano.tests import unittest_tools as utt
from theano.tensor.nnet import * from theano.tensor.nnet import *
class T_sigmoid(unittest.TestCase): class T_sigmoid(unittest.TestCase):
def setUp(self): def setUp(self):
unittest_tools.seed_rng() utt.seed_rng()
def test_elemwise(self): def test_elemwise(self):
TT.verify_grad(sigmoid, [numpy.random.rand(3,4)]) utt.verify_grad(sigmoid, [numpy.random.rand(3,4)])
class T_softplus(unittest.TestCase): class T_softplus(unittest.TestCase):
def setUp(self): def setUp(self):
unittest_tools.seed_rng() utt.seed_rng()
def test_elemwise(self): def test_elemwise(self):
TT.verify_grad(softplus, [numpy.random.rand(3,4)]) utt.verify_grad(softplus, [numpy.random.rand(3,4)])
class T_Softmax(unittest.TestCase): class T_Softmax(unittest.TestCase):
def setUp(self): def setUp(self):
unittest_tools.seed_rng() utt.seed_rng()
def test0(self): def test0(self):
def f(a): def f(a):
return softmax(a)[:,0] return softmax(a)[:,0]
TT.verify_grad(f, [numpy.random.rand(3,4)]) utt.verify_grad(f, [numpy.random.rand(3,4)])
def test1(self): def test1(self):
def f(a): def f(a):
return softmax(a)[:,1] return softmax(a)[:,1]
TT.verify_grad(f, [numpy.random.rand(3,4)]) utt.verify_grad(f, [numpy.random.rand(3,4)])
def test2(self): def test2(self):
def f(a): def f(a):
return softmax(a)[:,2] return softmax(a)[:,2]
TT.verify_grad(f, [numpy.random.rand(3,4)]) utt.verify_grad(f, [numpy.random.rand(3,4)])
def test3(self): def test3(self):
def f(a): def f(a):
return softmax(a)[:,3] return softmax(a)[:,3]
TT.verify_grad(f, [numpy.random.rand(3,4)]) utt.verify_grad(f, [numpy.random.rand(3,4)])
class T_SoftmaxWithBias(unittest.TestCase): class T_SoftmaxWithBias(unittest.TestCase):
def setUp(self): def setUp(self):
unittest_tools.seed_rng() utt.seed_rng()
def test0(self): def test0(self):
def f(a, b): def f(a, b):
return softmax_with_bias(a, b)[:,0] return softmax_with_bias(a, b)[:,0]
TT.verify_grad(f, [numpy.random.rand(3,4), utt.verify_grad(f, [numpy.random.rand(3,4),
numpy.random.rand(4)]) numpy.random.rand(4)])
def test1(self): def test1(self):
def f(a, b): def f(a, b):
return softmax_with_bias(a, b)[:,1] return softmax_with_bias(a, b)[:,1]
TT.verify_grad(f, [numpy.random.rand(3,4), utt.verify_grad(f, [numpy.random.rand(3,4),
numpy.random.rand(4)]) numpy.random.rand(4)])
def test2(self): def test2(self):
def f(a, b): def f(a, b):
return softmax_with_bias(a, b)[:,2] return softmax_with_bias(a, b)[:,2]
TT.verify_grad(f, [numpy.random.rand(3,4), utt.verify_grad(f, [numpy.random.rand(3,4),
numpy.random.rand(4)]) numpy.random.rand(4)])
def test3(self): def test3(self):
def f(a, b): def f(a, b):
return softmax_with_bias(a, b)[:,3] return softmax_with_bias(a, b)[:,3]
TT.verify_grad(f, [numpy.random.rand(3,4), utt.verify_grad(f, [numpy.random.rand(3,4),
numpy.random.rand(4)]) numpy.random.rand(4)])
class T_CrossentropySoftmax1Hot(unittest.TestCase): class T_CrossentropySoftmax1Hot(unittest.TestCase):
def setUp(self): def setUp(self):
unittest_tools.seed_rng() utt.seed_rng()
def test0(self): def test0(self):
y_idx = [0,1,3] y_idx = [0,1,3]
def f(a, b): def f(a, b):
return crossentropy_softmax_1hot_with_bias(a, b, y_idx)[0] return crossentropy_softmax_1hot_with_bias(a, b, y_idx)[0]
TT.verify_grad(f, [numpy.random.rand(3,4), utt.verify_grad(f, [numpy.random.rand(3,4),
numpy.random.rand(4)]) numpy.random.rand(4)])
def test1(self): def test1(self):
y_idx = [0,1,3] y_idx = [0,1,3]
def f(a): def f(a):
return crossentropy_softmax_1hot(a, y_idx)[0] return crossentropy_softmax_1hot(a, y_idx)[0]
TT.verify_grad(f, [numpy.random.rand(3,4)]) utt.verify_grad(f, [numpy.random.rand(3,4)])
class T_prepend(unittest.TestCase): class T_prepend(unittest.TestCase):
def setUp(self): def setUp(self):
unittest_tools.seed_rng() utt.seed_rng()
def test0(self): def test0(self):
"""basic functionality""" """basic functionality"""
x=tensor.matrix('x') x=tensor.matrix('x')
...@@ -110,7 +110,7 @@ class T_prepend(unittest.TestCase): ...@@ -110,7 +110,7 @@ class T_prepend(unittest.TestCase):
class T_solve(unittest.TestCase): class T_solve(unittest.TestCase):
def setUp(self): def setUp(self):
self.rng = numpy.random.RandomState(unittest_tools.fetch_seed(666)) self.rng = numpy.random.RandomState(utt.fetch_seed(666))
def test0(self): def test0(self):
A=self.rng.randn(5,5) A=self.rng.randn(5,5)
......
...@@ -8,11 +8,11 @@ import test_basic as TT ...@@ -8,11 +8,11 @@ import test_basic as TT
import random import random
import numpy.random import numpy.random
from theano.tests import unittest_tools from theano.tests import unittest_tools as utt
class T_XlogX(unittest.TestCase): class T_XlogX(unittest.TestCase):
def setUp(self): def setUp(self):
unittest_tools.seed_rng() utt.seed_rng()
def test0(self): def test0(self):
x = as_tensor_variable([1, 0]) x = as_tensor_variable([1, 0])
...@@ -23,7 +23,7 @@ class T_XlogX(unittest.TestCase): ...@@ -23,7 +23,7 @@ class T_XlogX(unittest.TestCase):
# class Dummy(object): # class Dummy(object):
# def make_node(self, a): # def make_node(self, a):
# return [xlogx(a)[:,2]] # return [xlogx(a)[:,2]]
TT.verify_grad(xlogx, [numpy.random.rand(3,4)]) utt.verify_grad(xlogx, [numpy.random.rand(3,4)])
if __name__ == '__main__': if __name__ == '__main__':
......
import unittest import unittest
import numpy import numpy
import theano.tensor as T
import os, sys import os, sys
...@@ -40,3 +41,14 @@ def seed_rng(pseed=None): ...@@ -40,3 +41,14 @@ def seed_rng(pseed=None):
'instead of seed %i given as parameter' % (seed, pseed) 'instead of seed %i given as parameter' % (seed, pseed)
numpy.random.seed(seed) numpy.random.seed(seed)
return seed return seed
def verify_grad(op, pt, n_tests=2, rng=None, eps=1.0e-7, tol=0.0001):
"""
Wrapper for tensor/basic.py:verify_grad
Takes care of seeding the random number generator if None is given
"""
if rng is None:
seed_rng()
rng = numpy.random
T.verify_grad(op, pt, n_tests, rng, eps, tol)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论