Warning
the use the of a DB Adapter can reduce the performance of the Genetic Algorithm.
Pyevolve have a feature in which you can save the statistics of every generation in a database, file or call an URL with the statistics as param. You can use the database to plot evolution statistics graphs later. In this module, you’ll find the adapters above cited.
See also
DBBaseAdapter Class - The base class for all DB Adapters
If you want to create your own DB Adapter, you must subclass this class.
Parameter: | frequency – the the generational dump frequency |
---|
New in version 0.6: Added the DBBaseAdapter class.
Return the statistics identify
Return type: | identify string |
---|
Returns the frequency of statistical dump
Return type: | the generation interval of statistical dump |
---|
Insert the stats
Parameter: | ga_engine – the GA Engine |
---|
This method is called one time to do the initialization of the DB Adapter
Parameter: | ga_engine – the GA Engine |
---|
Sets the identify of the statistics
Parameter: | identify – the id string |
---|
Set the frequency of statistical dump
Parameter: | statsGenFreq – the generation interval of statistical dump |
---|
DBFileCSV Class - Adapter to dump statistics in CSV format
Inheritance diagram for DBAdapters.DBFileCSV:
>>> adapter = DBFileCSV(filename="file.csv", identify="run_01",
frequency = 1, reset = True)
param filename: | the CSV filename |
---|---|
param identify: | the identify of the run |
param frequency: | |
the generational dump frequency | |
param reset: | if is True, the file old data will be overwrite with the new |
New in version 0.6: Removed the stub methods and subclassed the DBBaseAdapter class.
Return the statistics identify
Return type: | identify string |
---|
Returns the frequency of statistical dump
Return type: | the generation interval of statistical dump |
---|
Inserts the stats into the CSV file
Parameter: | ga_engine – the GA Engine |
---|
Changed in version 0.6: The method now receives the ga_engine parameter.
Open the CSV file or creates a new file
Parameter: | ga_engine – the GA Engine |
---|
Changed in version 0.6: The method now receives the ga_engine parameter.
Sets the identify of the statistics
Parameter: | identify – the id string |
---|
Set the frequency of statistical dump
Parameter: | statsGenFreq – the generation interval of statistical dump |
---|
DBMySQLAdapter Class - Adapter to dump data in MySql database server
Inheritance diagram for DBAdapters.DBMySQLAdapter:
>>> dbadapter = DBMySQLAdapter("pyevolve_username", "password", identify="run1")
or
>>> dbadapter = DBMySQLAdapter(user="username", passwd="password",
... host="mysqlserver.com.br", port=3306, db="pyevolve_db")
When you run some GA for the first time, you need to create the database, for this, you must use the resetDB parameter as True.
This parameter will erase all the database tables and will create the new ones. The resetDB parameter is different from the resetIdentify parameter, the resetIdentify only erases the rows with the same “identify” name, and resetDB will drop and recreate the tables.
Parameters: |
|
---|
Create table using the Statistics class structure
Parameter: | stats – the statistics object |
---|
Return a cursor from the pool
Return type: | the cursor |
---|
Return the statistics identify
Return type: | identify string |
---|
Returns the frequency of statistical dump
Return type: | the generation interval of statistical dump |
---|
Inserts the statistics data to database
Parameter: | ga_engine – the GA Engine |
---|
Changed in version 0.6: The method now receives the ga_engine parameter.
Open the database connection
Parameter: | ga_engine – the GA Engine |
---|
Changed in version 0.6: The method now receives the ga_engine parameter.
Deletes de current structure and calls createStructure
Parameter: | stats – the statistics object |
---|
Sets the identify of the statistics
Parameter: | identify – the id string |
---|
Set the frequency of statistical dump
Parameter: | statsGenFreq – the generation interval of statistical dump |
---|
DBSQLite Class - Adapter to dump data in SQLite3 database format
Inheritance diagram for DBAdapters.DBSQLite:
>>> dbadapter = DBSQLite(identify="test")
When you run some GA for the first time, you need to create the database, for this, you must use the resetDB parameter:
>>> dbadapter = DBSQLite(identify="test", resetDB=True)
This parameter will erase all the database tables and will create the new ones. The resetDB parameter is different from the resetIdentify parameter, the resetIdentify only erases the rows with the same “identify” name.
Parameters: |
|
---|
Create table using the Statistics class structure
Parameter: | stats – the statistics object |
---|
Return a cursor from the pool
Return type: | the cursor |
---|
Return the statistics identify
Return type: | identify string |
---|
Returns the frequency of statistical dump
Return type: | the generation interval of statistical dump |
---|
Inserts the statistics data to database
Parameter: | ga_engine – the GA Engine |
---|
Changed in version 0.6: The method now receives the ga_engine parameter.
Open the database connection
Parameter: | ga_engine – the GA Engine |
---|
Changed in version 0.6: The method now receives the ga_engine parameter.
Deletes de current structure and calls createStructure
Parameter: | stats – the statistics object |
---|
Sets the identify of the statistics
Parameter: | identify – the id string |
---|
Set the frequency of statistical dump
Parameter: | statsGenFreq – the generation interval of statistical dump |
---|
DBURLPost Class - Adapter to call an URL with statistics
Inheritance diagram for DBAdapters.DBURLPost:
>>> dbadapter = DBURLPost(url="http://localhost/post.py", identify="test")
The parameters that will be sent is all the statistics described in the Statistics.Statistics class, and the parameters:
Note
see the Statistics.Statistics documentation.
Parameters: |
|
---|
New in version 0.6: Removed the stub methods and subclassed the DBBaseAdapter class.
Return the statistics identify
Return type: | identify string |
---|
Returns the frequency of statistical dump
Return type: | the generation interval of statistical dump |
---|
Sends the data to the URL using POST or GET
Parameter: | ga_engine – the GA Engine |
---|
Changed in version 0.6: The method now receives the ga_engine parameter.
Load the modules needed
Parameter: | ga_engine – the GA Engine |
---|
Changed in version 0.6: The method now receives the ga_engine parameter.
Sets the identify of the statistics
Parameter: | identify – the id string |
---|
Set the frequency of statistical dump
Parameter: | statsGenFreq – the generation interval of statistical dump |
---|
The DBVPythonGraph Class - A DB Adapter for real-time visualization using VPython
Inheritance diagram for DBAdapters.DBVPythonGraph:
Note
to use this DB Adapter, you must install VPython first.
>>> adapter = DBAdapters.DBVPythonGraph(identify="run_01", frequency = 1)
>>> ga_engine.setDBAdapter(adapter)
Parameters: |
|
---|
New in version 0.6: The DBVPythonGraph class.
Return the statistics identify
Return type: | identify string |
---|
Returns the frequency of statistical dump
Return type: | the generation interval of statistical dump |
---|
Plot the current statistics to the graphs
Parameter: | ga_engine – the GA Engine |
---|
Used internally to create a new display for VPython.
Parameters: |
|
---|---|
Return type: | the window (the return of gdisplay call) |
Imports the VPython module and creates the four graph windows
Parameter: | ga_engine – the GA Engine |
---|
Sets the identify of the statistics
Parameter: | identify – the id string |
---|
Set the frequency of statistical dump
Parameter: | statsGenFreq – the generation interval of statistical dump |
---|
DBXMLRPC Class - Adapter to dump statistics to a XML Remote Procedure Call
Inheritance diagram for DBAdapters.DBXMLRPC:
>>> adapter = DBXMLRPC(url="http://localhost:8000/", identify="run_01",
frequency = 1)
param url: | the URL of the XML RPC |
---|---|
param identify: | the identify of the run |
param frequency: | |
the generational dump frequency |
Note
The XML RPC Server must implement the insert method, wich receives a python dictionary as argument.
Example of an server in Python:
import xmlrpclib
from SimpleXMLRPCServer import SimpleXMLRPCServer
def insert(l):
print "Received statistics: %s" % l
server = SimpleXMLRPCServer(("localhost", 8000), allow_none=True)
print "Listening on port 8000..."
server.register_function(insert, "insert")
server.serve_forever()
New in version 0.6: The DBXMLRPC class.
Return the statistics identify
Return type: | identify string |
---|
Returns the frequency of statistical dump
Return type: | the generation interval of statistical dump |
---|
Calls the XML RPC procedure
Parameter: | ga_engine – the GA Engine |
---|
Changed in version 0.6: The method now receives the ga_engine parameter.
Open the XML RPC Server proxy
Parameter: | ga_engine – the GA Engine |
---|
Changed in version 0.6: The method now receives the ga_engine parameter.
Sets the identify of the statistics
Parameter: | identify – the id string |
---|
Set the frequency of statistical dump
Parameter: | statsGenFreq – the generation interval of statistical dump |
---|