Package: causy
[!WARNING]
causy is currently in a very early and experimental stage of development. It currently only supports one algorithm. We do not recommend using it in production.causyCausal discovery made easy. Causy allows you to use and implement causal discovery algorithms with easy to use, extend and maintain pipelines. It is built based on pytorch which allows you to run the algorithms on CPUs as well as GPUs seamlessly.BackgroundCurrent causal discovery algorithms are often designed for the primary purpose of research. They are often implemented in a monolithic way, which makes it hard to understand and extend them. Causy aims to solve this problem by providing a framework which allows you to easily implement and use causal discovery algorithms by splitting them up into smaller logic steps which can be stacked together to form a pipeline. This allows you to easily understand, extend, optimize, and experiment with the algorithms.By shipping causy with sensitively configured default pipelines, we also aim to provide a tool that can be used by non-experts to get started with causal discovery.Thanks to the pytorch backend, causy is remarkably faster compared to serial CPU based implementations.In the future, causy aims to provide interactive visualizations which allow you to understand the causal discovery process.InstallationCurrently we only support python 3.11. To install causy runpipinstallcausyUsageCausy can be used via CLI or via code.Usage via CLIRun causy with one of the default algorithmscausyexecute--help
causyexecuteyour_data.json--algorithmPC--output-fileoutput.jsonThe input data should be a json file with a list of dictionaries. Each dictionary represents a data point. The keys of the dictionary are the variable names and the values are the values of the variables. The values can be either numeric or categorical.[{"a":1,"b":0.3},{"a":0.5,"b":0.2}]You can customize your causy pipeline by ejecting and modifying the pipeline file.causyejectPCpc.json# edit pc.jsoncausyexecuteyour_data.json--pipelinepc.jsonThis might be useful if you want to configure a custom algorithm or if you want to customize the pipeline of a default algorithm.Usage via CodeUse a default algorithmfromcausy.algorithmsimportPCfromcausy.graph_utilsimportretrieve_edgesmodel=PC()model.create_graph_from_data([{"a":1,"b":0.3},{"a":0.5,"b":0.2}])model.create_all_possible_edges()model.execute_pipeline_steps()edges=retrieve_edges(model.graph)foredgeinedges:print(f"{edge[0].name}->{edge[1].name}:{model.graph.edges[edge[0]][edge[1]]}")Use a custom algorithmfromcausy.common_pipeline_steps.exit_conditionsimportExitOnNoActionsfromcausy.graph_modelimportgraph_model_factoryfromcausy.common_pipeline_steps.logicimportLoopfromcausy.common_pipeline_steps.calculationimportCalculatePearsonCorrelationsfromcausy.independence_tests.commonimport(CorrelationCoefficientTest,PartialCorrelationTest,ExtendedPartialCorrelationTestMatrix,)fromcausy.orientation_rules.pcimport(ColliderTest,NonColliderTest,FurtherOrientTripleTest,OrientQuadrupleTest,FurtherOrientQuadrupleTest,)fromcausy.graph_utilsimportretrieve_edgesCustomPC=graph_model_factory(pipeline_steps=[CalculatePearsonCorrelations(),CorrelationCoefficientTest(threshold=0.1),PartialCorrelationTest(threshold=0.01),ExtendedPartialCorrelationTestMatrix(threshold=0.01),ColliderTest(),Loop(pipeline_steps=[NonColliderTest(),FurtherOrientTripleTest(),OrientQuadrupleTest(),FurtherOrientQuadrupleTest(),],exit_condition=ExitOnNoActions(),),])model=CustomPC()model.create_graph_from_data([{"a":1,"b":0.3},{"a":0.5,"b":0.2}])model.create_all_possible_edges()model.execute_pipeline_steps()edges=retrieve_edges(model.graph)foredgeinedges:print(f"{edge[0].name}->{edge[1].name}:{model.graph.edges[edge[0]][edge[1]]}")Supported algorithmsCurrently causy supports the following algorithms:PC (Peter-Clark)PC - the original PC algorithm without any modificationscausy.algorithms.PCParallelPC - a parallelized version of the PC algorithmcausy.algorithms.ParallelPCSupported pipeline stepsDetailed information about the pipeline steps can be found in theAPI Documentation.Dev usageSetupWe recommend using poetry to manage the dependencies. To install poetry follow the instructions onhttps://python-poetry.org/docs/#installation.Install dependenciespoetryinstallExecute testspoetryrunpython-munittest