Module Expr Str Assign NameStore Str ImportFrom alias ImportFrom alias ImportFrom alias alias alias FunctionDef arguments args NameParam NameParam NameParam defaults Num body Expr Str Return Call NameLoad GeneratorExp CompareLtE Call NameLoad BinOpSub NameLoad NameLoad NameLoad comprehension TupleStore NameStore NameStore Call NameLoad NameLoad NameLoad decorator_list FunctionDef arguments args NameParam NameParam NameParam NameParam defaults Num Num Num Dict body Expr Str Assign NameStore Call NameLoad BinOpMult ListLoad NameLoad NameLoad Assign NameStore Call NameLoad BinOpAdd Call NameLoad NameLoad ListLoad BinOpPow Num NameLoad Assign NameStore Call NameLoad BinOpPow NameLoad NameLoad keyword Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad Str Assign NameStore Call NameLoad BinOpPow NameLoad NameLoad keyword Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad Str Assign NameStore Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad Str Return Call NameLoad NameLoad NameLoad NameLoad keyword NameLoad decorator_list If CompareEq NameLoad Str body Expr Call NameLoad Call NameLoad Str
N/A N/A  A few tests for BorderSwipingNetworks
    >>> from pybrain import MotherConnection
    >>> from scipy import ones, array

We will use a simple 3-dimensional network:

    >>> dim = 3
    >>> size = 3
    >>> hsize = 1

It is possible to define some weights before construction:

    >>> predefined = {'outconn': MotherConnection(1)}
    >>> predefined['outconn']._setParameters([0.5])

Building it with the helper function below:

    >>> net = buildSimpleBorderSwipingNet(size, dim, hsize, predefined)
    >>> net.name
    'BorderSwipingNetwork-...

    >>> net.paramdim
    7

    >>> net.dims
    (3, 3, 3)


Did the weight get set correctly?

    >>> net.params[0]
    0.5

Now we'll set all weights to a sequence of values:

    >>> net._setParameters(array(range(net.paramdim))/10.+.1)
    >>> nearlyEqual(list(net.params), [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7])
    True

Now we want to use the same weights to build a bigger network

    >>> size2 = size + 2
    >>> net2 = buildSimpleBorderSwipingNet(size2, dim, hsize, net.predefined)

It has a few more parameters:

    >>> net2.paramdim
    12

But the values are the same than before except numerical differences.

    >>> nearlyEqual(list(net2.params), [0.1, 0.2, 0.3, 0.3, 0.4, 0.5, 0.4333, 0.40, 0.46666, 0.4142857, 0.6, 0.7])
    True

Let's attempt a couple of activations:

    >>> res = net.activate(array(range(net.indim))/10.)
    >>> res2 = net2.activate(array(range(net2.indim))/10.)
    >>> min(res), min(res2)
    (0.625..., 0.631...)

    >>> max(res), max(res2)
    (0.797..., 0.7999...)


 N/A __author__ Tom Schaul, tom@idsia.ch pybrain.tests runModuleTestSuite pybrain.structure.networks BorderSwipingNetwork pybrain ModuleMesh LinearLayer TanhLayer nearlyEqual N/A N/A lst1 lst2 tolerance N/A 0.001 N/A N/A Tell whether the itemwise differences of the two lists is never bigger
    than tolerance. N/A N/A all N/A N/A N/A abs N/A i j tolerance N/A N/A i j N/A zip lst1 lst2 N/A buildSimpleBorderSwipingNet N/A N/A size dim hsize predefined N/A 3 3 1 N/A N/A N/A  build a simple swiping network,of given size and dimension, using linear inputs and output N/A dims N/A tuple N/A N/A size dim N/A hdims N/A tuple N/A N/A list dims N/A N/A 2 dim N/A inmod N/A LinearLayer N/A size dim name input N/A inmesh N/A N/A ModuleMesh viewOnFlatLayer inmod dims inmesh N/A outmod N/A LinearLayer N/A size dim name output N/A outmesh N/A N/A ModuleMesh viewOnFlatLayer outmod dims outmesh N/A hiddenmesh N/A N/A ModuleMesh constructWithLayers TanhLayer hsize hdims hidden N/A N/A BorderSwipingNetwork inmesh hiddenmesh outmesh predefined predefined N/A N/A N/A __name__ __main__ N/A N/A N/A runModuleTestSuite N/A __import__ __main__