The Dependencies class#
Aliases#
halerium.core.causal_structure.Dependencies
- class Dependencies(dependencies=None)#
The Dependencies class.
The Dependencies class.
A collection of acyclic dependencies.
- Parameters:
dependencies (None, iterable or Dependency, optional) – The dependencies which make up the collection. Can be either a single Dependency instance or a list-like iterable containing Dependency instances, or list-like or dict-like elements which are valid __init__ arguments for the Dependency class. The default is None.
- Raises:
CyclicDependencyError – If the collection of dependencies is not acyclic an exception is raised.
Examples
>>> deps = [ >>> ["a", "b"], >>> Dependency(["b", "c"]), >>> {"feature": "c", "target": "d"}, >>> [["c", "d"], "e"], >>> ] >>> d = Dependencies(deps) >>> d.dependencies {'b': {'a'}, 'c': {'b'}, 'd': {'c'}, 'e': {'c', 'd'}}
>>> deps = [ >>> ["a", "b"], >>> ["b", "c"], >>> ["c", "a"], >>> ] >>> Dependencies(deps) CyclicDependencyError: Cyclic dependency detected
- add_dependency(*args, check_cyclic=True, **kwargs)#
Add dependency.
Add a single dependency to the dependency collection. The single dependency consists of a collection of features and targets.
There are three ways to provide features and targets.
1. single argument (list-like) The method is given a list or tuple of length 2 in which the first entry contains the feature(s) and the second entry the target(s).
2. single argument (dict-like) The method is given a dict of length 2 with the features as the value of a key named “feature”, “features”, “input”, “inputs”, “cause”, or “causes” and the target as the value of a key named “target”, “targets”, “output”, “outputs”, “effect”, or “effects”.
3. two (keyword) arguments (list-like) The method is given two arguments. The first positional argument contains the feature(s), the second the target(s). If keyword arguments are used, the allowed keys for the feature(s) are “feature”, “features”, “input”, “inputs”, “cause”, or “causes” and the allowed key for the target(s) are “target”, “targets”, “output”, “outputs”, “effect”, or “effects”.
- Raises:
CyclicDependencyError – If the collection of dependencies after adding the the single dependency is not acyclic an exception is raised.
- check_for_cyclic_dependencies()#
Check for cyclic dependencies.
Check whether the current collection of dependencies is acyclic.
- Raises:
CyclicDependencyError – If the collection of dependencies is not acyclic an exception is raised.
- get_features(target, default=None)#
Get a set of the features that directly influence the target.
- Parameters:
target (str) – The target
default (optional) – The return if target has no dependencies, e.g. if the target is independent.