-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac91e8b
commit 9944de1
Showing
24 changed files
with
1,069 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+34.6 KB
docs/source/auto_examples/images/thumb/sphx_glr_plot_advanced_example_thumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+12.6 KB
docs/source/auto_examples/images/thumb/sphx_glr_plot_basic_example_thumb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
:orphan: | ||
|
||
|
||
|
||
.. _sphx_glr_auto_examples: | ||
|
||
|
||
Examples Gallery | ||
================ | ||
|
||
Bellow is a gallery of examples. | ||
|
||
|
||
|
||
.. raw:: html | ||
|
||
<div class="sphx-glr-thumbcontainer" tooltip="Let's present what classo does when using its default parameters on synthetic data"> | ||
|
||
.. only:: html | ||
|
||
.. figure:: /auto_examples/images/thumb/sphx_glr_plot_basic_example_thumb.png | ||
:alt: Basic example | ||
|
||
:ref:`sphx_glr_auto_examples_plot_basic_example.py` | ||
|
||
.. raw:: html | ||
|
||
</div> | ||
|
||
|
||
.. toctree:: | ||
:hidden: | ||
|
||
/auto_examples/plot_basic_example | ||
|
||
.. raw:: html | ||
|
||
<div class="sphx-glr-thumbcontainer" tooltip="Let's present how one can specify different aspects of the problem formulation and model selec..."> | ||
|
||
.. only:: html | ||
|
||
.. figure:: /auto_examples/images/thumb/sphx_glr_plot_advanced_example_thumb.png | ||
:alt: Advanced example | ||
|
||
:ref:`sphx_glr_auto_examples_plot_advanced_example.py` | ||
|
||
.. raw:: html | ||
|
||
</div> | ||
|
||
|
||
.. toctree:: | ||
:hidden: | ||
|
||
/auto_examples/plot_advanced_example | ||
.. raw:: html | ||
|
||
<div class="sphx-glr-clear"></div> | ||
|
||
|
||
|
||
.. only :: html | ||
.. container:: sphx-glr-footer | ||
:class: sphx-glr-footer-gallery | ||
.. container:: sphx-glr-download sphx-glr-download-python | ||
:download:`Download all examples in Python source code: auto_examples_python.zip </auto_examples/auto_examples_python.zip>` | ||
.. container:: sphx-glr-download sphx-glr-download-jupyter | ||
:download:`Download all examples in Jupyter notebooks: auto_examples_jupyter.zip </auto_examples/auto_examples_jupyter.zip>` | ||
.. only:: html | ||
|
||
.. rst-class:: sphx-glr-signature | ||
|
||
`Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"%matplotlib inline" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"\n# Advanced example\n\nLet's present how one can specify different aspects of the problem \nformulation and model selection strategy on classo, using synthetic data\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from classo import classo_problem, random_data\nimport numpy as np" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Generate the data\nThis code snippet generates a problem instance with sparse \u00df in dimension\nd=100 (sparsity d_nonzero=5). The design matrix X comprises n=100 samples generated from an i.i.d standard normal\ndistribution. The dimension of the constraint matrix C is d x k matrix. The noise level is \u03c3=0.5. \nThe input `zerosum=True` implies that C is the all-ones vector and C\u00df=0. The n-dimensional outcome vector y\nand the regression vector \u00df is then generated to satisfy the given constraints. \n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"m, d, d_nonzero, k, sigma = 100, 200, 5, 1, 0.5\n(X, C, y), sol = random_data(m, d, d_nonzero, k, sigma, zerosum=True, seed=1)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Define the classo instance\nNext we can define a default c-lasso problem instance with the generated data:\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"problem = classo_problem(X, y, C)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Change the parameters\nLet's see some example of change in the parameters\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"problem.formulation.huber = True\nproblem.formulation.concomitant = False\nproblem.model_selection.CV = True\nproblem.model_selection.LAMfixed = True\nproblem.model_selection.PATH = True\nproblem.model_selection.StabSelparameters.method = 'max'\nproblem.model_selection.CVparameters.seed = 1\nproblem.model_selection.LAMfixedparameters.rescaled_lam = True\nproblem.model_selection.LAMfixedparameters.lam = .1" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Check parameters\nYou can look at the generated problem instance by typing:\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"print(problem)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Solve optimization problems\n We only use stability selection as default model selection strategy. \nThe command also allows you to inspect the computed stability profile for all variables \nat the theoretical \u03bb\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"problem.solve()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Visualisation\nAfter completion, the results of the optimization and model selection routines \ncan be visualized using\n\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"print(problem.solution)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.0" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
r""" | ||
Advanced example | ||
=============== | ||
Let's present how one can specify different aspects of the problem | ||
formulation and model selection strategy on classo, using synthetic data | ||
""" | ||
|
||
from classo import classo_problem, random_data | ||
import numpy as np | ||
|
||
# %% | ||
# Generate the data | ||
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
# This code snippet generates a problem instance with sparse ß in dimension | ||
# d=100 (sparsity d_nonzero=5). The design matrix X comprises n=100 samples generated from an i.i.d standard normal | ||
# distribution. The dimension of the constraint matrix C is d x k matrix. The noise level is σ=0.5. | ||
# The input `zerosum=True` implies that C is the all-ones vector and Cß=0. The n-dimensional outcome vector y | ||
# and the regression vector ß is then generated to satisfy the given constraints. | ||
|
||
m, d, d_nonzero, k, sigma = 100, 200, 5, 1, 0.5 | ||
(X, C, y), sol = random_data(m, d, d_nonzero, k, sigma, zerosum=True, seed=1) | ||
|
||
# %% | ||
# Define the classo instance | ||
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
# Next we can define a default c-lasso problem instance with the generated data: | ||
|
||
problem = classo_problem(X, y, C) | ||
|
||
|
||
# %% | ||
# Change the parameters | ||
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
# Let's see some example of change in the parameters | ||
|
||
problem.formulation.huber = True | ||
problem.formulation.concomitant = False | ||
problem.model_selection.CV = True | ||
problem.model_selection.LAMfixed = True | ||
problem.model_selection.PATH = True | ||
problem.model_selection.StabSelparameters.method = 'max' | ||
problem.model_selection.CVparameters.seed = 1 | ||
problem.model_selection.LAMfixedparameters.rescaled_lam = True | ||
problem.model_selection.LAMfixedparameters.lam = .1 | ||
|
||
|
||
|
||
# %% | ||
# Check parameters | ||
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
# You can look at the generated problem instance by typing: | ||
|
||
print(problem) | ||
|
||
# %% | ||
# Solve optimization problems | ||
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
# We only use stability selection as default model selection strategy. | ||
# The command also allows you to inspect the computed stability profile for all variables | ||
# at the theoretical λ | ||
|
||
problem.solve() | ||
|
||
# %% | ||
# Visualisation | ||
# ^^^^^^^^^^^^^^^ | ||
# After completion, the results of the optimization and model selection routines | ||
# can be visualized using | ||
|
||
print(problem.solution) |
Oops, something went wrong.