def writeNetwork(self, net, netroot): """ write a Network into a new XML node """ netroot.setAttribute('name', net.name) netroot.setAttribute('class', canonicClassString(net)) if net.argdict: self.writeArgs(netroot, net.argdict) # the modules mods = self.newChild(netroot, 'Modules') # first write the input modules (in order) for im in net.inmodules: self.writeModule(mods, im, True, im in net.outmodules) # now the output modules (in order) for om in net.outmodules: if om not in net.inmodules: self.writeModule(mods, om, False, True) # now the rest for m in net.modulesSorted: if m not in net.inmodules and m not in net.outmodules: self.writeModule(mods, m, False, False) # the motherconnections if len(net.motherconnections) > 0: mothers = self.newChild(netroot, 'MotherConnections') for m in net.motherconnections: self.writeBuildable(mothers, m) # the connections conns = self.newChild(netroot, 'Connections') for m in net.modulesSorted: for c in net.connections[m]: self.writeConnection(conns, c, False) if hasattr(net, "recurrentConns"): for c in net.recurrentConns: self.writeConnection(conns, c, True)
def writeNetwork(self, net, netroot): """ write a Network into a new XML node """ netroot.setAttribute('name', net.name) netroot.setAttribute('class', canonicClassString(net)) if net.argdict: self.writeArgs(netroot, net.argdict) # the modules mods = self.newChild(netroot, 'Modules') # first write the input modules (in order) for im in net.inmodules: self.writeModule(mods, im, True, im in net.outmodules) # now the output modules (in order) for om in net.outmodules: if om not in net.inmodules: self.writeModule(mods, om, False, True) # now the rest for m in net.modulesSorted: if m not in net.inmodules and m not in net.outmodules: self.writeModule(mods, m, False, False) # the motherconnections if len(net.motherconnections) > 0: mothers = self.newChild(netroot, 'MotherConnections') for m in net.motherconnections: self.writeBuildable(mothers, m) # the connections conns = self.newChild(netroot, 'Connections') for m in net.modulesSorted: for c in net.connections[m]: self.writeConnection(conns, c, False) if isinstance(net, RecurrentNetwork): for c in net.recurrentConns: self.writeConnection(conns, c, True)
def writeArgs(self, node, argdict): """ write a dictionnary of arguments """ for name, val in list(argdict.items()): if val != None: tmp = self.newChild(node, name) if isclass(val): s = canonicClassString(val) else: s = getattr(val, 'name', repr(val)) tmp.setAttribute('val', s)
def writeArgs(self, node, argdict): """ write a dictionnary of arguments """ for name, val in argdict.items(): if val != None: tmp = self.newChild(node, name) if isclass(val): s = canonicClassString(val) else: s = getattr(val, 'name', repr(val)) tmp.setAttribute('val', s)
def writeBuildable(self, rootnode, m): """ store the class (with path) and name in a new child. """ mname = m.__class__.__name__ mnode = self.newChild(rootnode, mname) mnode.setAttribute('name', m.name) mnode.setAttribute('class', canonicClassString(m)) if m.argdict: self.writeArgs(mnode, m.argdict) if m.paramdim > 0 and not isinstance(m, SharedConnection): self.writeParams(mnode, m.params) return mnode
def writeArgs(self, node, argdict): """ write a dictionnary of arguments """ for name, val in argdict.items(): if val != None: tmp = self.newChild(node, name) if isclass(val): s = canonicClassString(val) elif isinstance(val, ndarray): tmp.setAttribute('shape', 'x'.join([str(x) for x in val.shape])) tmp.setAttribute('dtype', str(val.dtype)) output = BytesIO() savetxt(output, val.view(float)) self.addTextNode(tmp, output.getvalue()) s = 'ndarray' else: s = getattr(val, 'name', repr(val)) tmp.setAttribute('val', s)