ribs.archives.ArchiveDataFrame

class ribs.archives.ArchiveDataFrame(*args, **kwargs)[source]

A modified DataFrame for archive data.

As this class inherits from DataFrame, it has the same methods, attributes, and arguments (even though the arguments shown here are *args and **kwargs). However, this class adds methods that make it convenient to work with elites. This documentation only lists these additional methods and attributes.

Example

This object is created by data() (i.e. users typically do not create it on their own):

df = archive.data(..., return_type="pandas")

To iterate through every elite as a dict, use:

for elite in df.iterelites():
    elite["solution"]  # Shape: (solution_dim,)
    elite["objective"]
    ...

Arrays corresponding to individual fields can be accessed with get_field(). For instance, the following is an array where entry i contains the measures of the i’th elite in the DataFrame:

df.get_field("measures")

Warning

Calling get_field() always creates a copy, so the following will copy the measures 3 times:

df.get_field("measures")[0]
df.get_field("measures").mean()
df.get_field("measures").median()

Thus, if you need to use the method several times, we recommend storing it first, like so:

measures = df.get_field("measures")
measures[0]
measures.mean()
measures.median()

Note

After saving an ArchiveDataFrame to a CSV, loading it with pandas.read_csv() will load a DataFrame. To load a CSV as an ArchiveDataFrame, pass the DataFrame from read_csv to ArchiveDataFrame:

df = ArchiveDataFrame(pd.read_csv("file.csv"))

Note

Results of get_field() “align” with each other – e.g. get_field("measures")[i] corresponds to get_field("index")[i], get_field("objective")[i], and get_field("solution")[i].

Methods

get_field(field)

Array holding the data for the given field.

iterelites()

Iterator that outputs every elite in the ArchiveDataFrame as a dict.

Attributes

get_field(field)[source]

Array holding the data for the given field.

None if there is no data for the field.

iterelites()[source]

Iterator that outputs every elite in the ArchiveDataFrame as a dict.