PyBrain Tutorial
Selected Reading
- PyBrain - Discussion
- PyBrain - Useful Resources
- PyBrain - Quick Guide
- PyBrain - Examples
- PyBrain - API & Tools
- PyBrain - Reinforcement Learning Module
- PyBrain - Connections
- PyBrain - Layers
- Training Network Using Optimization Algorithms
- PyBrain - Working with Recurrent Networks
- Working with Feed-Forward Networks
- PyBrain - Testing Network
- PyBrain - Training Datasets on Networks
- PyBrain - Importing Data For Datasets
- PyBrain - Datasets Types
- PyBrain - Working with Datasets
- PyBrain - Working with Networks
- PyBrain - Introduction to PyBrain Networks
- PyBrain - Environment Setup
- PyBrain - Overview
- PyBrain - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Training Network Using Optimization Algorithms
Training Network Using Optimization Algorithms
We have seen how to train a network using trainers in pybrain. In this chapter, will use optimization algorithms available with Pybrain to train a network.
In the example, we will use the GA optimization algorithm which needs to be imported as shown below −
from pybrain.optimization.populationbased.ga import GA
Example
Below is a working example of a training network using a GA optimization algorithm −
from pybrain.datasets.classification import ClassificationDataSet from pybrain.optimization.populationbased.ga import GA from pybrain.tools.shortcuts import buildNetwork # create XOR dataset ds = ClassificationDataSet(2) ds.addSample([0., 0.], [0.]) ds.addSample([0., 1.], [1.]) ds.addSample([1., 0.], [1.]) ds.addSample([1., 1.], [0.]) ds.setField( class , [ [0.],[1.],[1.],[0.]]) net = buildNetwork(2, 3, 1) ga = GA(ds.evaluateModuleMSE, net, minimize=True) for i in range(100): net = ga.learn(0)[0] print(net.activate([0,0])) print(net.activate([1,0])) print(net.activate([0,1])) print(net.activate([1,1]))
Output
The activate method on the network for the inputs almost matches with the output as shown below −
C:pybrainpybrainsrc>python example15.py [0.03055398] [0.92094839] [1.12246157] [0.02071285]Advertisements