@@ -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 ("\r GRaSP edge count: %i " % order .get_edges ())
210- sys .stdout .flush ()
211+ if verbose :
212+ sys .stdout .write ("\r GRaSP edge count: %i " % order .get_edges ())
213+ sys .stdout .flush ()
211214
212215 runtime = time .perf_counter () - runtime
213-
214- sys .stdout .write ("\n GRaSP completed in: %.2fs \n " % runtime )
215- sys .stdout .flush ()
216+
217+ if verbose :
218+ sys .stdout .write ("\n GRaSP 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