LifelongClassificationNetwork¶
- class proglearn.LifelongClassificationNetwork(network, loss='categorical_crossentropy', optimizer=<keras.optimizer_v2.adam.Adam object>, epochs=100, batch_size=32, verbose=False, default_network_construction_proportion=0.67)[source]¶
A class for progressive learning using Lifelong Learning Networks in a classification setting.
- Parameters
network: Keras model
Transformer network used to map input to output.
loss: string
String name of the function used to calculate the loss between labels and predictions.
optimizer: str or instance of keras.optimizers
Algorithm used as the optimizer.
epochs: int
Number of times the entire training set is iterated over.
batch_size: int
Batch size used in the training of the network.
verbose: bool
Boolean indicating the production of detailed logging information during training of the network.
default_network_construction_proportion: float, default = 0.67
The proportions of the input data set aside to train each network. The remainder of the data is used to fill in voting posteriors. This is used if 'tree_construction_proportion' is not fed to add_task.
Attributes
task_id_to_X
(dict) A dictionary with keys of type obj corresponding to task ids and values of type ndarray corresponding to the input data matrix X. This dictionary thus maps input data matrix to the task where posteriors are to be estimated.
task_id_to_y
(dict) A dictionary with keys of type obj corresponding to task ids and values of type ndarray corresponding to output data matrix y. This dictionary thus maps output data matrix to the task where posteriors are to be estimated.
transformer_id_to_X
(dict) A dictionary with keys of type obj corresponding to transformer ids and values of type ndarray corresponding to the output data matrix X. This dictionary thus maps input data matrix to a particular transformer.
transformer_id_to_y
(dict) A dictionary with keys of type obj corresponding to transformer ids and values of type ndarray corresponding to the output data matrix y. This dictionary thus maps output data matrix to a particular transformer.
transformer_id_to_transformers
(dict) A dictionary with keys of type obj corresponding to transformer ids and values of type obj corresponding to a transformer. This dictionary thus maps transformer ids to the corresponding transformers.
task_id_to_trasnformer_id_to_voters
(dict) A nested dictionary with outer key of type obj, corresponding to task ids inner key of type obj, corresponding to transformer ids, and values of type obj, corresponding to a voter. This dictionary thus maps voters to a corresponding transformer assigned to a particular task.
task_id_to_decider
(dict) A dictionary with keys of type obj, corresponding to task ids, and values of type obj corresponding to a decider. This dictionary thus maps deciders to a particular task.
task_id_to_decider_class
(dict) A dictionary with keys of type obj corresponding to task ids and values of type obj corresponding to a decider class. This dictionary thus maps decider classes to a particular task id.
task_id_to_voter_class
(dict) A dictionary with keys of type obj corresponding to task ids and values of type obj corresponding to a voter class. This dictionary thus maps voter classes to a particular task id.
task_id_to_voter_kwargs
(dict) A dictionary with keys of type obj corresponding to task ids and values of type obj corresponding to a voter kwargs. This dictionary thus maps voter kwargs to a particular task id.
task_id_to_decider_kwargs
(dict) A dictionary with keys of type obj corresponding to task ids and values of type obj corresponding to a decider kwargs. This dictionary thus maps decider kwargs to a particular task id.
task_id_to_bag_id_to_voter_data_idx
(dict) A nested dictionary with outer keys of type obj corresponding to task ids inner keys of type obj corresponding to bag ids and values of type obj corresponding to voter data indices. This dictionary thus maps voter data indices to particular bags for particular tasks.
task_id_to_decider_idx
(dict) A dictionary with keys of type obj corresponding to task ids and values of type obj corresponding to decider indices. This dictionary thus maps decider indices to particular tasks.
default_transformer_class
(NeuralClassificationTransformer) The class of transformer to which the network defaults if None is provided in any of the functions which add or set transformers.
default_transformer_kwargs
(dict) A dictionary with keys of type string and values of type obj corresponding to the given string kwarg. This determines to which type of transformer the network defaults if None is provided in any of the functions which add or set transformers.
default_voter_class
(KNNClassificationVoter) The class of voter to which the network defaults if None is provided in any of the functions which add or set voters.
default_voter_kwargs
(dict) A dictionary with keys of type string and values of type obj corresponding to the given string kwarg. This determines to which type of voter the network defaults if None is provided in any of the functions which add or set voters.
default_decider_class
(SimpleArgmaxAverage) The class of decider to which the network defaults if None is provided in any of the functions which add or set deciders.
default_decider_kwargs
(dict) A dictionary with keys of type string and values of type obj corresponding to the given string kwarg. This determines to which type of decider the network defaults if None is provided in any of the functions which add or set deciders.
Methods Summary
adds a task with id task_id, given input data matrix X and output data matrix y, to the Lifelong Classification Network |
|
adds a transformer with id transformer_id, trained on given input data matrix, X and output data matrix, y, to the Lifelong Classification Network. |
|
|
Predicts class labels under task_id for each example in input data X. |
Estimates class posteriors under task_id for each example in input data X. |
|
- LifelongClassificationNetwork.add_task(X, y, task_id=None, network_construction_proportion='default')[source]¶
adds a task with id task_id, given input data matrix X and output data matrix y, to the Lifelong Classification Network
- Parameters
X: ndarray
Input data matrix.
y: ndarray
Output (response) data matrix.
task_id: obj
The id corresponding to the task being added.
network_construction_proportion: float or str, default='default'
The proportions of the input data set aside to train each network. The remainder of the data is used to fill in voting posteriors. The default is used if 'default' is provided.
- Returns
self : LifelongClassificationNetwork
The object itself.
- LifelongClassificationNetwork.add_transformer(X, y, transformer_id=None)[source]¶
adds a transformer with id transformer_id, trained on given input data matrix, X and output data matrix, y, to the Lifelong Classification Network. Also trains the voters and deciders from new transformer to previous tasks, and will train voters and deciders from this transformer to all new tasks.
- Parameters
X: ndarray
Input data matrix.
y: ndarray
Output (response) data matrix.
transformer_id: obj
The id corresponding to the transformer being added.
- Returns
self : LifelongClassificationNetwork
The object itself.
- LifelongClassificationNetwork.get_task_ids()¶
- LifelongClassificationNetwork.get_transformer_ids()¶
- LifelongClassificationNetwork.predict(X, task_id)[source]¶
Predicts class labels under task_id for each example in input data X.
- Parameters
X: ndarray
Input data matrix.
task_id: obj
The task on which you are interested in performing inference.
- Returns
y_hat : ndarray of shape [n_samples]
predicted class label per example
- LifelongClassificationNetwork.predict_proba(X, task_id)[source]¶
Estimates class posteriors under task_id for each example in input data X.
- Parameters
X: ndarray
Input data matrix.
task_id: obj
The task on which you are interested in estimating posteriors.
- Returns
y_proba_hat : ndarray of shape [n_samples, n_classes]
posteriors per example
- LifelongClassificationNetwork.set_decider(task_id, transformer_ids, decider_class=None, decider_kwargs=None)¶
- LifelongClassificationNetwork.set_transformer(transformer_id=None, transformer=None, transformer_data_idx=None, transformer_class=None, transformer_kwargs=None)¶
- LifelongClassificationNetwork.set_voter(transformer_id, task_id=None, voter_class=None, voter_kwargs=None, bag_id=None)¶