Skip to content

Commit e1e2a6f

Browse files
authoredMar 25, 2024
Merge pull request #174 from X3ZvaWQ/main
Slightly improve the user experience of GRaSP.
2 parents 340d60a + c16aaeb commit e1e2a6f

File tree

1 file changed

+10
-6
lines changed
  • causallearn/search/PermutationBased

1 file changed

+10
-6
lines changed
 

‎causallearn/search/PermutationBased/GRaSP.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ def grasp(
8080
depth: Optional[int] = 3,
8181
maxP: Optional[float] = None,
8282
parameters: Optional[Dict[str, Any]] = None,
83-
) -> Dict[str, Any]:
83+
verbose: Optional[bool] = True,
84+
) -> GeneralGraph:
8485
"""
8586
Perform a greedy relaxation of the sparsest permutation (GRaSP) algorithm
8687
@@ -96,6 +97,7 @@ def grasp(
9697
parameters['lambda']: regularization parameter
9798
parameters['dlabel']: for variables with multi-dimensions,
9899
indicate which dimensions belong to the i-th variable.
100+
verbose : whether to print the time cost and verbose output of the algorithm.
99101
100102
Returns
101103
-------
@@ -206,13 +208,15 @@ def grasp(
206208
order.bump_edges(len(y_parents))
207209

208210
while dfs(depth - 1, set(), [], order, score):
209-
sys.stdout.write("\rGRaSP edge count: %i " % order.get_edges())
210-
sys.stdout.flush()
211+
if verbose:
212+
sys.stdout.write("\rGRaSP edge count: %i " % order.get_edges())
213+
sys.stdout.flush()
211214

212215
runtime = time.perf_counter() - runtime
213-
214-
sys.stdout.write("\nGRaSP completed in: %.2fs \n" % runtime)
215-
sys.stdout.flush()
216+
217+
if verbose:
218+
sys.stdout.write("\nGRaSP completed in: %.2fs \n" % runtime)
219+
sys.stdout.flush()
216220

217221
for y in range(p):
218222
for x in order.get_parents(y):

0 commit comments

Comments
 (0)
Failed to load comments.