Skip to content

Commit

Permalink
Merge pull request #174 from X3ZvaWQ/main
Browse files Browse the repository at this point in the history
Slightly improve the user experience of GRaSP.
  • Loading branch information
kunwuz authored Mar 25, 2024
2 parents 340d60a + c16aaeb commit e1e2a6f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions causallearn/search/PermutationBased/GRaSP.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def grasp(
depth: Optional[int] = 3,
maxP: Optional[float] = None,
parameters: Optional[Dict[str, Any]] = None,
) -> Dict[str, Any]:
verbose: Optional[bool] = True,
) -> GeneralGraph:
"""
Perform a greedy relaxation of the sparsest permutation (GRaSP) algorithm
Expand All @@ -96,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
-------
Expand Down Expand Up @@ -206,13 +208,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):
Expand Down

0 comments on commit e1e2a6f

Please sign in to comment.