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.
Parameters: | frequency – the the generational dump frequency |
---|
New in version 0.6: Added the DBBaseAdapter class.
This method is called at the end of the evolution, to closes the DB Adapter and commit the changes
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
Parameters: | ga_engine – the GA Engine |
---|
This method is called one time to do the initialization of the DB Adapter
Parameters: | ga_engine – the GA Engine |
---|
Sets the identify of the statistics
Parameters: | identify – the id string |
---|
Set the frequency of statistical dump
Parameters: | 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.
Closes the CSV file handle
Commits and closes
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
Parameters: | 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
Parameters: | ga_engine – the GA Engine |
---|
Changed in version 0.6: The method now receives the ga_engine parameter.
Sets the identify of the statistics
Parameters: | identify – the id string |
---|
Set the frequency of statistical dump
Parameters: | 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: |
|
---|
Close the database connection
Commit changes to database
Commit changes on database and closes connection
Create table using the Statistics class structure
Parameters: | 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
Parameters: | ga_engine – the GA Engine |
---|
Changed in version 0.6: The method now receives the ga_engine parameter.
Open the database connection
Parameters: | 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
Parameters: | stats – the statistics object |
---|
Delete all records on the table with the same Identify
Sets the identify of the statistics
Parameters: | identify – the id string |
---|
Set the frequency of statistical dump
Parameters: | 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: |
|
---|
Close the database connection
Commit changes to database
Commit changes on database and closes connection
Create table using the Statistics class structure
Parameters: | 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
Parameters: | ga_engine – the GA Engine |
---|
Changed in version 0.6: The method now receives the ga_engine parameter.
Open the database connection
Parameters: | 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
Parameters: | stats – the statistics object |
---|
Delete all records on the table with the same Identify
Sets the identify of the statistics
Parameters: | identify – the id string |
---|
Set the frequency of statistical dump
Parameters: | 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.
This method is called at the end of the evolution, to closes the DB Adapter and commit the changes
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
Parameters: | ga_engine – the GA Engine |
---|
Changed in version 0.6: The method now receives the ga_engine parameter.
Load the modules needed
Parameters: | ga_engine – the GA Engine |
---|
Changed in version 0.6: The method now receives the ga_engine parameter.
Sets the identify of the statistics
Parameters: | identify – the id string |
---|
Set the frequency of statistical dump
Parameters: | 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.
This method is called at the end of the evolution, to closes the DB Adapter and commit the changes
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
Parameters: | 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
Parameters: | ga_engine – the GA Engine |
---|
Sets the identify of the statistics
Parameters: | identify – the id string |
---|
Set the frequency of statistical dump
Parameters: | 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.
This method is called at the end of the evolution, to closes the DB Adapter and commit the changes
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
Parameters: | ga_engine – the GA Engine |
---|
Changed in version 0.6: The method now receives the ga_engine parameter.
Open the XML RPC Server proxy
Parameters: | ga_engine – the GA Engine |
---|
Changed in version 0.6: The method now receives the ga_engine parameter.
Sets the identify of the statistics
Parameters: | identify – the id string |
---|
Set the frequency of statistical dump
Parameters: | statsGenFreq – the generation interval of statistical dump |
---|