Skip to content

Commit aa758a5

Browse files
committed
update some options
1 parent a11518a commit aa758a5

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

rehline/_path_sol.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ def plqERM_Ridge_path_sol(
2323
shrink=1,
2424
warm_start=False,
2525
return_time=True,
26-
plot_path=False
2726
):
2827
"""
2928
Compute the PLQ Empirical Risk Minimization (ERM) path over a range of regularization parameters.
@@ -44,6 +43,7 @@ def plqERM_Ridge_path_sol(
4443
constraint : list of dict, optional (default=[])
4544
List of constraints applied to the optimization problem. Each constraint should be represented
4645
as a dictionary compatible with the solver.
46+
4747
4848
eps : float, default=1e-3
4949
Defines the range of regularization values when `Cs` is not provided. Specifically, the smallest
@@ -64,6 +64,8 @@ def plqERM_Ridge_path_sol(
6464
6565
verbose : int, default=0
6666
Controls verbosity level of output. Set to higher values (e.g., 1 or 2) for detailed progress logs.
67+
When verbose = 1, only print path results table;
68+
when verbose = 2, print path results table and path solution plot.
6769
6870
shrink : float, default=1
6971
Shrinkage factor for the solver, potentially influencing convergence behavior.
@@ -108,22 +110,22 @@ def plqERM_Ridge_path_sol(
108110
>>> y = np.sign(X.dot(beta0) + np.random.randn(n))
109111
>>> # define loss function
110112
>>> loss = {'name': 'svm'}
111-
>>> Cs = [2000, 3000, 4000]
112-
>>> constrain = [{'name': 'none'}]
113+
>>> Cs = np.logspace(-1,3,15)
114+
>>> constraint = [{'name': 'nonnegative'}]
113115
114116
115117
>>> # calculate
116-
>>> Cs, times, n_iters, losses, norms, coefs = plqERM_path_sol(
117-
... X, y, loss=loss, Cs=Cs, max_iter=100000,tol=1e-4,verbose=1,
118-
... warm_start=False, constrain=constrain, return_time=True, plot_path=True
118+
>>> Cs, times, n_iters, losses, norms, coefs = plqERM_Ridge_path_sol(
119+
... X, y, loss=loss, Cs=Cs, max_iter=100000,tol=1e-4,verbose=2,
120+
... warm_start=False, constraint=constraint, return_time=True
119121
... )
120122
121123
"""
122124

123125
n_samples, n_features = X.shape
124126

125127
if Cs is None:
126-
Cs = np.logspace(-2, 3, n_Cs)
128+
Cs = np.logspace(np.log10(eps), 3, n_Cs)
127129

128130
# Sort Cs to ensure computation starts from the smallest value
129131
Cs = np.sort(Cs)
@@ -194,7 +196,7 @@ def plqERM_Ridge_path_sol(
194196
avg_time_per_iter = total_time / sum(n_iters) if sum(n_iters) > 0 else float("inf")
195197

196198

197-
if verbose:
199+
if verbose >= 1:
198200
print("\nPLQ ERM Path Solution Results")
199201
print("=" * 90)
200202
print(f"{'C Value':<15}{'Iterations':<15}{'Time (s)':<20}{'Loss':<20}{'L2 Norm':<20}")
@@ -211,7 +213,7 @@ def plqERM_Ridge_path_sol(
211213
print(f"{'Avg Time/Iter':<12}{avg_time_per_iter:.6f} sec")
212214
print("=" * 90)
213215

214-
if plot_path:
216+
if verbose >= 2:
215217
import matplotlib.pyplot as plt
216218
plt.figure(figsize=(10, 6))
217219
for i in range(n_features):

0 commit comments

Comments
 (0)