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

merged

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