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 as_pandas() (i.e. users typically do not create it on their own):

df = archive.as_pandas()

To iterate through every Elite, use:

for elite in df.iterelites():
    elite.sol
    elite.obj
    ...

There are also methods to access the solutions, objectives, etc. of all elites in the archive. For instance, the following is an array where entry i contains the behavior values of the i’th elite in the DataFrame:

df.batch_behaviors()

Warning

Accessing batch methods (e.g. batch_behaviors()) always creates a copy, so the following will copy the behaviors 3 times:

df.batch_behaviors()[0]
df.batch_behaviors().mean()
df.batch_behaviors().median()

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

behaviors = df.batch_behaviors()
behaviors[0]
behaviors.mean()
behaviors.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

All the batch methods “align” with each other – i.e. batch_behaviors()[i] corresponds to batch_indices()[i], batch_metadata()[i], batch_objectives()[i], and batch_solutions()[i].

Methods

batch_behaviors()

Array with behavior values of all elites.

batch_indices()

List of archive indices of all elites.

batch_metadata()

Array with metadata of all elites.

batch_objectives()

Array with objective values of all elites.

batch_solutions()

Array with solutions of all elites.

iterelites()

Iterator which outputs every Elite in the ArchiveDataFrame.

Attributes

batch_behaviors()[source]

Array with behavior values of all elites.

None if there are no behavior values in the ArchiveDataFrame.

Returns

See above.

Return type

(n, behavior_dim) numpy.ndarray

batch_indices()[source]

List of archive indices of all elites.

This is a list because each index is a tuple, and numpy arrays are not designed to store tuple objects.

None if there are no indices in the ArchiveDataFrame.

Returns

See above.

Return type

(n,) list

batch_metadata()[source]

Array with metadata of all elites.

None if there is no metadata (e.g. if include_metadata=False in as_pandas()).

Returns

See above.

Return type

(n,) numpy.ndarray

batch_objectives()[source]

Array with objective values of all elites.

None if there are no objectives in the ArchiveDataFrame.

Returns

See above.

Return type

(n,) numpy.ndarray

batch_solutions()[source]

Array with solutions of all elites.

None if there are no solutions (e.g. if include_solutions=False in as_pandas()).

Returns

See above.

Return type

(n, solution_dim) numpy.ndarray

iterelites()[source]

Iterator which outputs every Elite in the ArchiveDataFrame.

Data which is unavailable will be turned into None. For example, if there are no solution columns, then elite.sol will be None.