Skip to content

Commit

Permalink
update documented examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Simpson committed Dec 11, 2020
1 parent 9944de1 commit 8129b48
Show file tree
Hide file tree
Showing 68 changed files with 2,213 additions and 418 deletions.
4 changes: 2 additions & 2 deletions classo/solve_R1.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def Classo_R1(pb, lam):


def pathlasso_R1(pb, path, n_active = False, return_sp_path = False):
n = pb.dim[0]
n, d, k = pb.dim
BETA, tol = [], pb.tol
if pb.type == "Path-Alg":
beta, sp_path = solve_path(pb.matrix, path[-1], n_active, 0, "R1")
Expand All @@ -181,7 +181,7 @@ def pathlasso_R1(pb, path, n_active = False, return_sp_path = False):
if type(n_active) == int and n_active > 0:
n_act = n_active
else:
n_act = n
n_act = d
for lam in path:
X = Classo_R1(pb, lam)
beta, init = X[0], X[1]
Expand Down
7 changes: 5 additions & 2 deletions classo/solve_R2.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def Classo_R2(pb, lam, compute = True):

tol = pb.tol * LA.norm(y) / LA.norm(A, "fro") # tolerance rescaled


"""
# cvx
# call to the cvx function of minimization
if pb_type == "cvx":
Expand All @@ -85,6 +87,7 @@ def Classo_R2(pb, lam, compute = True):
if regpath:
return (x.value, True)
return x.value
"""

if compute:
pb.compute_param()
Expand Down Expand Up @@ -176,7 +179,7 @@ def Classo_R2(pb, lam, compute = True):


def pathlasso_R2(pb, path, n_active = False):
n = pb.dim[0]
n, d, k = pb.dim
BETA, tol = [], pb.tol
if pb.type == "Path-Alg":
(A, C, y) = pb.matrix
Expand All @@ -194,7 +197,7 @@ def pathlasso_R2(pb, path, n_active = False):
if type(n_active) == int and n_active > 0:
n_act = n_active
else:
n_act = n
n_act = d
for lam in path:
X = Classo_R2(pb, lam, compute = False)
BETA.append(X[0])
Expand Down
2 changes: 1 addition & 1 deletion classo/solve_R3.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def pathlasso_R3(pb, path, n_active = False):
if type(n_active) == int and n_active > 0:
n_act = n_active
else:
n_act = n
n_act = d

for lam in path:
X = Classo_R3(pb, lam)
Expand Down
4 changes: 2 additions & 2 deletions classo/solve_R4.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def Classo_R4(pb, lam):


def pathlasso_R4(pb, path, n_active = False):
n = pb.dim[0]
n, d, k = pb.dim
BETA, SIGMA, tol = [], [], pb.tol
pb.type = "DR"
save_init = pb.init
Expand All @@ -140,7 +140,7 @@ def pathlasso_R4(pb, path, n_active = False):
if type(n_active) == int and n_active > 0:
n_act = n_active
else:
n_act = n
n_act = d

for lam in path:
X = Classo_R4(pb, lam)
Expand Down
Binary file modified docs/source/auto_examples/auto_examples_jupyter.zip
Binary file not shown.
Binary file modified docs/source/auto_examples/auto_examples_python.zip
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
44 changes: 43 additions & 1 deletion docs/source/auto_examples/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Bellow is a gallery of examples.

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="Let&#x27;s present what classo does when using its default parameters on synthetic data">
<div class="sphx-glr-thumbcontainer" tooltip="Let&#x27;s present what classo does when using its default parameters on synthetic data.">

.. only:: html

Expand Down Expand Up @@ -53,6 +53,48 @@ Bellow is a gallery of examples.
:hidden:

/auto_examples/plot_advanced_example

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="The next microbiome example considers the `Central Park Soil dataset &lt;https://github.com/Leo-S...">

.. only:: html

.. figure:: /auto_examples/images/thumb/sphx_glr_plot_pH_example_thumb.png
:alt: pH prediction using the Central Park soil dataset

:ref:`sphx_glr_auto_examples_plot_pH_example.py`

.. raw:: html

</div>


.. toctree::
:hidden:

/auto_examples/plot_pH_example

.. raw:: html

<div class="sphx-glr-thumbcontainer" tooltip="We first consider the `COMBO data set &lt;https://github.com/Leo-Simpson/c-lasso/tree/master/examp...">

.. only:: html

.. figure:: /auto_examples/images/thumb/sphx_glr_plot_combo_example_thumb.png
:alt: BMI prediction using the COMBO dataset

:ref:`sphx_glr_auto_examples_plot_combo_example.py`

.. raw:: html

</div>


.. toctree::
:hidden:

/auto_examples/plot_combo_example
.. raw:: html

<div class="sphx-glr-clear"></div>
Expand Down
198 changes: 198 additions & 0 deletions docs/source/auto_examples/plot_COMBO_example.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# BMI prediction using the COMBO dataset \n\nWe first consider the `COMBO data set <https://github.com/Leo-Simpson/c-lasso/tree/master/examples/COMBO_data>`_\nand show how to predict Body Mass Index (BMI) from microbial genus abundances and two non-compositional covariates using \"filtered_data\".\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from classo import csv_to_np, classo_problem, clr\nimport numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Load microbiome and covariate data X\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"X0 = csv_to_np('COMBO_data/complete_data/GeneraCounts.csv', begin = 0).astype(float)\nX_C = csv_to_np('COMBO_data/CaloriData.csv', begin = 0).astype(float)\nX_F = csv_to_np('COMBO_data/FatData.csv', begin = 0).astype(float)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Load BMI measurements y\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"y = csv_to_np('COMBO_data/BMI.csv', begin = 0).astype(float)[:, 0]\nlabels = csv_to_np('COMBO_data/complete_data/GeneraPhylo.csv').astype(str)[:, -1]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Normalize/transform data\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"y = y - np.mean(y) #BMI data (n = 96)\nX_C = X_C - np.mean(X_C, axis = 0) #Covariate data (Calorie)\nX_F = X_F - np.mean(X_F, axis = 0) #Covariate data (Fat)\nX0 = clr(X0, 1 / 2).T"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Set up design matrix and zero-sum constraints for 45 genera\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"X = np.concatenate((X0, X_C, X_F, np.ones((len(X0), 1))), axis = 1) # Joint microbiome and covariate data and offset\nlabel = np.concatenate([labels, np.array(['Calorie', 'Fat', 'Bias'])])\nC = np.ones((1, len(X[0])))\nC[0, -1], C[0, -2], C[0, -3] = 0., 0., 0."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Set up c-lassso problem\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"problem = classo_problem(X, y, C)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use stability selection with theoretical lambda [Combettes & M\u00fcller, 2020b]\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"problem.model_selection.StabSelparameters.method = 'lam'\nproblem.model_selection.StabSelparameters.threshold_label = 0.5"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Use formulation R3\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"problem.formulation.concomitant = True\n\nproblem.solve()\nprint(problem)\nprint(problem.solution)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Use formulation R4\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"problem.formulation.huber = True\nproblem.formulation.concomitant = True\n\nproblem.solve()\nprint(problem)\nprint(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
}
Loading

0 comments on commit 8129b48

Please sign in to comment.