DBAdapters – database adapters for statistics

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

Method GSimpleGA.GSimpleGA.setDBAdapter()
DB Adapters are set in the GSimpleGA Class.
class DBAdapters.DBFileCSV(filename='pyevolve.csv', identify=None, frequency=1, reset=True)

DBFileCSV Class - Adapter to dump statistics in CSV format

Example:
>>> 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
close()
Closes the CSV file handle
commit()
Stub
commitAndClose()
Commits and closes
insert(stats, population, generation)

Inserts the stats into the CSV file

Parameters:
open()
Open the CSV file or creates a new file
class DBAdapters.DBSQLite(dbname='pyevolve.db', identify=None, resetDB=False, resetIdentify=True, frequency=1, commit_freq=500)

DBSQLite Class - Adapter to dump data in SQLite3 database format

Example:
>>> 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:
  • dbname – the database filename
  • identify – the identify if the run
  • resetDB – if True, the database structure will be recreated
  • resetIdentify – if True, the identify with the same name will be overwrite with new data
  • frequency – the generational dump frequency
  • commit_freq – the commit frequency
close()
Close the database connection
commit()
Commit changes to database
commitAndClose()
Commit changes on database and closes connection
createStructure(stats)

Create table using the Statistics class structure

Parameter:stats – the statistics object
getCursor()

Return a cursor from the pool

Return type:the cursor
insert(stats, population, generation)

Inserts the statistics data to database

Parameters:
open()
Open the database connection
resetStructure(stats)

Deletes de current structure and calls createStructure

Parameter:stats – the statistics object
resetTableIdentify()
Delete all records on the table with the same Identify
class DBAdapters.DBURLPost(url, identify=None, frequency=100, post=True)

DBURLPost Class - Adapter to call an URL with statistics

Example:
>>> dbadapter = DBSQLite(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:

generation
The generation of the statistics
identify
The id specified by user

Note

see the Statistics.Statistics documentation.

Parameters:
  • url – the URL to be used
  • identify – the identify of the run
  • frequency – the generational dump frequency
  • post – if True, the POST method will be used, otherwise GET will be used.
close()
Stub
commit()
Stube
commitAndClose()
Stub
insert(stats, population, generation)

Sends the data to the URL using POST or GET

Parameters:
open()
Stub

Recent Blog Posts

Previous topic

Interaction – interaction module

Next topic

FunctionSlot – function slots module

This Page