neuraxle.metaopt.data.aggregates

Module-level documentation for neuraxle.metaopt.data.aggregates. Here is an inheritance diagram, including dependencies to other base modules of Neuraxle:


Neuraxle’s AutoML Scope Manager Classes

Scope manager objects used by AutoML algorithm classes.

Although the name “manager” for a class is disliked by the Neuraxle community, it is used as these are Pythonic context managers, as described in Python’s contextlib documentation.

Classes are splitted like this for the AutoML:

  • Projects

  • Clients

  • Rounds (runs)

  • Trials

  • TrialSplits

  • MetricResults

Classes

BaseAggregate(_dataclass, context[, is_deep])

Base class for aggregated objects using the repo and the dataclasses to manipulate them.

Client(_dataclass, context[, is_deep])

MetricResults(_dataclass, context[, is_deep])

Project(_dataclass, context[, is_deep])

Root(_dataclass, context[, is_deep])

Round(_dataclass, context[, is_deep])

Trial(_dataclass, context[, is_deep])

This class is a sub-contextualization of the HyperparameterRepository class for holding a trial and manipulating it within its context.

TrialSplit(_dataclass, context[, is_deep])

One split of a trial.


neuraxle.metaopt.data.aggregates._with_method_as_context_manager(func: Callable[[BaseAggregate], BaseAggregate]) → Callable[[neuraxle.metaopt.data.aggregates.BaseAggregate], AbstractContextManager[SubAggregateT]][source]

This is a method to be used as a context manager. This will sync items with the repos. Example:

See also

neuraxle.metaopt.data.aggregates.BaseAggregate neuraxle.metaopt.data.aggregates.BaseAggregate.__enter__() neuraxle.metaopt.data.aggregates.BaseAggregate.__exit__() neuraxle.metaopt.auto_ml.Trainer neuraxle.metaopt.auto_ml.Trainer.train()

class neuraxle.metaopt.data.aggregates.BaseAggregate(_dataclass: SubDataclassT, context: neuraxle.metaopt.context.AutoMLContext, is_deep=False, parent: ParentAggregateT = None)[source]

Bases: neuraxle.metaopt.data.reporting.BaseReport, neuraxle.base._CouldHaveContext, neuraxle.base.BaseService, contextlib.AbstractContextManager, typing.Generic

Base class for aggregated objects using the repo and the dataclasses to manipulate them. An aggregate is also a report, and can be used as a context manager for managing their children dataclasses, acting like a tape logging the information to the AutoML repositories.

For more information, read this article by Martin Fowler on DDD Aggregates.

See also

neuraxle.metaopt.data.vanilla.ScopedLocation neuraxle.metaopt.data.vanilla.BaseDataclass neuraxle.metaopt.data.vanilla.HyperparamsRepository neuraxle.metaopt.data.vanilla.AutoMLContext neuraxle.metaopt.data.reporting.BaseReport

__init__(_dataclass: SubDataclassT, context: neuraxle.metaopt.context.AutoMLContext, is_deep=False, parent: ParentAggregateT = None)[source]

Initialize self. See help(type(self)) for accurate signature.

static from_context(context: neuraxle.metaopt.context.AutoMLContext, is_deep=True) → neuraxle.metaopt.data.aggregates.BaseAggregate[source]

Return an aggregate from a context. Requirement: Have already pre-push the attr of dataclass into the context before calling this.

classmethod dummy(context: neuraxle.metaopt.context.AutoMLContext = None) → neuraxle.metaopt.data.aggregates.BaseAggregate[source]

Create a dummy object of the desired type for testing purposes. The parent subtree will be created in a temporary repository, or in a real repository if the context is provided.

_invariant()[source]
without_context() → neuraxle.metaopt.data.aggregates.BaseAggregate[source]

Return a copy of this aggregate without the context. Useful for initializing a temporary aggregate, such as a filtered or reduced aggregate without all its subaggregates to disallow saving the reduced aggregate.

flow
repo
subaggregate(_dataclass: SubDataclassT, context: neuraxle.metaopt.context.AutoMLContext, is_deep=False, parent: ParentAggregateT = None) → SubAggregateT[source]
parent
parentaggregate
report
dataclass
subdataclass
refresh(deep: bool = True)[source]
save(deep: bool = True) → neuraxle.metaopt.data.aggregates.BaseAggregate[source]
save_subaggregate(subagg: SubAggregateT, deep=False) → neuraxle.metaopt.data.aggregates.BaseAggregate[source]
managed_subresource(*args, **kwds) → SubAggregateT[source]

This is a method to be used as a context manager. This will sync items with the repos. Example:

See also

neuraxle.metaopt.data.aggregates.BaseAggregate neuraxle.metaopt.data.aggregates.BaseAggregate.__enter__() neuraxle.metaopt.data.aggregates.BaseAggregate.__exit__() neuraxle.metaopt.auto_ml.Trainer neuraxle.metaopt.auto_ml.Trainer.train()

_managed_subresource(*args, **kwds) → AbstractContextManager[SubAggregateT][source]
_acquire_managed_subresource(*args, **kwds) → SubAggregateT[source]

Acquire a new subaggregate that is managed such that it is deep saved at the beginning. Generally:

  1. Refresh self,

  2. load subagg to fetch or create it,

  3. save loaded subagg in case it changed, and return it.

_release_managed_subresource(resource: SubAggregateT, e: Exception = None) → bool[source]

Release a subaggregate that was acquired with managed_subresource. The subaggregate normally has already saved itself. We may update things again here if needed.

Exceptions may be handled here. If handled, return True, if not, then return False.

_abc_impl = <_abc_data object>
class neuraxle.metaopt.data.aggregates.Root(_dataclass: SubDataclassT, context: neuraxle.metaopt.context.AutoMLContext, is_deep=False, parent: ParentAggregateT = None)[source]

Bases: neuraxle.metaopt.data.reporting.RootReport, neuraxle.metaopt.data.aggregates.BaseAggregate

save(deep: bool = False)[source]
projects
static from_repo(context: neuraxle.metaopt.context.AutoMLContext, repo: neuraxle.metaopt.repositories.repo.HyperparamsRepository) → neuraxle.metaopt.data.aggregates.Root[source]
static vanilla(context: neuraxle.metaopt.context.AutoMLContext = None) → neuraxle.metaopt.data.aggregates.Root[source]
get_project(name: str) → neuraxle.metaopt.data.aggregates.Root[source]

This is a method to be used as a context manager. This will sync items with the repos. Example:

See also

neuraxle.metaopt.data.aggregates.BaseAggregate neuraxle.metaopt.data.aggregates.BaseAggregate.__enter__() neuraxle.metaopt.data.aggregates.BaseAggregate.__exit__() neuraxle.metaopt.auto_ml.Trainer neuraxle.metaopt.auto_ml.Trainer.train()

default_project() → neuraxle.metaopt.data.aggregates.Root[source]

This is a method to be used as a context manager. This will sync items with the repos. Example:

See also

neuraxle.metaopt.data.aggregates.BaseAggregate neuraxle.metaopt.data.aggregates.BaseAggregate.__enter__() neuraxle.metaopt.data.aggregates.BaseAggregate.__exit__() neuraxle.metaopt.auto_ml.Trainer neuraxle.metaopt.auto_ml.Trainer.train()

_acquire_managed_subresource(project_name: str) → neuraxle.metaopt.data.aggregates.Project[source]

Acquire a new subaggregate that is managed such that it is deep saved at the beginning. Generally:

  1. Refresh self,

  2. load subagg to fetch or create it,

  3. save loaded subagg in case it changed, and return it.

_abc_impl = <_abc_data object>
class neuraxle.metaopt.data.aggregates.Project(_dataclass: SubDataclassT, context: neuraxle.metaopt.context.AutoMLContext, is_deep=False, parent: ParentAggregateT = None)[source]

Bases: neuraxle.metaopt.data.reporting.ProjectReport, neuraxle.metaopt.data.aggregates.BaseAggregate

get_client(name: str) → neuraxle.metaopt.data.aggregates.Project[source]

This is a method to be used as a context manager. This will sync items with the repos. Example:

See also

neuraxle.metaopt.data.aggregates.BaseAggregate neuraxle.metaopt.data.aggregates.BaseAggregate.__enter__() neuraxle.metaopt.data.aggregates.BaseAggregate.__exit__() neuraxle.metaopt.auto_ml.Trainer neuraxle.metaopt.auto_ml.Trainer.train()

default_client() → neuraxle.metaopt.data.aggregates.Project[source]

This is a method to be used as a context manager. This will sync items with the repos. Example:

See also

neuraxle.metaopt.data.aggregates.BaseAggregate neuraxle.metaopt.data.aggregates.BaseAggregate.__enter__() neuraxle.metaopt.data.aggregates.BaseAggregate.__exit__() neuraxle.metaopt.auto_ml.Trainer neuraxle.metaopt.auto_ml.Trainer.train()

_acquire_managed_subresource(client_name: str) → neuraxle.metaopt.data.aggregates.Client[source]

Acquire a new subaggregate that is managed such that it is deep saved at the beginning. Generally:

  1. Refresh self,

  2. load subagg to fetch or create it,

  3. save loaded subagg in case it changed, and return it.

_abc_impl = <_abc_data object>
class neuraxle.metaopt.data.aggregates.Client(_dataclass: SubDataclassT, context: neuraxle.metaopt.context.AutoMLContext, is_deep=False, parent: ParentAggregateT = None)[source]

Bases: neuraxle.metaopt.data.reporting.ClientReport, neuraxle.metaopt.data.aggregates.BaseAggregate

new_round(main_metric_name: str) → neuraxle.metaopt.data.aggregates.Client[source]

This is a method to be used as a context manager. This will sync items with the repos. Example:

See also

neuraxle.metaopt.data.aggregates.BaseAggregate neuraxle.metaopt.data.aggregates.BaseAggregate.__enter__() neuraxle.metaopt.data.aggregates.BaseAggregate.__exit__() neuraxle.metaopt.auto_ml.Trainer neuraxle.metaopt.auto_ml.Trainer.train()

resume_last_round() → neuraxle.metaopt.data.aggregates.Client[source]

This is a method to be used as a context manager. This will sync items with the repos. Example:

See also

neuraxle.metaopt.data.aggregates.BaseAggregate neuraxle.metaopt.data.aggregates.BaseAggregate.__enter__() neuraxle.metaopt.data.aggregates.BaseAggregate.__exit__() neuraxle.metaopt.auto_ml.Trainer neuraxle.metaopt.auto_ml.Trainer.train()

optim_round(new_round: bool, main_metric_name: str) → neuraxle.metaopt.data.aggregates.Client[source]

This is a method to be used as a context manager. This will sync items with the repos. Example:

See also

neuraxle.metaopt.data.aggregates.BaseAggregate neuraxle.metaopt.data.aggregates.BaseAggregate.__enter__() neuraxle.metaopt.data.aggregates.BaseAggregate.__exit__() neuraxle.metaopt.auto_ml.Trainer neuraxle.metaopt.auto_ml.Trainer.train()

_acquire_managed_subresource(new_round: bool = True, main_metric_name: str = None) → neuraxle.metaopt.data.aggregates.Round[source]

Acquire a new subaggregate that is managed such that it is deep saved at the beginning. Generally:

  1. Refresh self,

  2. load subagg to fetch or create it,

  3. save loaded subagg in case it changed, and return it.

_abc_impl = <_abc_data object>
class neuraxle.metaopt.data.aggregates.Round(_dataclass: SubDataclassT, context: neuraxle.metaopt.context.AutoMLContext, is_deep=False, parent: ParentAggregateT = None)[source]

Bases: neuraxle.metaopt.data.reporting.RoundReport, neuraxle.metaopt.data.aggregates.BaseAggregate

with_optimizer(hp_optimizer: neuraxle.metaopt.optimizer.BaseHyperparameterOptimizer, hp_space: neuraxle.hyperparams.space.HyperparameterSpace) → neuraxle.metaopt.data.aggregates.Round[source]
with_metric(metric_name: str) → neuraxle.metaopt.data.aggregates.Round[source]
new_rvs_trial(continue_on_error: bool = False) → neuraxle.metaopt.data.aggregates.Round[source]

This is a method to be used as a context manager. This will sync items with the repos. Example:

See also

neuraxle.metaopt.data.aggregates.BaseAggregate neuraxle.metaopt.data.aggregates.BaseAggregate.__enter__() neuraxle.metaopt.data.aggregates.BaseAggregate.__exit__() neuraxle.metaopt.auto_ml.Trainer neuraxle.metaopt.auto_ml.Trainer.train()

last_trial(continue_on_error: bool = False) → neuraxle.metaopt.data.aggregates.Round[source]

This is a method to be used as a context manager. This will sync items with the repos. Example:

See also

neuraxle.metaopt.data.aggregates.BaseAggregate neuraxle.metaopt.data.aggregates.BaseAggregate.__enter__() neuraxle.metaopt.data.aggregates.BaseAggregate.__exit__() neuraxle.metaopt.auto_ml.Trainer neuraxle.metaopt.auto_ml.Trainer.train()

refitting_best_trial() → neuraxle.metaopt.data.aggregates.Round[source]

This is a method to be used as a context manager. This will sync items with the repos. Example:

See also

neuraxle.metaopt.data.aggregates.BaseAggregate neuraxle.metaopt.data.aggregates.BaseAggregate.__enter__() neuraxle.metaopt.data.aggregates.BaseAggregate.__exit__() neuraxle.metaopt.auto_ml.Trainer neuraxle.metaopt.auto_ml.Trainer.train()

_trials
round_number
_acquire_managed_subresource(new_trial: Optional[bool] = True, continue_on_error: bool = False) → neuraxle.metaopt.data.aggregates.Trial[source]

Get a trial. If new_trial is None, refit the best trial.

Parameters
  • new_trial – If True, will create a new trial. If false, will load the last trial. If None, will load the best trial.

  • continue_on_error (bool) – If True, will continue to the next trial if the current trial fails. Otherwise, will let the exception be raised for the failure (won’t catch).

_release_managed_subresource(resource: neuraxle.metaopt.data.aggregates.Trial, e: Exception = None) → bool[source]

Release a subaggregate that was acquired with managed_subresource. The subaggregate normally has already saved itself. We may update things again here if needed.

Exceptions may be handled here. If handled, return True, if not, then return False.

append(trial: neuraxle.metaopt.data.aggregates.Trial)[source]

Add a new trial. Will also save the trial shallowly.

Parameters

trial – new trial

Returns

copy() → neuraxle.metaopt.data.aggregates.Round[source]
main_metric_name
_abc_impl = <_abc_data object>
class neuraxle.metaopt.data.aggregates.Trial(_dataclass: SubDataclassT, context: neuraxle.metaopt.context.AutoMLContext, is_deep=False, parent: ParentAggregateT = None)[source]

Bases: neuraxle.metaopt.data.reporting.TrialReport, neuraxle.metaopt.data.aggregates.BaseAggregate

This class is a sub-contextualization of the HyperparameterRepository class for holding a trial and manipulating it within its context. A Trial contains the results for each validation split. Each trial split contains both the training set results, and the validation set results.

See also

Trial, TrialSplit, HyperparamsRepository, AutoML, ExecutionContext

continue_loop_on_error() → neuraxle.metaopt.data.aggregates.Trial[source]
_validation_splits
main_metric_name
new_validation_split(continue_loop_on_error: bool = False) → neuraxle.metaopt.data.aggregates.Trial[source]

This is a method to be used as a context manager. This will sync items with the repos. Example:

See also

neuraxle.metaopt.data.aggregates.BaseAggregate neuraxle.metaopt.data.aggregates.BaseAggregate.__enter__() neuraxle.metaopt.data.aggregates.BaseAggregate.__exit__() neuraxle.metaopt.auto_ml.Trainer neuraxle.metaopt.auto_ml.Trainer.train()

retrain_split() → neuraxle.metaopt.data.aggregates.Trial[source]

This is a method to be used as a context manager. This will sync items with the repos. Example:

See also

neuraxle.metaopt.data.aggregates.BaseAggregate neuraxle.metaopt.data.aggregates.BaseAggregate.__enter__() neuraxle.metaopt.data.aggregates.BaseAggregate.__exit__() neuraxle.metaopt.auto_ml.Trainer neuraxle.metaopt.auto_ml.Trainer.train()

_acquire_managed_subresource(continue_loop_on_error: bool, retrain_split=False) → neuraxle.metaopt.data.aggregates.TrialSplit[source]

Acquire a new subaggregate that is managed such that it is deep saved at the beginning. Generally:

  1. Refresh self,

  2. load subagg to fetch or create it,

  3. save loaded subagg in case it changed, and return it.

_release_managed_subresource(resource: neuraxle.metaopt.data.aggregates.TrialSplit, e: Exception = None) → bool[source]

Release a subaggregate that was acquired with managed_subresource. The subaggregate normally has already saved itself. We may update things again here if needed.

Exceptions may be handled here. If handled, return True, if not, then return False.

_set_success() → neuraxle.metaopt.data.aggregates.Trial[source]

Set trial status to success. Must save after to ensure consistency.

_set_failed(error: Exception) → neuraxle.metaopt.data.aggregates.Trial[source]

Set failed trial with exception. Must save after to ensure consistency.

Parameters

error (Exception) – catched exception

Returns

self

_abc_impl = <_abc_data object>
class neuraxle.metaopt.data.aggregates.TrialSplit(_dataclass: SubDataclassT, context: neuraxle.metaopt.context.AutoMLContext, is_deep=False, parent: neuraxle.metaopt.data.aggregates.Trial = None)[source]

Bases: neuraxle.metaopt.data.reporting.TrialSplitReport, neuraxle.metaopt.data.aggregates.BaseAggregate

One split of a trial. This is where a model is trained and evaluated on a specific dataset split.

__init__(_dataclass: SubDataclassT, context: neuraxle.metaopt.context.AutoMLContext, is_deep=False, parent: neuraxle.metaopt.data.aggregates.Trial = None)[source]

Initialize self. See help(type(self)) for accurate signature.

_invariant()[source]
main_metric_name
with_n_epochs(n_epochs: int) → neuraxle.metaopt.data.aggregates.TrialSplit[source]
next_epoch() → int[source]

Increment epoch. Returns the new epoch id. Epochs are 1-indexed like lengths: first epoch is 1, second is 2, etc.

start() → neuraxle.metaopt.data.aggregates.TrialSplit[source]

Start the trial split.

metric_results
metric_result(metric_name: str = None) → neuraxle.metaopt.data.aggregates.MetricResults[source]

Get a metric result that is not managed with a “with” statement. Access it read-only.

managed_metric(metric_name: str, higher_score_is_better: bool) → neuraxle.metaopt.data.aggregates.TrialSplit[source]

To be used as a with statement to get the managed metric.

This is a method to be used as a context manager. This will sync items with the repos. Example:

See also

neuraxle.metaopt.data.aggregates.BaseAggregate neuraxle.metaopt.data.aggregates.BaseAggregate.__enter__() neuraxle.metaopt.data.aggregates.BaseAggregate.__exit__() neuraxle.metaopt.auto_ml.Trainer neuraxle.metaopt.auto_ml.Trainer.train()

_acquire_managed_subresource(metric_name: str, higher_score_is_better: bool) → neuraxle.metaopt.data.aggregates.MetricResults[source]

Acquire a new subaggregate that is managed such that it is deep saved at the beginning. Generally:

  1. Refresh self,

  2. load subagg to fetch or create it,

  3. save loaded subagg in case it changed, and return it.

_create_or_get_metric_results(metric_name, higher_score_is_better)[source]
_release_managed_subresource(resource: neuraxle.metaopt.data.aggregates.MetricResults, e: Exception = None) → bool[source]

Release a subaggregate that was acquired with managed_subresource. The subaggregate normally has already saved itself. We may update things again here if needed.

Exceptions may be handled here. If handled, return True, if not, then return False.

_set_success() → neuraxle.metaopt.data.aggregates.TrialSplit[source]

Set trial status to success. Must save after to ensure consistency.

Returns

self

_set_failed(error: Exception) → neuraxle.metaopt.data.aggregates.TrialSplit[source]

Set failed trial with exception. Must save after to ensure consistency.

Parameters

error (Exception) – catched exception

Returns

self

train_context() → neuraxle.metaopt.context.AutoMLContext[source]
validation_context() → neuraxle.metaopt.context.AutoMLContext[source]
_abc_impl = <_abc_data object>
class neuraxle.metaopt.data.aggregates.MetricResults(_dataclass: SubDataclassT, context: neuraxle.metaopt.context.AutoMLContext, is_deep=False, parent: ParentAggregateT = None)[source]

Bases: neuraxle.metaopt.data.reporting.MetricResultsReport, neuraxle.metaopt.data.aggregates.BaseAggregate

_invariant()[source]
metric_name
_acquire_managed_subresource(*args, **kwds) → SubAggregateT[source]

Acquire a new subaggregate that is managed such that it is deep saved at the beginning. Generally:

  1. Refresh self,

  2. load subagg to fetch or create it,

  3. save loaded subagg in case it changed, and return it.

add_train_result(score: float)[source]

Add a train metric result.

Parameters
  • name – name of the metric. If None, use the main metric name.

  • score (float) – the value to be logged

  • higher_score_is_better – wheter or not a higher score is better for this metric

add_valid_result(score: float)[source]

Add a validation metric result.

Parameters
  • name – name of the metric. If None, use the main metric name.

  • score (float) – the value to be logged

  • higher_score_is_better – wheter or not a higher score is better for this metric

_abc_impl = <_abc_data object>