Skip to content

Commit

Permalink
Black-box optimizer interface adjustments in CMA and FEM.
Browse files Browse the repository at this point in the history
Some import fixes.
Pydev dependency ignore settings.
  • Loading branch information
schaul committed Oct 14, 2009
1 parent 0a784b7 commit 18828fd
Show file tree
Hide file tree
Showing 29 changed files with 6,182 additions and 6,274 deletions.
848 changes: 425 additions & 423 deletions arac/src/python/arac/cppbridge.py

Large diffs are not rendered by default.

724 changes: 362 additions & 362 deletions arac/src/python/arac/pybrainbridge.py

Large diffs are not rendered by default.

162 changes: 81 additions & 81 deletions arac/src/python/arac/tests/test_cppbridge.py
Original file line number Diff line number Diff line change
@@ -1,82 +1,82 @@
#! /usr/bin/env python2.5
# -*- coding: utf-8 -*

"""Unittests for the arac.pybrainbridge module."""


__author__ = 'Justin S Bayer, [email protected]'


import unittest
import scipy

import arac.cppbridge
from arac.tests.common import TestCase


class TestStructure(TestCase):

def testFullConnection(self):
params = scipy.array((1, 2, 3, 4), dtype='float64')
derivs = scipy.zeros(4, dtype='float64')
l1 = arac.cppbridge.LinearLayer(2)
l2 = arac.cppbridge.LinearLayer(2)
c = arac.cppbridge.FullConnection(l1, l2, params, derivs, 0, 2, 0, 2)

self.assertEqual(c.get_incomingstart(), 0)
self.assertEqual(c.get_incomingstop(), 2)
self.assertEqual(c.get_outgoingstart(), 0)
self.assertEqual(c.get_outgoingstop(), 2)

self.assert_(c.this is not None)

def testNetwork(self):
l1 = arac.cppbridge.LinearLayer(2)
l2 = arac.cppbridge.LinearLayer(2)

params = scipy.array((1, 2, 3, 4), dtype='float64')
derivs = scipy.zeros(4)
con = arac.cppbridge.FullConnection(l1, l2, params, derivs, 0, 2, 0, 2)
# con = arac.cppbridge.IdentityConnection(l1, l2, 0, 2, 0, 2)

net = arac.cppbridge.Network()
net.add_module(l1, arac.cppbridge.Network.InputModule)
net.add_module(l2, arac.cppbridge.Network.OutputModule)
net.add_connection(con)
inpt = scipy.array((3., 4.))
result = scipy.zeros(2)
net.activate(inpt, result)
self.assertArrayNear(result, scipy.array((11, 25)))

def testNetworkClear(self):
net = arac.cppbridge.Network()
l = arac.cppbridge.LinearLayer(1)
net.add_module(l, arac.cppbridge.Network.InputOutputModule)
inputbuffer = scipy.ones((1, 1))
outputbuffer = scipy.ones((1, 1))
inputerror = scipy.ones((1, 1))
outputerror = scipy.ones((1, 1))
net.init_input(inputbuffer)
net.init_output(outputbuffer)
net.init_inerror(inputerror)
net.init_outerror(outputerror)
net.clear()
self.assert_((inputbuffer == 0).all())
self.assert_((outputbuffer == 0).all())
self.assert_((inputerror == 0).all())
self.assert_((outputerror == 0).all())

def testCreateHugeModule(self):
s = 1000
l = arac.cppbridge.LinearLayer(s)
self.assertEqual(l.insize(), s)
self.assertEqual(l.outsize(), s)
l = arac.cppbridge.MdlstmLayer(1, s)
self.assertEqual(l.insize(), 5 * s)
self.assertEqual(l.outsize(), 2 * s)




if __name__ == "__main__":
#! /usr/bin/env python2.5
# -*- coding: utf-8 -*

"""Unittests for the arac.pybrainbridge module."""


__author__ = 'Justin S Bayer, [email protected]'


import unittest
import scipy

import arac.cppbridge #@UnresolvedImport
from arac.tests.common import TestCase #@UnresolvedImport


class TestStructure(TestCase):

def testFullConnection(self):
params = scipy.array((1, 2, 3, 4), dtype='float64')
derivs = scipy.zeros(4, dtype='float64')
l1 = arac.cppbridge.LinearLayer(2)
l2 = arac.cppbridge.LinearLayer(2)
c = arac.cppbridge.FullConnection(l1, l2, params, derivs, 0, 2, 0, 2)

self.assertEqual(c.get_incomingstart(), 0)
self.assertEqual(c.get_incomingstop(), 2)
self.assertEqual(c.get_outgoingstart(), 0)
self.assertEqual(c.get_outgoingstop(), 2)

self.assert_(c.this is not None)

def testNetwork(self):
l1 = arac.cppbridge.LinearLayer(2)
l2 = arac.cppbridge.LinearLayer(2)

params = scipy.array((1, 2, 3, 4), dtype='float64')
derivs = scipy.zeros(4)
con = arac.cppbridge.FullConnection(l1, l2, params, derivs, 0, 2, 0, 2)
# con = arac.cppbridge.IdentityConnection(l1, l2, 0, 2, 0, 2)

net = arac.cppbridge.Network()
net.add_module(l1, arac.cppbridge.Network.InputModule)
net.add_module(l2, arac.cppbridge.Network.OutputModule)
net.add_connection(con)
inpt = scipy.array((3., 4.))
result = scipy.zeros(2)
net.activate(inpt, result)
self.assertArrayNear(result, scipy.array((11, 25)))

def testNetworkClear(self):
net = arac.cppbridge.Network()
l = arac.cppbridge.LinearLayer(1)
net.add_module(l, arac.cppbridge.Network.InputOutputModule)
inputbuffer = scipy.ones((1, 1))
outputbuffer = scipy.ones((1, 1))
inputerror = scipy.ones((1, 1))
outputerror = scipy.ones((1, 1))
net.init_input(inputbuffer)
net.init_output(outputbuffer)
net.init_inerror(inputerror)
net.init_outerror(outputerror)
net.clear()
self.assert_((inputbuffer == 0).all())
self.assert_((outputbuffer == 0).all())
self.assert_((inputerror == 0).all())
self.assert_((outputerror == 0).all())

def testCreateHugeModule(self):
s = 1000
l = arac.cppbridge.LinearLayer(s)
self.assertEqual(l.insize(), s)
self.assertEqual(l.outsize(), s)
l = arac.cppbridge.MdlstmLayer(1, s)
self.assertEqual(l.insize(), 5 * s)
self.assertEqual(l.outsize(), 2 * s)




if __name__ == "__main__":
unittest.main()
Loading

0 comments on commit 18828fd

Please sign in to comment.