How To Save The Network In XML File Using PyBrain
In this article, we are going to see how to save the network in an XML file using PyBrain in Python.
A network consists of several modules. These modules are generally connected with connections. PyBrain provides programmers with the support of neural networks. A network can be interpreted as an acyclic directed graph where each module serves the purpose of vertex/node and connections are assumed to edge.
Creating a Network
To create a network, PyBrain provides us with pybrain.tools.shortcuts. We can import buildNetwork shortcuts from this. The source code is given below,
[<BiasUnit ‘bias’>, <LinearLayer ‘in’>, <SigmoidLayer ‘hidden0’>, <LinearLayer ‘out’>]
[<FullConnection ‘FullConnection-4’: ‘hidden0’ -> ‘out’>, <FullConnection ‘FullConnection-5’: ‘in’ -> ‘hidden0’>, <FullConnection ‘FullConnection-6’: ‘bias’ -> ‘out’>, <FullConnection ‘FullConnection-7’: ‘bias’ -> ‘hidden0’>]
Saving the created network in an XML file
we can use NetworkWriter library from pybrain.tools.customxml. It provides us writeToFile() function whose syntax is given below,
- writeToFile(network, xml_file)
- network: The created network
- xml_file: The name of the xml file with extension
This function will first create an XML file with the name passed as the parameter to the function and save the created myNetwork in it.
Below is the complete implementation:
As you can see in the output, the myNetwork.XML file is generated by executing the below code.
Please Login to comment...