Skip to content

Commit 8d2b002

Browse files
committed
Refactor code and improve test coverage
- Updated `requirements.txt` to ensure proper package management. - Simplified the `get_eigen_include` class in `setup.py`. - Cleaned up comments in `rehline.h` for better readability. - Added regression tests in `test_bugfixes.py` to cover previously fixed bugs. - Enhanced existing tests in `test_cqr.py`, `test_elastic_net.py`, `test_fairsvm.py`, `test_mf.py`, `test_monotonic.py`, `test_multiclass.py`, `test_path_sol.py`, `test_sklearn_mixin.py`, and `test_warmstart.py` for improved assertion clarity and consistency. - Removed unnecessary assertions and improved error messages for better debugging.
1 parent efc3054 commit 8d2b002

65 files changed

Lines changed: 6103 additions & 5609 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
indent_style = space
9+
indent_size = 4
10+
11+
[*.{yaml,yml,toml}]
12+
indent_size = 2
13+
14+
[*.md]
15+
trim_trailing_whitespace = false

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ assignees: ''
2121
## Steps to Reproduce
2222

2323
<!-- Steps to reproduce the bug -->
24-
1.
25-
2.
26-
3.
24+
1.
25+
2.
26+
3.
2727

2828
## Minimal Code Example
2929

@@ -37,12 +37,12 @@ from rehline import ReHLine
3737

3838
## Environment
3939

40-
- OS:
41-
- Python version:
42-
- ReHLine version:
43-
- NumPy version:
44-
- SciPy version:
45-
- scikit-learn version:
40+
- OS:
41+
- Python version:
42+
- ReHLine version:
43+
- NumPy version:
44+
- SciPy version:
45+
- scikit-learn version:
4646

4747
## Additional Context
4848

.github/workflows/wheels.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Build and upload to PyPI
22

3-
on:
3+
on:
44
push:
55
paths-ignore:
66
- .gitignore
@@ -27,7 +27,7 @@ jobs:
2727
uses: pypa/cibuildwheel@v3.3.1
2828
env:
2929
CIBW_BUILD_VERBOSITY: 1
30-
30+
3131
- uses: actions/upload-artifact@v6
3232
with:
3333
name: rehline-wheels-${{ matrix.os }}-${{ strategy.job-index }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ eigen3.zip
4444
local/
4545

4646
# auto API
47-
doc/source/autoapi/
47+
doc/source/autoapi/

.pre-commit-config.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: trailing-whitespace
6+
args: [--markdown-linebreak-ext=md]
7+
- id: end-of-file-fixer
8+
- id: check-yaml
9+
- id: check-added-large-files
10+
args: [--maxkb=500]
11+
- id: check-merge-conflict
12+
13+
- repo: https://github.com/astral-sh/ruff-pre-commit
14+
rev: v0.11.4
15+
hooks:
16+
- id: ruff
17+
args: [--fix, --exit-non-zero-on-fix]
18+
- id: ruff-format
19+
20+
- repo: https://github.com/codespell-project/codespell
21+
rev: v2.4.1
22+
hooks:
23+
- id: codespell
24+
additional_dependencies: [tomli]
25+
args: [--skip, "*.so,*.cpp,*.h,*.zip,eigen-*,build,dist,.git"]

.readthedocs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ sphinx:
2929
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
3030
python:
3131
install:
32-
- requirements: ./requirements.txt
32+
- requirements: ./requirements.txt

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
"tuple": "cpp",
77
"utility": "cpp"
88
}
9-
}
9+
}

README.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ See more details in the [ReHLine documentation](https://rehline-python.readthedo
3030
pip install rehline
3131
```
3232

33+
### Development Install
34+
35+
For contributors and developers:
36+
37+
```bash
38+
git clone https://github.com/softmin/ReHLine-python.git
39+
cd ReHLine-python
40+
pip install -e ".[dev]"
41+
```
42+
43+
To run tests:
44+
45+
```bash
46+
pytest tests/
47+
```
48+
3349
## 🚀 Quick Start
3450

3551
### Scikit-Learn Style API (Recommended)
@@ -79,20 +95,27 @@ print(f"Best params: {grid_search.best_params_}")
7995
from rehline import ReHLine
8096
import numpy as np
8197

98+
# Generate sample data
99+
np.random.seed(42)
100+
X = np.random.randn(100, 5)
101+
y = np.random.choice([-1, 1], size=100)
102+
n, d = X.shape
103+
C = 1.0
104+
82105
# Define custom PLQ loss parameters
83106
clf = ReHLine()
84107
# Set custom U, V matrices for ReLU loss
85108
# and S, T, tau for ReHU loss
86109
## U
87-
clf.U = -(C*y).reshape(1,-1)
110+
clf._U = -(C*y).reshape(1,-1)
88111
## V
89-
clf.V = (C*np.array(np.ones(n))).reshape(1,-1)
112+
clf._V = (C*np.ones(n)).reshape(1,-1)
90113

91114
# Set custom linear constraints A*beta + b >= 0
92115
X_sen = X[:,0]
93116
tol_sen = 0.1
94-
clf.A = np.repeat([X_sen @ X], repeats=[2], axis=0) / n
95-
clf.A[1] = -clf.A[1]
117+
clf._A = np.repeat([X_sen @ X], repeats=[2], axis=0) / n
118+
clf._A[1] = -clf._A[1]
96119

97120
clf.fit(X)
98121
```
@@ -113,7 +136,7 @@ ReHLine excels at solving a wide range of machine learning problems:
113136
| **Sparse Learning** | Feature selection with L1 regularization | Scales to high dimensions |
114137
| **Custom Optimization** | Any PLQ loss with linear constraints | Flexible framework for research |
115138

116-
<!--
139+
<!--
117140
## 📝 Formulation
118141
119142
**ReHLine** is designed to address the empirical regularized ReLU-ReHU minimization problem, named *ReHLine optimization*, of the following form:

doc/source/_static/benchmark/benchmark_FairSVM.html

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
article, aside, figcaption, figure, footer, header, nav, section {
2323
display: block;
2424
}
25-
25+
2626
/* PARAGRAPHS */
2727
h1, h2, h3, h4 {
2828
line-height: 1.25; /* Bigger text is often nicer with smaller line height */
@@ -55,7 +55,7 @@
5555
figure {
5656
margin: 1em 0; /* Default in HTML5 spec: `1em 40px` */
5757
}
58-
58+
5959
/* LINKS */
6060
/* Default browser styles (from Firefox, similar in most browsers) */
6161
a {
@@ -80,7 +80,7 @@
8080
a img {
8181
border: none;
8282
}
83-
83+
8484
/* MISC TEXT-LEVEL ELEMENTS */
8585
/* Make quotations and references more visible */
8686
q, cite {
@@ -95,7 +95,7 @@
9595
sup, sub {
9696
line-height: 0;
9797
}
98-
98+
9999
/* FORMS */
100100
fieldset {
101101
margin: 0; /* Common default is `0 2px` */
@@ -105,7 +105,7 @@
105105
input, button, select {
106106
vertical-align: middle; /* Helps keep form elements roughly aligned */
107107
}
108-
108+
109109
select {
110110
border: 1px solid #aaa;
111111
border-radius: 3px;
@@ -114,7 +114,7 @@
114114
padding: 4px;
115115
color: #333;
116116
}
117-
117+
118118
/* TABLES */
119119
table {
120120
border-collapse: collapse; /* Merges cell borders together */
@@ -128,7 +128,7 @@
128128
td:first-child, th:first-child {
129129
empty-cells: hide; /* Hide empty cells when they're the first in the row */
130130
}
131-
131+
132132
/* Custom stuff on top of the base style sheet */
133133
.status {
134134
font-weight: bold;
@@ -146,28 +146,28 @@
146146
.error {
147147
background-color: firebrick;
148148
}
149-
149+
150150
.summary a {
151151
font-weight: 500;
152152
}
153-
153+
154154
.highlight {
155155
margin: 0;
156156
}
157-
157+
158158
.highlight pre {
159159
padding: 1em;
160160
border: 1px solid #eee;
161161
background-color: #f5f5f5;
162162
margin-bottom: 0.1em;
163163
overflow-x: auto;
164164
}
165-
165+
166166
.source {
167167
margin: 0.3em 0 2em;
168168
font-size: 90%;
169169
}
170-
170+
171171
.source a:visited,
172172
.source a:link {
173173
color: #666;
@@ -177,10 +177,10 @@
177177
color: #666;
178178
text-decoration: underline;
179179
}
180-
180+
181181
/* Pandas dataframe css */
182182
/* Taken from: https://github.com/spatialaudio/nbsphinx/blob/fb3ba670fc1ba5f54d4c487573dbc1b4ecf7e9ff/src/nbsphinx.py#L587-L619 */
183-
183+
184184
table.dataframe {
185185
border: none !important;
186186
border-collapse: collapse;
@@ -226,7 +226,7 @@
226226
div.dataTables_filter, div.dataTables_length {
227227
padding: 20px;
228228
}
229-
229+
230230
.backtotop {
231231
text-decoration: none;
232232
display: flex;
@@ -240,7 +240,7 @@
240240
margin-left: auto;
241241
z-index: 999;
242242
}
243-
243+
244244
.priority1 {
245245
color: purple;
246246
}
@@ -253,7 +253,7 @@
253253
td.number {
254254
text-align: right;
255255
}
256-
256+
257257
/* Style buttons */
258258
.btn {
259259
background-color: DodgerBlue; /* Blue background */
@@ -879,23 +879,23 @@ <h1>
879879
</label>
880880
<select id=select_cpu onchange="change(['cpu', 'ram (GB)', 'cuda'])">
881881
<option value=""> Any </option>
882-
882+
883883
<option value="<b>cpu</b>: 4"> 4 </option>
884884
</select>
885885
<label for=select_ram(GB) style="padding-left: 20px; color: #333">
886886
RAM (GB)
887887
</label>
888888
<select id=select_ram(GB) onchange="change(['cpu', 'ram (GB)', 'cuda'])">
889889
<option value=""> Any </option>
890-
890+
891891
<option value="<b>ram (GB)</b>: 31"> 31 </option>
892892
</select>
893893
<label for=select_cuda style="padding-left: 20px; color: #333">
894894
CUDA
895895
</label>
896896
<select id=select_cuda onchange="change(['cpu', 'ram (GB)', 'cuda'])">
897897
<option value=""> Any </option>
898-
898+
899899
<option value="<b>cuda</b>: NVIDIA GeForce RTX 4090: cuda_12.2"> NVIDIA GeForce RTX 4090: cuda_12.2 </option>
900900
</select>
901901
</div>
@@ -913,46 +913,46 @@ <h1>
913913
<tr>
914914
<td class="fname">
915915
<a href="benchmark_FairSVM_benchopt_run_2023-10-12_22h11m38.html">
916-
916+
917917
FairSVM 2023-10-12 22h11m38
918918
</a>
919919
<input type="checkbox" name="checkfiles" data-result="benchopt_run_2023-10-12_22h11m38.parquet" data-html="benchmark_FairSVM_benchopt_run_2023-10-12_22h11m38.html" style="display:none;">
920920
</td>
921921
<td class="datasets">
922922
<ul style="list-style-type: none; margin-top: 0;">
923923
<div class=dataset>
924-
924+
925925
Classification_data
926926
<li><span style="font-size: 80%;padding-left:15px;padding-bottom:5px;">dataset_name=steel-plates-fault </span> </li>
927-
927+
928928
</div>
929929
<div class=dataset>
930-
930+
931931
<li><span style="font-size: 80%;padding-left:15px;padding-bottom:5px;">dataset_name=philippine </span> </li>
932-
932+
933933
</div>
934934
<div class=dataset>
935-
935+
936936
<li><span style="font-size: 80%;padding-left:15px;padding-bottom:5px;">dataset_name=sylva_prior </span> </li>
937-
937+
938938
</div>
939939
<div class=dataset>
940-
940+
941941
<li><span style="font-size: 80%;padding-left:15px;padding-bottom:5px;">dataset_name=creditcard </span> </li>
942-
942+
943943
</div>
944944
</ul>
945945

946946
</td>
947-
947+
948948
<td class="sysinfo">
949949
<ul style="list-style-type: none; margin-top: 0;">
950950
<li>
951951
<b>CPU</b>: 4
952952
<button data-idx=0 id=btn_subinfo0 class="button buttoncent" style="float:right;">
953953
<i class='fas fa-plus-circle'></i>
954954
</button>
955-
955+
956956
</li>
957957
<li>
958958
<b>RAM (GB)</b>: 31

0 commit comments

Comments
 (0)