![pybrain](https://img-blog.csdnimg.cn/img_convert/cb3ffb3cdf45ad4e79eb8272d460b487.png)
pybrain
PyBrain-API和工具 (PyBrain - API & Tools)
Now we know how to build a network and train it. In this chapter, we will understand how to create and save the network, and use the network whenever required.
现在我们知道了如何建立网络并对其进行培训。 在本章中,我们将了解如何创建和保存网络,以及在需要时使用网络。
保存和恢复网络 (Save and Recover Network)
We are going to make use of NetworkWriter and NetworkReader from Pybrain tool, i.e., pybrain.tools.customxml.
我们将使用Pybrain工具中的NetworkWriter和NetworkReader,即pybrain.tools.customxml。
Here is a working example of the same −
这是相同的工作示例-
from pybrain.tools.shortcuts import buildNetwork
from pybrain.tools.customxml import NetworkWriter
from pybrain.tools.customxml import NetworkReader
net = buildNetwork(2,1,1)
NetworkWriter.writeToFile(net, 'network.xml')
net = NetworkReader.readFrom('network.xml')
The network is saved inside network.xml.
网络保存在network.xml中。
NetworkWriter.writeToFile(net, 'network.xml')
To read the xml when required we can use code as follows −
要在需要时读取xml,我们可以使用以下代码-
net = NetworkReader.readFrom('network.xml')
Here is the network.xml file created −
这是创建的network.xml文件-
<?xml version="1.0" ?>
<PyBrain>
<Network class="pybrain.structure.networks.feedforward.FeedForwardNetwork" name="FeedForwardNetwork-8">
<name val="'FeedForwardNetwork-8'"/>
<Modules>
<LinearLayer class="pybrain.structure.modules.linearlayer.LinearLayer" inmodule="True" name="in">
<name val="'in'"/>
<dim val="2"/>
</LinearLayer>
<LinearLayer class="pybrain.structure.modules.linearlayer.LinearLayer" name="out" outmodule="True">
<name val="'out'"/>
<dim val="1"/>
</LinearLayer>
<BiasUnit class="pybrain.structure.modules.biasunit.BiasUnit" name="bias">
<name val="'bias'"/>
</BiasUnit>
<SigmoidLayer class="pybrain.structure.modules.sigmoidlayer.SigmoidLayer" name="hidden0">
<name val="'hidden0'"/>
<dim val="1"/>
</SigmoidLayer>
</Modules>
<Connections>
<FullConnection class="pybrain.structure.connections.full.FullConnection" name="FullConnection-6">
<inmod val="bias"/>
<outmod val="out"/>
<Parameters>[1.2441093186965146]</Parameters>
</FullConnection>
<FullConnection class="pybrain.structure.connections.full.FullConnection" name="FullConnection-7">
<inmod val="bias"/>
<outmod val="hidden0"/>
<Parameters>[-1.5743530012126412]</Parameters>
</FullConnection>
<FullConnection class="pybrain.structure.connections.full.FullConnection" name="FullConnection-4">
<inmod val="in"/>
<outmod val="hidden0"/>
<Parameters>[-0.9429546042034236, -0.09858196752687162]</Parameters>
</FullConnection>
<FullConnection class="pybrain.structure.connections.full.FullConnection" name="FullConnection-5">
<inmod val="hidden0"/>
<outmod val="out"/>
<Parameters>[-0.29205472354634304]</Parameters>
</FullConnection>
</Connections>
</Network>
</PyBrain>
API (API)
Below is a list of APIs that we have used throughout this tutorial.
以下是我们在本教程中一直使用的API列表。
对于网络 (For Networks)
activate(input) − It takes parameter, i.e., the value to be tested. It will return back the result based on the input given.
activate(input) -接受参数,即要测试的值。 它将根据给定的输入返回结果。
activateOnDataset(dataset) − It will iterate over the dataset given and return the output.
activateOnDataset(dataset) -它将遍历给定的数据集并返回输出。
addConnection(c) − Adds connection to the network.
addConnection(c) -将连接添加到网络。
addInputModule(m) − Adds the module given to the network and mark it as an input module.
addInputModule(m) -添加给网络的模块并将其标记为输入模块。
addModule(m) − Adds the given module to the network.
addModule(m) -将给定的模块添加到网络。
addOutputModule(m) − Adds the module to the network and mark it as an output module.
addOutputModule(m) -将模块添加到网络并将其标记为输出模块。
reset() − Resets the modules and the network.
reset() -重置模块和网络。
sortModules() − It prepares the network for activation by sorting internally. It has to be called before activation.
sortModules() -它通过内部排序为激活准备网络。 必须在激活之前调用它。
对于监督数据集 (For Supervised Datasets)
addSample(inp, target) − Adds a new sample of input and target.
addSample(inp,target) -添加输入和目标的新样本。
splitWithProportion(proportion=0.5) − Divides dataset into two parts, the first part containing the proportion part data and the next set containing the remaining one.
splitWithProportion(proportion = 0.5) -将数据集分为两部分,第一部分包含比例部分数据,第二部分包含其余部分。
对于培训师 (For Trainers)
trainUntilConvergence(dataset=None, maxEpochs=None, verbose=None, continueEpochs=10, validationProportion=0.25) − It is used to train the module on the dataset until it converges. If dataset is not given, it will try to train on the trained dataset used at the start.
trainUntilConvergence(数据集=无,maxEpochs =无,冗长=无,continueEpochs = 10,validationProportion = 0.25) -用于训练数据集中的模块直至收敛。 如果未提供数据集,它将尝试在开始时使用经过训练的数据集进行训练。
翻译自: https://www.tutorialspoint.com/pybrain/pybrain_api_tools.htm
pybrain