Skip to content

Commit 1c37775

Browse files
committed
add tutorials
1 parent d97c52a commit 1c37775

File tree

12 files changed

+421
-85
lines changed

12 files changed

+421
-85
lines changed

doc/source/autoapi/rehline/index.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ Overview
1919
- Empirical Risk Minimization (ERM) with a piecewise linear-quadratic (PLQ) objective with a ridge penalty.
2020

2121

22+
.. list-table:: Function
23+
:header-rows: 0
24+
:widths: auto
25+
:class: summarytable
26+
27+
* - :py:obj:`ReHLine_solver <rehline.ReHLine_solver>`\ (X, U, V, Tau, S, T, A, b, max_iter, tol, shrink, verbose, trace_freq)
28+
- \-
29+
2230

2331

2432
Classes
@@ -101,7 +109,7 @@ Classes
101109
>>> U = -(C*y).reshape(1,-1)
102110
>>> L = U.shape[0]
103111
>>> V = (C*np.array(np.ones(n))).reshape(1,-1)
104-
>>> clf = ReHLine(loss={'name': 'svm'}, C=C)
112+
>>> clf = ReHLine(C=C)
105113
>>> clf.U, clf.V = U, V
106114
>>> clf.fit(X=X)
107115
>>> print('sol privided by rehline: %s' %clf.coef_)
@@ -320,6 +328,10 @@ Classes
320328

321329

322330

331+
Functions
332+
---------
333+
.. py:function:: ReHLine_solver(X, U, V, Tau=np.empty(shape=(0, 0)), S=np.empty(shape=(0, 0)), T=np.empty(shape=(0, 0)), A=np.empty(shape=(0, 0)), b=np.empty(shape=0), max_iter=1000, tol=0.0001, shrink=1, verbose=1, trace_freq=100)
334+
323335
324336
325337

doc/source/example.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Example Gallery
55
---------------
66

77
.. nblinkgallery::
8-
:caption: A few links
8+
:caption: Emprical Risk Minimization
99
:name: rst-link-gallery
1010

1111
examples/QR.ipynb

doc/source/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
- Homepage: `https://rehline.github.io/ <https://rehline.github.io/>`_
3333
- GitHub repo: `https://github.com/softmin/ReHLine-python <https://github.com/softmin/ReHLine-python>`_
34-
- Documentation: `https://rehline.readthedocs.io <https://rehline.readthedocs.io/en/latest/>`_
34+
- Documentation: `https://rehline-python.readthedocs.io <https://rehline-python.readthedocs.io/en/latest/>`_
3535
- PyPi: `https://pypi.org/project/rehline <https://pypi.org/project/rehline>`_
3636
- Paper: `NeurIPS | 2023 <https://openreview.net/pdf?id=3pEBW2UPAD>`_
3737
.. - Open Source: `MIT license <https://opensource.org/licenses/MIT>`_
@@ -76,5 +76,6 @@ If you use this code please star 🌟 the repository and cite the following pape
7676
:hidden:
7777

7878
getting_started
79+
tutorials
7980
example
8081
benchmark

doc/source/tutorials.rst

Lines changed: 35 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Tutorials
2-
=========
2+
---------
33

4-
`ReHLine` is designed to address the empirical regularized ReLU-ReHU minimization problem, named *ReHLine optimization*, of the following form:
4+
`ReHLine` is designed to address the regularized ReLU-ReHU minimization problem, named *ReHLine optimization*, of the following form:
55

66
.. math::
77
@@ -17,87 +17,43 @@ Some popular examples include SVMs with fairness constraints (FairSVM),
1717
elastic net regularized quantile regression (ElasticQR),
1818
and ridge regularized Huber minimization (RidgeHuber).
1919

20-
.. image:: ./figs/tab.png
20+
See `Manual ReHLine Formulation`_ documentation for more details and examples on converting your problem to ReHLine formulation.
2121

22-
Solving PLQ ERMs
23-
----------------
2422

25-
Loss
26-
****
23+
Moreover, the following specific classes of formulations can be directly solved by `ReHLine`.
2724

28-
.. code:: python
29-
30-
# name (str): name of the custom loss function
31-
# loss_kwargs: more keys and values for loss parameters
32-
loss = {'name': <loss_name>, <**loss_kwargs>}
25+
- **Empirical Risk Minimization** (ERM) with various loss functions, see `ReHLine: Empirical Risk Minimization`_.
26+
- **Matrix Factorization** (MF) with with various loss functions, see `ReHLine: Matrix Factorization`_.
3327

34-
.. list-table::
35-
36-
* - **SVM**
37-
- | ``loss_name``: 'hinge' / 'svm' / 'SVM'
38-
|
39-
| *Example:* ``loss = {'name': 'SVM'}``
40-
41-
* - **Quantile Reg**
42-
- | ``loss_name``: 'check' / 'quantile' / 'quantile regression' / 'QR'
43-
| ``qt`` (*float*): qt
44-
|
45-
| *Example:* ``loss = {'name': 'QR', 'qt': 0.25}``
46-
47-
* - **Smooth SVM**
48-
- | ``loss_name``: 'sSVM' / 'smooth SVM' / 'smooth hinge'
49-
|
50-
| *Example:* ``loss = {'name': 'sSVM'}``
51-
52-
* - **Huber**
53-
- | ``loss_name``: 'huber' / 'Huber'
54-
|
55-
| *Example:* ``loss = {'name': 'huber'}``
56-
57-
* - **SVR**
58-
- | ``loss_name``: 'SVR' / 'svr'
59-
| ``epsilon`` (*float*): 0.1
60-
|
61-
| *Example:* ``loss = {'name': 'svr', 'epsilon': 0.1}``
62-
63-
constraint
64-
**********
65-
66-
.. code:: python
67-
68-
# list of
69-
# name (str): name of the custom loss function
70-
# loss_kwargs: more keys and values for loss parameters
71-
constraint = [{'name': <loss_name>, <**loss_kwargs>}, ...]
28+
List of Tutorials
29+
=================
7230

7331
.. list-table::
32+
:align: left
33+
:widths: 10 10 20
34+
:header-rows: 1
35+
36+
* - tutorials
37+
- | API
38+
- | description
39+
* - `Manual ReHLine Formulation <./tutorials/ReHLine_manual.rst>`_
40+
- | `ReHLine <./autoapi/rehline/index.html#rehline.ReHLine>`_
41+
- | ReHLine minimization with manual parameter settings.
42+
43+
* - `ReHLine: Empirical Risk Minimization <./tutorials/ReHLine_ERM.rst>`_
44+
- | `plqERM_Ridge <./autoapi/rehline/index.html#rehline.plqERM_Ridge>`_
45+
- | Empirical Risk Minimization (ERM) with a piecewise linear-quadratic (PLQ) objective with a ridge penalty.
46+
47+
* - `ReHLine: Matrix Factorization <./tutorials/ReHLine_MF.rst>`_
48+
- | `plqMF_Ridge <./autoapi/rehline/index.html#rehline.plqERM_Ridge>`_
49+
- | Matrix Factorization (MF) with a piecewise linear-quadratic (PLQ) objective with a ridge penalty.
50+
51+
.. toctree::
52+
:maxdepth: 2
53+
:hidden:
54+
55+
./tutorials/ReHLine_manual
56+
./tutorials/ReHLine_ERM
57+
./tutorials/loss
58+
./tutorials/constraint
7459

75-
* - **SVM**
76-
- | ``loss_name``: 'hinge' / 'svm' / 'SVM'
77-
|
78-
| *Example:* ``loss = {'name': 'SVM'}``
79-
80-
* - **Quantile Reg**
81-
- | ``loss_name``: 'check' / 'quantile' / 'quantile regression' / 'QR'
82-
| ``qt`` (*list*): [q1, q2, ... qK]
83-
|
84-
| *Example:* ``loss = {'name': 'QR', 'qt': [0.25, 0.75]}``
85-
86-
* - **Smooth SVM**
87-
- | ``loss_name``: 'sSVM' / 'smooth SVM' / 'smooth hinge'
88-
|
89-
| *Example:* ``loss = {'name': 'sSVM'}``
90-
91-
* - **Huber**
92-
- | ``loss_name``: 'huber' / 'Huber'
93-
|
94-
| *Example:* ``loss = {'name': 'huber'}``
95-
96-
* - **SVR**
97-
- | ``loss_name``: 'SVR' / 'svr'
98-
| ``epsilon`` (*float*): 0.1
99-
|
100-
| *Example:* ``loss = {'name': 'svr', 'epsilon': 0.1}``
101-
102-
manual ReHLine
103-
--------------
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
ReHLine: Empirical Risk Minimization
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
The objective function is given by the following PLQ formulation, where :math:`\phi` is a convex piecewise linear function and :math:`\lambda` is a positive regularization parameter.
5+
6+
.. math::
7+
8+
\min_{\pmb{\beta} \in \mathbb{R}^d} \sum_{i=1}^n \text{PLQ}(y_i, \mathbf{x}_i^T \pmb{\beta}) + \frac{1}{2} \| \pmb{\beta} \|_2^2, \ \text{ s.t. } \
9+
\mathbf{A} \pmb{\beta} + \mathbf{b} \geq \mathbf{0},
10+
11+
where :math:`\text{PLQ}(\cdot, \cdot)` is a convex piecewise linear quadratic function, see `Loss <./loss.rst>`_ for build-in loss functions, and :math:`\mathbf{A}` is a :math:`K \times d` matrix, and :math:`\mathbf{b}` is a :math:`K`-dimensional vector for linear constraints, see `Constraints <./constraint.rst>`_ for more details.
12+
13+
For example, it supports the following loss functions and constraints.
14+
15+
.. image:: ../figs/tab.png
16+
17+
Example
18+
-------
19+
20+
.. nblinkgallery::
21+
:caption: Emprical Risk Minimization
22+
:name: rst-link-gallery
23+
24+
../examples/QR.ipynb
25+
../examples/SVM.ipynb
26+
../examples/FairSVM.ipynb
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ReHLine: Matrix Factorization
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)