- Added the
cai_causal_graph.causal_graph.CausalGraph.get_nondirected_edges
method, which returns all edges that are not explicitly directed, i.e. not of typeEdgeType.DIRECTED_EDGE
.
- Added support for
numpy < 3.0.0
for Python versions>= 3.10
.
- Added the
cai_causal_graph.causal_graph.CausalGraph.get_nodes_between
method, which returns the set of all nodes that are on a directed causal path between two nodes in the graph.
- Fixed a bug in the
cai_causal_graph.causal_graph.CausalGraph.add_edge
method that would allow the addition of an edge betweenb
anda
when the reversed edge, i.e. betweena
andb
was already specified. - Added the
CausalGraphError.ReverseEdgeExistsError
exception, which distinguishes errors arising from the introduction of cycles or reverse edges.
- Improved the speed of the
cai_causal_graph.causal_graph.CausalGraph.get_descendant_graph
andcai_causal_graph.causal_graph.CausalGraph.get_ancestral_graph
methods for large graphs. - Improved the speed of the
cai_causal_graph.causal_graph.CausalGraph.from_adjacency_matrix
andcai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.from_adjacency_matrices
methods by introducing avalidate
flag. WhenFalse
, there are no checks for cycles (default isTrue
).- Also added this flag for all
from_skeleton
,from_networkx
andfrom_gml_string
methods.
- Also added this flag for all
- Fixed a bug in the
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_summary_graph
method for thecai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
class where it would not correctly maintain floating nodes.
cai_causal_graph.utils.get_variable_name_and_lag
now allows new lines in the names of variables.- Passing
input_list
,output_list
, andfully_connected
as arguments to the constructor of acai_causal_graph.causal_graph.CausalGraph
is now deprecated, and will be removed in future versions. To maintain this behavior, callcai_causal_graph.causal_graph.CausalGraph.add_fully_connected_nodes
after construction. - Upgraded
poetry
version from1.8.2
to1.8.3
in the GitHub workflows.
- Removed caching from
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_minimal_graph
,cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_stationary_graph
andcai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_summary_graph
because the caching would not account for changes in node/edge metadata.
- Improved caching of results for
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
class, including:- Adding caching to the following methods:
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_minimal_graph
,cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.is_minimal_graph
,cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.is_stationary_graph
. - Fixed a bug in
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_stationary_graph
where the same cached graph would be returned multiple times. Instead now, a deepcopied version of this graph is returned. - Fixed a bug where cached attributes would not be reset when adding edges to
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
, which can lead to erroneous stationary graphs being returned.
- Adding caching to the following methods:
- Added caching of
cai_causal_graph.causal_graph.CausalGraph.is_dag
,cai_causal_graph.causal_graph.CausalGraph.adjacency_matrix
andcai_causal_graph.causal_graph.CausalGraph.to_networkx
methods. - Unified cached attribute resetting between
cai_causal_graph.causal_graph.CausalGraph
andcai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
by introducing acai_causal_graph.causal_graph.CausalGraph._reset_cached_attributes
method andcai_causal_graph.causal_graph.reset_cached_attributes_decorator
decorator. - Fixed a bug where calling
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.variables
method would return the variable list by reference, rather than returning a copy.
NOTE: Backwards compatibility warning! Global metadata to
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
andcai_causal_graph.causal_graph.CausalGraph
, which means their serialized state has changed.
NOTE: Backwards compatibility warning! The default value of the
include_all_parents
argument tocai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.extend_graph
has been changed toTrue
(fromFalse
).
- The default value of the
include_all_parents
argument tocai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.extend_graph
has been changed toTrue
(fromFalse
). - Added metadata handling system to the
cai_causal_graph.interfaces.HasMetadata
class. All extending classes should use this system to parse and set their metadata. - Added
cai_causal_graph.graph_components.TimeSeriesEdge
class, which is used as an edge class bycai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
. - Added metadata to
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
andcai_causal_graph.causal_graph.CausalGraph
. - Ensured consistent metadata handling. Metadata passed at construction to
cai_causal_graph.graph_components.TimeSeriesNode
,cai_causal_graph.graph_components.Node
,cai_causal_graph.graph_components.TimeSeriesEdge
,cai_causal_graph.graph_components.Edge
,cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
andcai_causal_graph.causal_graph.CausalGraph
is shallow-copied. Any metadata is deepcopied when constructingcai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
andcai_causal_graph.causal_graph.CausalGraph
from dictionary. - Ensured that
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.replace_node
performs similarly tocai_causal_graph.causal_graph.CausalGraph.replace_node
, meaning that if any additional information (such as metadata) is specified, it is used to overwrite corresponding information in the constructed node. - Generalized
cai_causal_graph.causal_graph.CausalGraph.__eq__
to check for the class of the instance itself, enabling to reuse this method by extending classes. - Added
cai_causal_graph.causal_graph.CausalGraph.has_non_serializable_metadata
method, which returnsFalse
by default. - Extended the string representation (
repr
) ofcai_causal_graph.causal_graph.CausalGraph
to include whether the graph instance is a directed acyclic graph (DAG). - Dropped support for
python
3.8
as it is approaching end of life.
- Improved documentation by cleaning up a few syntax issues to support the new docs building process.
- Fixed a bug where metadata on floating nodes would not be correctly carried over to the minimal graph when calling
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_minimal_graph
. This also fixes an issue wherecai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.is_minimal_graph
could returnFalse
on minimal graphs that contain floating nodes.
- Upgraded
docs-builder
dependency to"~0.2.1"
in the Makefile and updated syntax to support newerpoetry
.
- Added the
cai_causal_graph.causal_graph.identify_utils.identity_colliders
utility function, which allows you to identify a list of colliders in acai_causal_graph.causal_graph.CausalGraph
. - Improved efficiency of
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_nodes_at_lag
andcai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_nodes_for_variable_name
by adding caching. - Updated
networkx
dependency from">=3.0.0, <4.0.0"
to">=3.0.0, <3.3.0"
andnetworkx
have claimed to fix a bug with simple paths and other related functions, but this now introduces paths of length 1 which we do not want. Also updatedpyproject.toml
to allow differentnetworkx
versions forpython
3.8
and3.9
-3.12
asnetworkx
3.1
is the last one that supports3.8
. - Upgraded
poetry
version from1.7.1
to1.8.2
in the GitHub workflows.
- Added the Boolean keyword argument
include_all_parents
tocai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.extend_graph
. WhenTrue
extra nodes may be added. Nodes and edges will be added as far back that all nodes up tobackward_steps
in the past have all their parents and inbound edges. This means that the extended graph may now have nodes at lags further back thanbackward_steps
. Default isFalse
, meaning the default behavior of the method has not changed. - Added the Boolean keyword argument
construct_minimal
tocai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.from_adjacency_matrices
to allow the user to specify whether to construct a minimal graph from adjacency matrices. Default isTrue
, making the change backwards compatible. - Fixed a bug in the
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.from_adjacency_matrices
method ofcai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
that was introduced in the previous release. The method was not properly handling undirected edges in the adjacency matrices. - Fixed a bug in the
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.to_numpy_by_lag
method ofcai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
where it was not always returning the correct variable names. - Fixed a bug in the
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.adjacency_matrices
property ofcai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
where it was not looking at the variable names of the minimal graph, as expected, but the variables names of the full graph. - Removed the
return_minimal
argument from thecai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.adjacency_matrices
property ofcai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
as this was never working.
- Fixed a bug in
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.from_adjacency_matrices
forcai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
where the method was not handling properly undirected edges in the adjacency matrices. - Added
mypy-extensions
dependency as"^1.0.0"
and movedmypy
back to dev dependency (setting it as"^1.8.0"
).
- Relaxed
mypy
dependency to"*"
.
- Added the
cai_causal_graph.causal_graph.CausalGraph.replace_edge
method to thecai_causal_graph.causal_graph.CausalGraph
class, which allows you to replace an existing edge with a new one. - Added the
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_nodes_for_variable_name
method to thecai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
class. - Added the
cai_causal_graph.graph_components.Node.is_source_node
andcai_causal_graph.graph_components.Node.is_sink_node
methods to thecai_causal_graph.graph_components.Node
, indicating whether the node is a source node or sink node respectively. - Changed the following methods in
cai_causal_graph.causal_graph.CausalGraph
from static to class methods:cai_causal_graph.causal_graph.CausalGraph.from_skeleton
cai_causal_graph.causal_graph.CausalGraph.from_networkx
cai_causal_graph.causal_graph.CausalGraph.from_gml_string
- Note that
cai_causal_graph.causal_graph.CausalGraph.from_dict
andcai_causal_graph.causal_graph.CausalGraph.from_adjacency_matrix
were already class methods. Now all thefrom_
methods are consistent. This change is transparent to the user. - This allowed us to remove them from
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
. This change is transparent to the user.
- Updated
cai_causal_graph.causal_graph.Skeleton
such that its nodes match the class type of its graph.- Added ability to pass
graph_class
to the following methods incai_causal_graph.causal_graph.Skeleton
such that the node classes will match accordingly when the newcai_causal_graph.causal_graph.Skeleton
is constructed:cai_causal_graph.causal_graph.Skeleton.from_dict
cai_causal_graph.causal_graph.Skeleton.from_adjacency_matrix
cai_causal_graph.causal_graph.Skeleton.from_networkx
cai_causal_graph.causal_graph.Skeleton.from_gml_string
- Note that
cai_causal_graph.causal_graph.Skeleton.from_dict
was already a class method but the other three were also changed to class methods for consistency. This change is transparent to the user.
- Added ability to pass
- Fixed a bug where the
cai_causal_graph.type_definitions.NodeVariableType
was not synced between thecai_causal_graph.causal_graph.CausalGraph
andcai_causal_graph.causal_graph.Skeleton
. - Changed
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.from_adjacency_matrices
from a static method to a class method to align with otherfrom_
methods. - Updated
numpy
dependency from"^1.18.0"
to"^1.20.0"
and allow differentnumpy
versions in thepoetry.lock
forpython
3.8
and3.9
-3.12
. This is to allow specific versions for3.8
and the others as there is no version ofnumpy
that supports them all. - Upgraded
poetry
version from1.4.2
to1.7.1
in the GitHub workflows. - Moved
mypy
from a dev dependency to a dependency as it is now used in source code. - Updated actions in GitHub workflows to transition from
Node
16
toNode
20
.
- Added the
validate
flag tocai_causal_graph.causal_graph.CausalGraph.add_edge
,cai_causal_graph.causal_graph.CausalGraph.add_edges_from
,cai_causal_graph.causal_graph.CausalGraph.add_edges_from_paths
,cai_causal_graph.causal_graph.CausalGraph.add_edge_by_pair
,cai_causal_graph.causal_graph.CausalGraph.from_dict
,cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.add_edge
, andcai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.add_time_edge
which, if set toFalse
, will disable validation checks. Currently, this disables cyclicity checks when adding edges. Default isTrue
, making the change backwards compatible. There is no guarantees about the behavior of the resulting graph if this is disabled specifically to introduce cycles. This should only be used to speed up this method in situations where it is known the resulting graph is still valid, for example when copying a graph.
- Removed
**kwargs
from thecai_causal_graph.causal_graph.CausalGraph.add_node
,cai_causal_graph.causal_graph.CausalGraph.add_edge
, andcai_causal_graph.causal_graph.CausalGraph.add_edge_by_pair
methods incai_causal_graph.causal_graph.CausalGraph
and its subclasses, as none of them use it. - Improved the
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_minimal_graph
method incai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
to avoid a recursion issue. - Added
cai_causal_graph.causal_graph.CausalGraph.add_edges_from_paths
convenience method to thecai_causal_graph.causal_graph.CausalGraph
class, in order to add edges from paths. - The
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_minimal_graph
method incai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
will now always return a graph of the same class type as the current graph instance. - The returned graph type from the
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_summary_graph
method incai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
can now be specified in subclasses ofcai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
using the_SummaryGraphCls
attribute. - Fixed a bug where
__getitem__
method ofcai_causal_graph.causal_graph.CausalGraph
would work when specifying invalid node or edge query, for example a whole path. Instead, aTypeError
is now raised. - Fixed a bug where
cai_causal_graph.causal_graph.CausalGraph.delete_edge
would not support passing source and destination ascai_causal_graph.graph_components.Node
. - Added support for passing source and destination as
cai_causal_graph.graph_components.Node
tocai_causal_graph.causal_graph.CausalGraph.remove_edge
. - The
cai_causal_graph.causal_graph.CausalGraph.from_adjacency_matrix
is now a class method (rather than being a static method) which has been generalized to return an instance of the class on which it has been called (e.g. enabling returning instances of classes inheriting fromcai_causal_graph.causal_graph.CausalGraph
.
- Fixed a bug in
cai_causal_graph.identify_utils.identify_confounders
where an empty confounding set would be returned in the edge case where all causal paths from the true confounders tonode_1
were blocked by ancestors ofnode_2
, or vice versa. This comes at a slight performance cost.
- Improved the
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_topological_order
method incai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
to improve performance. Added a new keyword argumentrespect_time_ordering
to allow the user to specify whether the topological order must respect the time ordering of the nodes. Ifrespect_time_ordering=True
, the topological order will respect the time ordering, otherwise it may not. For example, if the graph is'Y lag(n=1)' -> 'Y' <- 'X'
, then['X', 'Y lag(n=1)', 'Y']
and['Y lag(n=1)', 'X', 'Y']
are both valid topological orders. However, only the second one would respect time ordering. If bothreturn_all
andrespect_time_ordering
areTrue
, then only all topological orders that respect time are returned, not all valid topological orders. The default isrespect_time_ordering=True
, matching previous behavior.
- Improved efficiency of
cai_causal_graph.identify_utils.identify_confounders
by performing all operations directly usingnetworkx
, removing the need to copy graphs and improving recursive logic, such that only the minimal confounders of the specified nodes are calculated (rather than recursively calculating minimal confounders of each parent). This results in significant speedups (in the order of hundreds of times in some cases).
- Fixed a bug in the
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.extend_graph
method incai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
where the method was not adding nodes correctly with particular graph configurations.
- Fixed a bug in the
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_minimal_graph
method incai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
where floating nodes were not added correctly. This also impacted thecai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.extend_graph
method incai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
; it is also fixed now for floating nodes.
- Fixed a bug in the
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_topological_order
method incai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
.
- Fixed a bug in
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.from_causal_graph
forcai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
where the method was not adding floating nodes correctly. - Added
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.max_backward_lag
andcai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.max_forward_lag
properties tocai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
to return the absolute maximum backward and forward time lag of the graph, respectively. - Fixed a bug with the property
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.maxlag
incai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
since it could give wrong information if the future was included in the graph.
- Fixed a bug in
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.from_adjacency_matrices
forcai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
where the method was not adding floating nodes to the graph. Now any floating nodes at time lag 0 will be added.
- Added
__iter__
tocai_causal_graph.causal_graph.Skeleton
.
- Added the
cai_causal_graph.identify_utils.identify_markov_boundary
utility function, which allows you to identify the Markov boundary of a node in acai_causal_graph.causal_graph.CausalGraph
or in acai_causal_graph.causal_graph.Skeleton
. - Added
get_neighbor_nodes
andget_neighbors
methods tocai_causal_graph.causal_graph.CausalGraph
andcai_causal_graph.causal_graph.Skeleton
.get_neighbor_nodes
returns the nodes neighboring the specified node whileget_neighbors
returns the identifiers of the neighboring nodes. Note: For acai_causal_graph.causal_graph.CausalGraph
, it does not matter what the edge type is, as long as there is an edge between the specified node and another node, that other node is considered its neighbor.
- Extended documentation to provide further information regarding the types of mixed graphs that can be defined in a
cai_causal_graph.causal_graph.CausalGraph
.
- Fixed a bug in
cai_causal_graph.identify_utils.identify_instruments
andcai_causal_graph.identify_utils.identify_mediators
, where an unclear error was raised if thesource
node was a descendant of thedestination
node. Instead, these methods now return an empty list in that case. - Extended the quickstart documentation to describe how to set the
variable_type
when adding acai_causal_graph.graph_components.Node
/cai_causal_graph.graph_components.TimeSeriesNode
to acai_causal_graph.causal_graph.CausalGraph
/cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
, respectively.
- Improved documentation.
- Fixed a bug for forward extension in the
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.extend_graph
method incai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
.
NOTE: Backwards compatibility warning! The definition of the
cai_causal_graph.type_definitions.EdgeConstraint
enumeration has changed.
- Updated the
cai_causal_graph.type_definitions.EdgeConstraint
enumeration to simplify the enumeration members and exposed it at the root level, so it can be imported asfrom cai_causal_graph import EdgeConstraint
.cai_causal_graph.type_definitions.EdgeConstraint
is not used by thecai-causal-graph
package but any packages that rely on its definition, must be updated to reflect the new members.
- Fixed the docstrings of
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.from_adjacency_matrices
, such that the examples render properly.
- Fixed a bug where
cai_causal_graph.utils.get_variable_name_and_lag
would not match variable names with non-alphanumeric characters, and would not match variable names with the stringlag
orfuture
in them.
- Improved performance of checking for cycles when adding edges by avoiding repeated checks.
- Modified
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.add_edge
incai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
to always order source and destination nodes bytime_lag
even when the edge is not directed. For example,add_edge('c', 'a (lag=1)', edge_type=EdgeType.UNDIRECTED_EDGE)
will add an undirected edgea (lag=1) -- c
instead ofc -- a (lag=1)
. This is done just for convenience and to avoid confusion.
- Improved documentation.
- Added
cai_causal_graph.graph_components.Node.node_name
property tocai_causal_graph.graph_components.Node
as an alias ofcai_causal_graph.graph_components.Node.identifier
. - Added
cai_causal_graph.causal_graph.CausalGraph.get_parent_nodes
andcai_causal_graph.causal_graph.CausalGraph.get_children_nodes
tocai_causal_graph.causal_graph.CausalGraph
. These return a list of the parent and childrencai_causal_graph.graph_components.Node
objects, respectively. This is to supplement thecai_causal_graph.causal_graph.CausalGraph.get_parents
andcai_causal_graph.causal_graph.CausalGraph.get_children
methods, which only return the node identifiers.
- Improved the
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_topological_order
method for acai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
to better account for time. - Fixed a bug in
cai_causal_graph.causal_graph.CausalGraph
andcai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
that preventedcai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_minimal_graph
,cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_summary_graph
andcai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.extend_graph
from working properly as it did not maintain the correct extra information such as node variable types.
- Added the
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_nodes_at_lag
andcai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_contemporaneous_nodes
methods to thecai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
class to get the nodes at a given lag and the contemporaneous nodes of the provided node, respectively. - General improvements to several
from_*
methods in thecai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
class.
- Added support for
python
version3.12
.
- Changed the order of the documentation in the sidebar to ensure Quickstart is at the top.
- Improved internal logic for how an
cai_causal_graph.graph_components.Edge
is instantiated from a dictionary.
- Improved the
cai_causal_graph.causal_graph.CausalGraph.copy
method incai_causal_graph.causal_graph.CausalGraph
such that it is more general and preserves the subclass type. As such, the.copy
method was removed from thecai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
class. - Extended equality methods for the
cai_causal_graph.causal_graph.Skeleton
,cai_causal_graph.causal_graph.CausalGraph
, andcai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
classes. A new keyword parameterdeep
has been added. Ifdeep=True
, deep equality checks are also done on all nodes and edges in the graphs. To call you must dograph_1.__eq__(graph_2, deep=True)
asgraph_1 == graph_2
still matches previous behavior.
- Added the
cai_causal_graph.identify_utils.identify_confounders
utility function, which allows you to identify a list of confounders between two nodes in acai_causal_graph.causal_graph.CausalGraph
. - Added the
cai_causal_graph.identify_utils.identify_instruments
utility function, which allows you to identify a list of instrumental variables between two nodes in acai_causal_graph.causal_graph.CausalGraph
. - Added the
cai_causal_graph.identify_utils.identify_mediators
utility function, which allows you to identify a list of mediators between two nodes in acai_causal_graph.causal_graph.CausalGraph
.
- Fixed formatting in the documentation.
- Added the deserialization method
from_dict
to the following classes:cai_causal_graph.graph_components.Node
,cai_causal_graph.graph_components.TimeSeriesNode
, andcai_causal_graph.graph_components.Edge
. - Added the serialization method
cai_causal_graph.graph_components.TimeSeriesNode.to_dict
tocai_causal_graph.graph_components.TimeSeriesNode
.cai_causal_graph.graph_components.Node
andcai_causal_graph.graph_components.Edge
already had it. - Changed behavior of
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.add_node
method incai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
such that when bothidentifier
and (time_lag
,variable_name
) are provided. Now, if all are provided, the method will raise an error only ifidentifier
is not equal toget_name_with_lag(time_lag, variable_name)
, that is, the correct name. - Extended equality methods for the
cai_causal_graph.graph_components.Node
,cai_causal_graph.graph_components.Edge
andcai_causal_graph.graph_components.TimeSeriesNode
classes. A new keyword parameterdeep
has been added. Ifdeep=True
, additional class attributes are also checked; see the docstrings for additional information. To call you must donode_1.__eq__(node_2, deep=True)
asnode_1 == node_2
still matches previous behavior. - Added
cai_causal_graph.graph_components.Edge.edge_type
property to thecai_causal_graph.graph_components.Edge
class.
- Fixed typo in the quickstart documentation.
- Fixed
repr
bug in thecai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
class. - Added
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.to_numpy_by_lag
method to convert thecai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
to a dictionary of adjacency matrices where the keys are the time lags with the values being the adjacency matrices with respect to the variables. - Changed the
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.extend_graph
method incai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
to work with a non-negativebackward_steps
andforward_steps
instead of strictly positive. - Fixed edge type in the
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.extend_graph
method incai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
. - Added
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.add_time_edge
method incai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
to add a time edge between two nodes. This method allows to specify the time lag for source and destination variables. This avoids having to create the corresponding node name manually or using the utility functioncai_causal_graph.utils.get_name_with_lag
. - Added equality method for the
cai_causal_graph.graph_components.TimeSeriesNode
class. - Extended unit tests for the
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
andcai_causal_graph.graph_components.TimeSeriesNode
classes. - Documentation:
- Added a documentation page for the
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
class. - Changed quickstart to start from a
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
instead of acai_causal_graph.causal_graph.CausalGraph
.
- Added a documentation page for the
- Added the
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
class to represent a time series causal graph.cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
is aware of the time relationships between the nodes in the graph whilecai_causal_graph.causal_graph.CausalGraph
is not. Moreover, thecai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
class has three new representations:- The minimal graph, which can be obtained via the
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_minimal_graph
method, defines the graph with the minimal number of nodes and edges that is required to capture all the information encoded in the original graph. This is because a time series causal graph may contain a lot of repetitive information. For example, if the original graph isx(t-2) -> x(t-1) -> x(t)
, then the minimal graph would bex(t-1) -> x(t)
. In other words, it is a graph that has no edges whose destination is not time 0. - The summary graph, which can be obtained via the
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.get_summary_graph
method, defines the graph collapsed in time so there is a single node per variable. For example, if the original graph isz(t-2) -> x(t) <- y(t) <- y(t-1)
then the summary group would bez -> x <- y
. Note, it is possible to have cycles in the summary graph. For example, a graph with edgesy(t-1) -> x(t)
andx(t-1) -> y(t)
would have a summary graph ofx <-> y
. - The extended graph, which can be obtained via the
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.extend_graph
method, defines the graph obtained by extending backward and forward in time via the argumentsbackward_steps
andforward_steps
, respectively. This graph may contain lots of redundant information. For example, if the original graph isx(t-1) -> x(t)
andbackward_steps=2
andforward_steps=1
, then the extended graph would bex(t-2) -> x(t-1) -> x(t) -> x(t+1)
.
- The minimal graph, which can be obtained via the
- The
cai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph.from_adjacency_matrices
method was added to instantiate an instance ofcai_causal_graph.time_series_causal_graph.TimeSeriesCausalGraph
from a dictionary of adjacency matrices where the keys are the time lags. - Added the
cai_causal_graph.graph_components.TimeSeriesNode
class to extend thecai_causal_graph.graph_components.Node
class to represent time information on the node. The following properties were added:variable_name
: The variable name of the time series node. For example, if the identifier of the time series node is'X1 lag(n=1)'
, i.e., it is a lagged version of the variable'X1'
, thenvariable_name
would be'X1'
.time_lag
: The time lag of the time series node. For example, if the identifier of the time series node is'X1 lag(n=1)'
, i.e., it is a lagged version of the variable'X1'
, thentime_lag
would be-1
.
- Renamed
EdgeTypeEnum
tocai_causal_graph.type_definitions.EdgeType
.
- Fixed a syntax error in the docstring for the
cai_causal_graph.causal_graph.CausalGraph.get_bidirected_edges
method that was preventing the reference docs from being built.
- Improved
README
links so images appear on PyPI. - Upgraded
poetry
version from1.2.2
to1.4.2
in the GitHub workflows.
- Added security linting checks of source code using
bandit
. - Improved documentation packaging and publishing.
- Initial release of the
cai-causal-graph
package with thecai_causal_graph.causal_graph.CausalGraph
class and component classes:cai_causal_graph.causal_graph.Skeleton
,cai_causal_graph.graph_components.Node
, andcai_causal_graph.graph_components.Edge
.