bayerj / arac

C++ library for neural networks.
Other
39 stars 57 forks source link

Not compatible with PyBrain 0.3.1 #15

Open NicholasWalton opened 12 years ago

NicholasWalton commented 12 years ago

PyBrain 0.3 works fine.

Procedure: Install PyBrain 0.3.1 Run test_pybrainbridge.py

Expected result: All tests pass

Observed result: 13 tests fail with identical exceptions.

======================================================================
ERROR: testCopyable (__main__.TestNetworkEquivalence)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/nicholas/src/arac/src/python/arac/tests/test_pybrainbridge.py", line 348, in testCopyable
    copied = net.copy()
  File "/home/nicholas/src/arac/src/python/arac/pybrainbridge.py", line 266, in copy
    result.sortModules()
  File "/home/nicholas/src/pybrain/pybrain/structure/networks/recurrent.py", line 137, in sortModules
    super(RecurrentNetworkComponent, self).sortModules()
  File "/home/nicholas/src/arac/src/python/arac/pybrainbridge.py", line 274, in sortModules
    super(_Network, self).sortModules()
  File "/home/nicholas/src/pybrain/pybrain/structure/networks/network.py", line 259, in sortModules
    Module.__init__(self, self.indim, self.outdim, name=self.name)
  File "/home/nicholas/src/pybrain/pybrain/structure/modules/module.py", line 51, in __init__
    self._resetBuffers()
  File "/home/nicholas/src/pybrain/pybrain/structure/networks/network.py", line 263, in _resetBuffers
    super(Network, self)._resetBuffers(length)
  File "/home/nicholas/src/pybrain/pybrain/structure/modules/module.py", line 58, in _resetBuffers
    self.offset = 0
AttributeError: can't set attribute
o-v-o commented 11 years ago

I had this problem a while ago. I guess it happens because the attribute offset of the module class is replaced by a property in the arac wrapper class _Network ( which is in the file pybrainbridge.py) and this property is read only i.e. has no setter. I added a setter

    @offset.setter
    def offset(self, value):
        pass

below the following lines of code in _Network:

    @property
    def offset(self):
        return self.proxies[self].timestep()

This fixed the AttributeError regarding offset for me and I was able to train networks, but I hardly used pybrain and arac and therefore have not tested if an empty setter does not break certain parts of pybrain <-> arac interaction, but maybe someone might find this info helpful.

ypxie commented 8 years ago

add a function to component.cpp

void
Component::set_timestep(int value)
{
    _timestep = value;
    return ;
}

add the function declaration in component.h

then in pybrainbridge.py

add the following :

    @property
    def offset(self):
        return self.proxies.handle(self).timestep()

    @offset.setter
    def offset(self, value):  
        self.proxies.handle(self).set_timestep(int(value))

the original self.proxies(self) does not work.

Then the uncompatibility should be fixed.