The Dependency class#

Aliases#

halerium.core.causal_structure.Dependency
class Dependency(*args, **kwargs)#

The Dependency class.

The Dependency class.

A dependency is essentially a tuple of features and targets. It stores the information that the features depend on the targets. Features and targets are a set of strings.

There are three ways to provide features and targets to the __init__.

1. single argument (list-like) The __init__ 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 __init__ 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 __init__ 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”.

If a string in the features is also contained in the targets a CyclicDependencyError is raised.

Examples

>>> d = Dependency("a", "b")
>>> print(d.features, d.targets)
{'a'} {'b'}
>>> d = Dependency(["a", "c"], target="b")
>>> print(d.features, d.targets)
{'a', 'c'} {'b'}
>>> d = Dependency(causes=["a", "c"], effects=["b", "d"])
>>> print(d.features, d.targets)
{'a', 'c'} {'b', 'd'}
>>> Dependency(causes=["a", "c"], effects=["c", "d"])
CyclicDependencyError: Cyclic dependency detected for c
>>> Dependency(causes=[1], effects=[2])
TypeError: Expected strings as features and targets. Got 1 of type <class 'int'> instead.
allowed_feature_keys = {'cause', 'causes', 'feature', 'features', 'input', 'inputs'}#
allowed_target_keys = {'effect', 'effects', 'output', 'outputs', 'target', 'targets'}#