Skip to content

Commit

Permalink
Update stable version
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanKossaifi committed Dec 7, 2020
1 parent bc3e3a4 commit 55bdab7
Show file tree
Hide file tree
Showing 374 changed files with 15,763 additions and 8,330 deletions.
6 changes: 3 additions & 3 deletions home.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
<html lang="en">
<head>

<meta http-equiv="refresh" content="1; url=https://tensorly.github.io/stable/home.html">
<meta http-equiv="refresh" content="1; url=https://tensorly.github.io/stable/index.html">

<meta name="keywords" content="tensor learning, tensor decomposition, tensor operations">
<meta name="description" content="TensorLy: Tensor learning in Python -- Redirection to stable">
<meta name="author" content="Jean Kossaifi">
<title>TensorLy: Tensor learning in Python</title>

<script type="text/javascript">
window.location.href = "https://tensorly.github.io/stable/home.html"
window.location.href = "https://tensorly.github.io/stable/index.html"
</script>

</head>

<body>

If you are not redirected automatically, follow the link to the <a href='https://tensorly.github.io/stable/home.html'>stable version</a> or <a href='https://tensorly.github.io/dev/home.html'>dev version</a>.
If you are not redirected automatically, follow the link to the <a href='https://tensorly.github.io/stable/index.html'>stable version</a> or <a href='https://tensorly.github.io/dev/index.html'>dev version</a>.

</body>

Expand Down
4 changes: 0 additions & 4 deletions stable/.buildinfo

This file was deleted.

Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@

"""
Using line search with PARAFAC
==============================
Example on how to use :func:`tensorly.decomposition.parafac` with line search to accelerate convergence.
"""
import matplotlib.pyplot as plt

from time import time
import numpy as np
import tensorly as tl
from tensorly.random import random_cp
from tensorly.decomposition import parafac
import matplotlib.pyplot as plt
from tensorly.decomposition import CP, parafac

tol = np.logspace(-1, -9)
err = np.empty_like(tol)
Expand All @@ -27,20 +26,28 @@
for ii, toll in enumerate(tol):
# Run PARAFAC decomposition without line search and time
start = time()
fac = parafac(tensor, rank=3, n_iter_max=2000000, tol=toll)
cp = CP(rank=3, n_iter_max=2000000, tol=toll, linesearch=False)
fac = cp.fit_transform(tensor)
tt[ii] = time() - start
# Run PARAFAC decomposition with line search and time
err[ii] = tl.norm(tl.cp_to_tensor(fac) - tensor)

# Run PARAFAC decomposition with line search and time
for ii, toll in enumerate(tol):
start = time()
fac_ls = parafac(tensor, rank=3, n_iter_max=2000000, tol=toll, linesearch=True)
cp = CP(rank=3, n_iter_max=2000000, tol=toll, linesearch=True)
fac_ls = cp.fit_transform(tensor)
tt_ls[ii] = time() - start

# Calculate the error of both decompositions
err[ii] = tl.norm(tl.cp_to_tensor(fac) - tensor)
err_ls[ii] = tl.norm(tl.cp_to_tensor(fac_ls) - tensor)

plt.loglog(tt, err - err_min, '.', label="No line search")
plt.loglog(tt_ls, err_ls - err_min, '.r', label="Line search")
plt.ylabel("Time")
plt.xlabel("Error")
plt.legend()

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.loglog(tt, err - err_min, '.', label="No line search")
ax.loglog(tt_ls, err_ls - err_min, '.r', label="Line search")
ax.legend()
ax.set_ylabel("Time")
ax.set_xlabel("Error")

plt.show()
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Using line search with PARAFAC\n\nExample on how to use :func:`tensorly.decomposition.parafac` with line search to accelerate convergence.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n\nfrom time import time\nimport numpy as np\nimport tensorly as tl\nfrom tensorly.random import random_cp\nfrom tensorly.decomposition import CP, parafac\n\ntol = np.logspace(-1, -9)\nerr = np.empty_like(tol)\nerr_ls = np.empty_like(tol)\ntt = np.empty_like(tol)\ntt_ls = np.empty_like(tol)\ntensor = random_cp((10, 10, 10), 3, random_state=1234, full=True)\n\n# Get a high-accuracy decomposition for comparison\nfac = parafac(tensor, rank=3, n_iter_max=2000000, tol=1.0e-15, linesearch=True)\nerr_min = tl.norm(tl.cp_to_tensor(fac) - tensor)\n\nfor ii, toll in enumerate(tol):\n\t# Run PARAFAC decomposition without line search and time\n start = time()\n cp = CP(rank=3, n_iter_max=2000000, tol=toll, linesearch=False)\n fac = cp.fit_transform(tensor)\n tt[ii] = time() - start\n err[ii] = tl.norm(tl.cp_to_tensor(fac) - tensor)\n\n# Run PARAFAC decomposition with line search and time\nfor ii, toll in enumerate(tol):\n start = time()\n cp = CP(rank=3, n_iter_max=2000000, tol=toll, linesearch=True)\n fac_ls = cp.fit_transform(tensor)\n tt_ls[ii] = time() - start\n\n # Calculate the error of both decompositions\n err_ls[ii] = tl.norm(tl.cp_to_tensor(fac_ls) - tensor)\n\n\nfig = plt.figure()\nax = fig.add_subplot(1, 1, 1)\nax.loglog(tt, err - err_min, '.', label=\"No line search\")\nax.loglog(tt_ls, err_ls - err_min, '.r', label=\"Line search\")\nax.legend()\nax.set_ylabel(\"Time\")\nax.set_xlabel(\"Error\")\n\nplt.show()"
]
}
],
"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.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def to_image(tensor):
cp_reconstruction = tl.cp_to_tensor((weights, factors))

# Tucker decomposition
core, tucker_factors = tucker(image, ranks=tucker_rank, init='random', tol=10e-5, random_state=random_state)
core, tucker_factors = tucker(image, rank=tucker_rank, init='random', tol=10e-5, random_state=random_state)
tucker_reconstruction = tl.tucker_to_tensor((core, tucker_factors))

# Plotting the original and reconstruction from the decompositions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\nimport tensorly as tl\nimport numpy as np\nfrom scipy.misc import face\nfrom scipy.ndimage import zoom\nfrom tensorly.decomposition import parafac\nfrom tensorly.decomposition import tucker\nfrom math import ceil\n\n\nrandom_state = 12345\n\nimage = face()\nimage = tl.tensor(zoom(face(), (0.3, 0.3, 1)), dtype='float64')\n\ndef to_image(tensor):\n \"\"\"A convenience function to convert from a float dtype back to uint8\"\"\"\n im = tl.to_numpy(tensor)\n im -= im.min()\n im /= im.max()\n im *= 255\n return im.astype(np.uint8)\n\n# Rank of the CP decomposition\ncp_rank = 25\n# Rank of the Tucker decomposition\ntucker_rank = [100, 100, 2]\n\n# Perform the CP decomposition\nweights, factors = parafac(image, rank=cp_rank, init='random', tol=10e-6)\n# Reconstruct the image from the factors\ncp_reconstruction = tl.cp_to_tensor((weights, factors))\n\n# Tucker decomposition\ncore, tucker_factors = tucker(image, ranks=tucker_rank, init='random', tol=10e-5, random_state=random_state)\ntucker_reconstruction = tl.tucker_to_tensor((core, tucker_factors))\n\n# Plotting the original and reconstruction from the decompositions\nfig = plt.figure()\nax = fig.add_subplot(1, 3, 1)\nax.set_axis_off()\nax.imshow(to_image(image))\nax.set_title('original')\n\nax = fig.add_subplot(1, 3, 2)\nax.set_axis_off()\nax.imshow(to_image(cp_reconstruction))\nax.set_title('CP')\n\nax = fig.add_subplot(1, 3, 3)\nax.set_axis_off()\nax.imshow(to_image(tucker_reconstruction))\nax.set_title('Tucker')\n\nplt.tight_layout()\nplt.show()"
"import matplotlib.pyplot as plt\nimport tensorly as tl\nimport numpy as np\nfrom scipy.misc import face\nfrom scipy.ndimage import zoom\nfrom tensorly.decomposition import parafac\nfrom tensorly.decomposition import tucker\nfrom math import ceil\n\n\nrandom_state = 12345\n\nimage = face()\nimage = tl.tensor(zoom(face(), (0.3, 0.3, 1)), dtype='float64')\n\ndef to_image(tensor):\n \"\"\"A convenience function to convert from a float dtype back to uint8\"\"\"\n im = tl.to_numpy(tensor)\n im -= im.min()\n im /= im.max()\n im *= 255\n return im.astype(np.uint8)\n\n# Rank of the CP decomposition\ncp_rank = 25\n# Rank of the Tucker decomposition\ntucker_rank = [100, 100, 2]\n\n# Perform the CP decomposition\nweights, factors = parafac(image, rank=cp_rank, init='random', tol=10e-6)\n# Reconstruct the image from the factors\ncp_reconstruction = tl.cp_to_tensor((weights, factors))\n\n# Tucker decomposition\ncore, tucker_factors = tucker(image, rank=tucker_rank, init='random', tol=10e-5, random_state=random_state)\ntucker_reconstruction = tl.tucker_to_tensor((core, tucker_factors))\n\n# Plotting the original and reconstruction from the decompositions\nfig = plt.figure()\nax = fig.add_subplot(1, 3, 1)\nax.set_axis_off()\nax.imshow(to_image(image))\nax.set_title('original')\n\nax = fig.add_subplot(1, 3, 2)\nax.set_axis_off()\nax.imshow(to_image(cp_reconstruction))\nax.set_title('CP')\n\nax = fig.add_subplot(1, 3, 3)\nax.set_axis_off()\nax.imshow(to_image(tucker_reconstruction))\nax.set_title('Tucker')\n\nplt.tight_layout()\nplt.show()"
]
}
],
Expand All @@ -46,7 +46,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.8.5"
}
},
"nbformat": 4,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified stable/_images/math/1060b27e042e5e7224ea357bd9cad0b44248b14f.png
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 modified stable/_images/math/1b782627d1b0843af085aa264886d73f35e56715.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 modified stable/_images/math/267d50f457b0de0e577cc9fcb19eab6528b8c899.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 modified stable/_images/math/38c1e934184582677d3addf0297a1f91c8094fe9.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 modified stable/_images/math/3c1670a65c8af230b8412e85bd659415a4aba0e7.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 modified stable/_images/math/49123964effe20fb6ef3ee1778a5e52b9dbb6d73.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 modified stable/_images/math/501fd4b16bcaea9f025a5e5887f1d6c39080257c.png
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 modified stable/_images/math/56be6f5cfc02befc55ca906d00ce27571fc05e2d.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 modified stable/_images/math/5adc61b02c3e06e38e47acd6acff95b5b12b6a72.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 modified stable/_images/math/75f5d5e1b7c7e27bf646ce2310d037a34bebf8b2.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 modified stable/_images/math/7bfeae1b7ee675473e7ab395c0ea880330e96a91.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 modified stable/_images/math/7e5cefcc72773fad54dbd09a90444798f81da3c8.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 modified stable/_images/math/86ddd8406f22c657b5cf4b31103defcc7ce13169.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 modified stable/_images/math/881588c7e264617a22ab13ee01a8a7124b0ac018.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 modified stable/_images/math/92fe9d704c81c8a6234d13f01c702aac029a4215.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 modified stable/_images/math/b31e914569cd101eaf7d42500e22550fe7ceec9f.png
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 modified stable/_images/math/c5461f9eb416012b3cd303ca8f9ce3b5f579d18c.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 modified stable/_images/math/d58f41145b94a6e17dc8672ac824b056a06cf5ee.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 modified stable/_images/math/ddc5a930d6d9dda09f065bea14fa9e4b457f6d90.png
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.
Binary file modified stable/_images/math/eb279446e130e5472e805db0b5c048316ce00204.png
Binary file modified stable/_images/math/f1ef44a8ac7f20c194e0905450031d192ed45621.png
Diff not rendered.
Binary file modified stable/_images/sphx_glr_plot_cp_regression_001.png
Binary file modified stable/_images/sphx_glr_plot_cp_regression_thumb.png
Binary file modified stable/_images/sphx_glr_plot_image_compression_001.png
Binary file modified stable/_images/sphx_glr_plot_image_compression_thumb.png
Binary file modified stable/_images/sphx_glr_plot_parafac2_001.png
Binary file modified stable/_images/sphx_glr_plot_parafac2_002.png
Binary file modified stable/_images/sphx_glr_plot_tucker_regression_001.png
Binary file modified stable/_images/sphx_glr_plot_tucker_regression_thumb.png
Loading

0 comments on commit 55bdab7

Please sign in to comment.