提交 43291f46 authored 作者: James Bergstra's avatar James Bergstra

merged

...@@ -23,16 +23,21 @@ class test_logistic_regression_example(unittest.TestCase): ...@@ -23,16 +23,21 @@ class test_logistic_regression_example(unittest.TestCase):
def test_example_main(self): def test_example_main(self):
"""Test that the file execute without trouble""" """Test that the file execute without trouble"""
from ..examples import logistic_regression import os
sys.path.append(os.path.realpath(".."))
import logistic_regression
logistic_regression.main() logistic_regression.main()
def test_example_moduleN(self): def test_example_moduleN(self):
"""Test that the LogisticRegressionN module execute the same with different mode""" """Test that the LogisticRegressionN module execute the same with different mode"""
from ..examples import logistic_regression import os
sys.path.append(os.path.realpath(".."))
import logistic_regression
pprint.assign(nnet.crossentropy_softmax_1hot_with_bias_dx, printing.FunctionPrinter('xsoftmaxdx')) pprint.assign(nnet.crossentropy_softmax_1hot_with_bias_dx, printing.FunctionPrinter('xsoftmaxdx'))
pprint.assign(nnet.crossentropy_softmax_argmax_1hot_with_bias, printing.FunctionPrinter('nll', 'softmax', 'argmax')) pprint.assign(nnet.crossentropy_softmax_argmax_1hot_with_bias, printing.FunctionPrinter('nll', 'softmax', 'argmax'))
lrc = logistic_regression.LogisticRegressionN() lrc = logistic_regression.LogisticRegressionN()
lr0 = lrc.make(10, 2, seed=1827)
lr1 = lrc.make(10, 2, mode=theano.Mode('c|py', 'fast_run'), seed=1827) lr1 = lrc.make(10, 2, mode=theano.Mode('c|py', 'fast_run'), seed=1827)
lr2 = lrc.make(10, 2, mode=theano.Mode('py', 'fast_run'), seed=1827) lr2 = lrc.make(10, 2, mode=theano.Mode('py', 'fast_run'), seed=1827)
lr3 = lrc.make(10, 2, mode=theano.Mode('py', 'merge'), seed=1827) #'FAST_RUN') lr3 = lrc.make(10, 2, mode=theano.Mode('py', 'merge'), seed=1827) #'FAST_RUN')
...@@ -45,41 +50,53 @@ class test_logistic_regression_example(unittest.TestCase): ...@@ -45,41 +50,53 @@ class test_logistic_regression_example(unittest.TestCase):
for i in xrange(1000): for i in xrange(1000):
lr.lr = 0.02 lr.lr = 0.02
xe = lr.update(data_x, data_y) xe = lr.update(data_x, data_y)
train(lr0)
train(lr1) train(lr1)
train(lr2) train(lr2)
train(lr3) train(lr3)
train(lr4) train(lr4)
assert lr1==lr2 assert lr0==lr1
assert lr1==lr3 assert lr0==lr2
assert lr1==lr4 assert lr0==lr3
assert lr0==lr4
def test_example_module2(self): def test_example_module2(self):
"""Test that the LogisticRegression2 module execute the same with different mode""" """Test that the LogisticRegression2 module execute the same with different mode"""
from ..examples import logistic_regression import os
sys.path.append(os.path.realpath(".."))
import logistic_regression
lrc = logistic_regression.LogisticRegression2() #TODO: test 2==N lrc = logistic_regression.LogisticRegression2() #TODO: test 2==N
lr0 = lrc.make(10,2) lr0 = lrc.make(10,1827)
# lr0 = lrc.make(10,2,seed=1827)#error lr1 = lrc.make(10, mode=theano.Mode('c|py', 'fast_run'), seed=1827)
# lr1 = lrc.make(10, 2, mode=theano.Mode('c|py', 'fast_run'), seed=1827) lr2 = lrc.make(10, mode=theano.Mode('py', 'fast_run'), seed=1827)
# lr2 = lrc.make(10, 2, mode=theano.Mode('py', 'fast_run'), seed=1827) lr3 = lrc.make(10, mode=theano.Mode('py', 'merge'), seed=1827) #'FAST_RU
# lr3 = lrc.make(10, 2, mode=theano.Mode('py', 'merge'), seed=1827) #'FAST_RU lr4 = lrc.make(10, mode=compile.FAST_RUN.excluding('fast_run'), seed=1827)
#FAST_RUN, FAST_COMPILE,
# lr4 = lrc.make(10, 2, mode=compile.FAST_RUN.excluding('fast_run'), seed=1827) data_x = N.random.randn(5, 10)
# #FAST_RUN, FAST_COMPILE, data_y = (N.random.randn(5) > 0)
# data_x = N.random.randn(5, 10) data_y = data_y.reshape((data_y.shape[0],1))#need to be a column
# data_y = (N.random.randn(5) > 0)
# def train(lr): def train(lr):
# for i in xrange(10000): for i in xrange(1000):
# lr.lr = 0.02 lr.lr = 0.02
# xe = lr.update(data_x, data_y) xe = lr.update(data_x, data_y)
# train(lr1)
# train(lr2) train(lr0)
# train(lr3) train(lr1)
# train(lr4) train(lr2)
train(lr3)
train(lr4)
assert lr0==lr1
assert lr0==lr2
assert lr0==lr3
assert lr0==lr4
# self.fail("NotImplementedError") # self.fail("NotImplementedError")
if __name__ == '__main__': if __name__ == '__main__':
from theano.tests import main from theano.tests import main
main("test_wiki") main(__file__)
...@@ -310,4 +310,4 @@ class T_test_wiki_module(unittest.TestCase): ...@@ -310,4 +310,4 @@ class T_test_wiki_module(unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
from theano.tests import main from theano.tests import main
main("test_wiki") main(__file__)
...@@ -15,11 +15,13 @@ def join(*args): ...@@ -15,11 +15,13 @@ def join(*args):
join('a', 'b', 'c') => 'a.b.c' join('a', 'b', 'c') => 'a.b.c'
""" """
return ".".join(arg for arg in args if arg) return ".".join(arg for arg in args if arg)
def split(sym, n=-1): def split(sym, n=-1):
""" """
Gets the names from their joined representation Gets the names from their joined representation
split('a.b.c') => 'a', 'b', 'c' split('a.b.c') => ['a', 'b', 'c']
Returns the n first names, if n==-1 returns all of them. Returns the n first names, if n==-1 returns all of them.
split('a.b.c',1) => ['a', 'b.c']
""" """
return sym.split('.', n) return sym.split('.', n)
...@@ -27,6 +29,7 @@ def canonicalize(name): ...@@ -27,6 +29,7 @@ def canonicalize(name):
""" """
Splits the name and converts each name to the Splits the name and converts each name to the
right type (e.g. "2" -> 2) right type (e.g. "2" -> 2)
[Fred: why we return the right type? Why int only?]
""" """
if isinstance(name, str): if isinstance(name, str):
name = split(name) name = split(name)
...@@ -48,6 +51,7 @@ class BindError(Exception): ...@@ -48,6 +51,7 @@ class BindError(Exception):
""" """
Exception raised when a Component is already bound and we try to Exception raised when a Component is already bound and we try to
bound it again. bound it again.
see Component.bind() help for more information.
""" """
pass pass
...@@ -103,6 +107,7 @@ class Component(object): ...@@ -103,6 +107,7 @@ class Component(object):
""" """
Populates the memo dictionary with Result -> Container Populates the memo dictionary with Result -> Container
pairings. pairings.
[Fred: what memo mean?]
""" """
raise NotImplementedError raise NotImplementedError
...@@ -112,6 +117,7 @@ class Component(object): ...@@ -112,6 +117,7 @@ class Component(object):
and taking the containers in the memo dictionary. and taking the containers in the memo dictionary.
A Component which builds nothing may return None. A Component which builds nothing may return None.
[Fred: why a Component would build nothing? Method? Member should always build something to my understanding]
""" """
raise NotImplementedError raise NotImplementedError
...@@ -180,11 +186,11 @@ class _RComponent(Component): ...@@ -180,11 +186,11 @@ class _RComponent(Component):
def __init__(self, r): def __init__(self, r):
super(_RComponent, self).__init__() super(_RComponent, self).__init__()
self.r = r self.r = r
self.owns_name = r.name is None self.owns_name = r.name is None #Fred: is not? else the choise of owns_name is bad.
def __set_name__(self, name): def __set_name__(self, name):
super(_RComponent, self).__set_name__(name) super(_RComponent, self).__set_name__(name)
if self.owns_name: if self.owns_name:# Fred: why only if it don't have name?
self.r.name = name self.r.name = name
def __str__(self): def __str__(self):
...@@ -195,7 +201,7 @@ class _RComponent(Component): ...@@ -195,7 +201,7 @@ class _RComponent(Component):
return rval return rval
def dup(self): def dup(self):
return self.__class__(self.r) return self.__class__(self.r)#Fred: this don't dup the results? Is that normal?
class External(_RComponent): class External(_RComponent):
...@@ -260,7 +266,7 @@ class Method(Component): ...@@ -260,7 +266,7 @@ class Method(Component):
Composite which holds references to Members, the Method may Composite which holds references to Members, the Method may
use them without declaring them in the inputs, outputs or use them without declaring them in the inputs, outputs or
updates list. updates list.
[Fred: what are kits? not defined in this file]
inputs, outputs or updates may be strings. In that case, they inputs, outputs or updates may be strings. In that case, they
will be resolved in the Composite which is the parent of this will be resolved in the Composite which is the parent of this
Method. Method.
......
"""Defines the `Type` class.""" """WRITEME Defines the `Type` class."""
__docformat__ = "restructuredtext en" __docformat__ = "restructuredtext en"
......
import unittest import unittest,sys
def main(modulename): def main(modulename):
debug = False
if 0: if 0:
unittest.main() unittest.main()
elif 1: elif len(sys.argv)==2 and sys.argv[1]=="--debug":
module = __import__(modulename) module = __import__(modulename)
tests = unittest.TestLoader().loadTestsFromModule(module) tests = unittest.TestLoader().loadTestsFromModule(module)
tests.debug() tests.debug()
elif len(sys.argv)==1:
module = __import__(modulename)
tests = unittest.TestLoader().loadTestsFromModule(module)
unittest.TextTestRunner(verbosity=2).run(tests)
else: else:
testcases = [] print "options: [--debug]"
testcases.append(T_function_module)
#<testsuite boilerplate>
testloader = unittest.TestLoader()
suite = unittest.TestSuite()
for testcase in testcases:
suite.addTest(testloader.loadTestsFromTestCase(testcase))
unittest.TextTestRunner(verbosity=2).run(suite)
#</boilerplate>
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论