AlgorithmCollection#

class AlgorithmCollection(*args)[source]#

Bases: list

A collection for managing AlgorithmWrapper instances.

Provides both list-like and dict-like access to AlgorithmWrapper objects, with name-based lookup functionality. Inherits from list to provide standard list operations while adding dictionary-style key access.

Parameters:
*argsAlgorithmWrapper

Initial AlgorithmWrapper instances to add to the collection

Attributes:
Inherits all list attributes and methods
Raises:
TypeError

If non-AlgorithmWrapper instance is added

ValueError

If duplicate algorithm names are found

Notes

The collection maintains uniqueness of algorithm names and provides both index-based and name-based access to algorithms. This allows for flexible algorithm management in Brisk configurations.

Examples

Create a collection with algorithms:
>>> from brisk.configuration import AlgorithmWrapper
>>> alg1 = AlgorithmWrapper("linear", LinearRegression())
>>> alg2 = AlgorithmWrapper("rf", RandomForestClassifier())
>>> collection = AlgorithmCollection(alg1, alg2)
Access by index:
>>> collection[0]  # Returns first algorithm
Access by name:
>>> collection["linear"]  # Returns linear algorithm
append(item: AlgorithmWrapper) None[source]#

Add an AlgorithmWrapper to the collection.

Adds a new algorithm wrapper to the collection while ensuring that algorithm names remain unique. Validates that the item is an AlgorithmWrapper instance before adding.

Parameters:
itemAlgorithmWrapper

Algorithm wrapper to add to the collection

Raises:
TypeError

If item is not an AlgorithmWrapper instance

ValueError

If algorithm name already exists in collection

Notes

The method performs two validation checks: 1. Ensures the item is an AlgorithmWrapper instance 2. Checks that no algorithm with the same name already exists

Examples

Add a new algorithm:
>>> collection = AlgorithmCollection()
>>> alg = AlgorithmWrapper("svm", SVC())
>>> collection.append(alg)