def buildSharedCrossedNetwork(): """ build a network with shared connections. Two hiddne modules are symetrically linked, but to a different input neuron than the output neuron. The weights are random. """ N = FeedForwardNetwork('shared-crossed') h = 1 a = LinearLayer(2, name='a') b = LinearLayer(h, name='b') c = LinearLayer(h, name='c') d = LinearLayer(2, name='d') N.addInputModule(a) N.addModule(b) N.addModule(c) N.addOutputModule(d) m1 = MotherConnection(h) m1.params[:] = scipy.array((1, )) m2 = MotherConnection(h) m2.params[:] = scipy.array((2, )) N.addConnection(SharedFullConnection(m1, a, b, inSliceTo=1)) N.addConnection(SharedFullConnection(m1, a, c, inSliceFrom=1)) N.addConnection(SharedFullConnection(m2, b, d, outSliceFrom=1)) N.addConnection(SharedFullConnection(m2, c, d, outSliceTo=1)) N.sortModules() return N
def _buildDirectLink(self, inmesh, outmesh): if not 'directconn' in self.predefined: self.predefined['directconn'] = MotherConnection( inmesh.componentOutdim * outmesh.componentIndim, 'inconn') for unit in self._iterateOverUnits(): self.addConnection( SharedFullConnection(self.predefined['directconn'], inmesh[unit], outmesh[unit]))
def _linkToAll(self, inmod, mesh, conn): for unit in self._iterateOverUnits(): self.addConnection(SharedFullConnection(conn, inmod, mesh[unit]))