From 4f6b812fbde389b3a59991d27044c463cb3d0e42 Mon Sep 17 00:00:00 2001 From: x3zvawq Date: Mon, 25 Mar 2024 08:45:41 +0800 Subject: [PATCH 1/3] perf: GRaSP allow disable stdout output Signed-off-by: x3zvawq --- causallearn/search/PermutationBased/GRaSP.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/causallearn/search/PermutationBased/GRaSP.py b/causallearn/search/PermutationBased/GRaSP.py index ba77b3ef..e46fb7b2 100644 --- a/causallearn/search/PermutationBased/GRaSP.py +++ b/causallearn/search/PermutationBased/GRaSP.py @@ -80,6 +80,7 @@ def grasp( depth: Optional[int] = 3, maxP: Optional[float] = None, parameters: Optional[Dict[str, Any]] = None, + verbose: Optional[bool] = True, ) -> Dict[str, Any]: """ Perform a greedy relaxation of the sparsest permutation (GRaSP) algorithm @@ -206,13 +207,15 @@ def grasp( order.bump_edges(len(y_parents)) while dfs(depth - 1, set(), [], order, score): - sys.stdout.write("\rGRaSP edge count: %i " % order.get_edges()) - sys.stdout.flush() + if verbose: + sys.stdout.write("\rGRaSP edge count: %i " % order.get_edges()) + sys.stdout.flush() runtime = time.perf_counter() - runtime - - sys.stdout.write("\nGRaSP completed in: %.2fs \n" % runtime) - sys.stdout.flush() + + if verbose: + sys.stdout.write("\nGRaSP completed in: %.2fs \n" % runtime) + sys.stdout.flush() for y in range(p): for x in order.get_parents(y): From 125e834d7839a63157ccd3c17e9a32908e47fd34 Mon Sep 17 00:00:00 2001 From: x3zvawq Date: Mon, 25 Mar 2024 08:46:26 +0800 Subject: [PATCH 2/3] perf: GRaSP function return value type Signed-off-by: x3zvawq --- causallearn/search/PermutationBased/GRaSP.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/causallearn/search/PermutationBased/GRaSP.py b/causallearn/search/PermutationBased/GRaSP.py index e46fb7b2..2964dc27 100644 --- a/causallearn/search/PermutationBased/GRaSP.py +++ b/causallearn/search/PermutationBased/GRaSP.py @@ -81,7 +81,7 @@ def grasp( maxP: Optional[float] = None, parameters: Optional[Dict[str, Any]] = None, verbose: Optional[bool] = True, -) -> Dict[str, Any]: +) -> GeneralGraph: """ Perform a greedy relaxation of the sparsest permutation (GRaSP) algorithm From c16aaeb9860241b078b5017ac499fd9bda0834bd Mon Sep 17 00:00:00 2001 From: x3zvawq Date: Mon, 25 Mar 2024 08:59:27 +0800 Subject: [PATCH 3/3] chore: GRaSP function docs append verbose Signed-off-by: x3zvawq --- causallearn/search/PermutationBased/GRaSP.py | 1 + 1 file changed, 1 insertion(+) diff --git a/causallearn/search/PermutationBased/GRaSP.py b/causallearn/search/PermutationBased/GRaSP.py index 2964dc27..38cdabf7 100644 --- a/causallearn/search/PermutationBased/GRaSP.py +++ b/causallearn/search/PermutationBased/GRaSP.py @@ -97,6 +97,7 @@ def grasp( parameters['lambda']: regularization parameter parameters['dlabel']: for variables with multi-dimensions, indicate which dimensions belong to the i-th variable. + verbose : whether to print the time cost and verbose output of the algorithm. Returns -------