English 中文(简体)
PyBrain - Working with Networks
  • 时间:2024-09-17

PyBrain - Working With Networks


Previous Page Next Page  

A network is composed of modules, and they are connected using connections. In this chapter, we will learn to −

    Create Network

    Analyze Network

Creating Network

We are going to use python interpreter to execute our code. To create a network in pybrain, we have to use buildNetwork api as shown below −


C:pybrainpybrain>python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "pcense" for more information.
>>>
>>>
>>> from pybrain.tools.shortcuts import buildNetwork
>>> network = buildNetwork(2, 3, 1)
>>>

We have created a network using buildNetwork() and the params are 2, 3, 1 which means the network is made up of 2 inputs, 3 hidden and one single output.

Below are the details of the network, i.e., Modules and Connections −


C:pybrainpybrain>python
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "pcense" for more information.
>>> from pybrain.tools.shortcuts import buildNetwork
>>> network = buildNetwork(2,3,1)
>>> print(network)
FeedForwardNetwork-8
   Modules:
   [<BiasUnit  bias >, <LinearLayer  in >, <SigmoidLayer  hidden0 >,
<LinearLay er  out >]
   Connections:
   [<FullConnection  FullConnection-4 :  hidden0  ->  out >, <FullConnection  F
ullConnection-5 :  in  ->  hidden0 >, <FullConnection  FullConnection-6 :  bias 
-<  out >, <FullConnection  FullConnection-7 :  bias  ->  hidden0 >]
>>>

Modules consists of Layers, and Connection are made from FullConnection Objects. So each of the modules and connection are named as shown above.

Analyzing Network

You can access the module layers and connection inspanidually by referring to their names as follows −


>>> network[ bias ]
<BiasUnit  bias >
>>> network[ in ]
<LinearLayer  in >
Advertisements