Skip to content

Commit 9140624

Browse files
Github action: auto-update.
1 parent f6c2b89 commit 9140624

82 files changed

Lines changed: 292 additions & 306 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Binary file not shown.
0 Bytes
Binary file not shown.

dev/_downloads/32f8d624f9d1f7b561ad62798d8861ca/plot_parafac2.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21

32
"""
43
Demonstration of PARAFAC2
0 Bytes
Binary file not shown.

dev/_downloads/42966e24b5f81902fc31165ec0d52e6c/plot_cp_regression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
ax.set_axis_off()
6868

6969
if i == 0:
70-
ax.set_title("Learned\nrank = {}".format(rank))
70+
ax.set_title(f"Learned\nrank = {rank}")
7171

7272
plt.suptitle("CP tensor regression")
7373
plt.show()
-48 Bytes
Binary file not shown.

dev/_downloads/4646f2ed882fdbd7317db8bc1eb3916e/plot_cp_regression.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"outputs": [],
1717
"source": [
18-
"import matplotlib.pyplot as plt\nfrom tensorly.base import tensor_to_vec, partial_tensor_to_vec\nfrom tensorly.datasets.synthetic import gen_image\nfrom tensorly.regression.cp_regression import CPRegressor\nimport tensorly as tl\n\n# Parameter of the experiment\nimage_height = 25\nimage_width = 25\n# shape of the images\npatterns = [\"rectangle\", \"swiss\", \"circle\"]\n# ranks to test\nranks = [1, 2, 3, 4, 5]\n\n# Generate random samples\nrng = tl.check_random_state(1)\nX = tl.tensor(rng.normal(size=(1000, image_height, image_width), loc=0, scale=1))\n\n\n# Parameters of the plot, deduced from the data\nn_rows = len(patterns)\nn_columns = len(ranks) + 1\n# Plot the three images\nfig = plt.figure()\n\nfor i, pattern in enumerate(patterns):\n\n # Generate the original image\n weight_img = gen_image(\n region=pattern, image_height=image_height, image_width=image_width\n )\n weight_img = tl.tensor(weight_img)\n\n # Generate the labels\n y = tl.dot(partial_tensor_to_vec(X, skip_begin=1), tensor_to_vec(weight_img))\n\n # Plot the original weights\n ax = fig.add_subplot(n_rows, n_columns, i * n_columns + 1)\n ax.imshow(tl.to_numpy(weight_img), cmap=plt.cm.OrRd, interpolation=\"nearest\")\n ax.set_axis_off()\n if i == 0:\n ax.set_title(\"Original\\nweights\")\n\n for j, rank in enumerate(ranks):\n\n # Create a tensor Regressor estimator\n estimator = CPRegressor(\n weight_rank=rank, tol=10e-7, n_iter_max=100, reg_W=1, verbose=0\n )\n\n # Fit the estimator to the data\n estimator.fit(X, y)\n\n ax = fig.add_subplot(n_rows, n_columns, i * n_columns + j + 2)\n ax.imshow(\n tl.to_numpy(estimator.weight_tensor_),\n cmap=plt.cm.OrRd,\n interpolation=\"nearest\",\n )\n ax.set_axis_off()\n\n if i == 0:\n ax.set_title(\"Learned\\nrank = {}\".format(rank))\n\nplt.suptitle(\"CP tensor regression\")\nplt.show()"
18+
"import matplotlib.pyplot as plt\nfrom tensorly.base import tensor_to_vec, partial_tensor_to_vec\nfrom tensorly.datasets.synthetic import gen_image\nfrom tensorly.regression.cp_regression import CPRegressor\nimport tensorly as tl\n\n# Parameter of the experiment\nimage_height = 25\nimage_width = 25\n# shape of the images\npatterns = [\"rectangle\", \"swiss\", \"circle\"]\n# ranks to test\nranks = [1, 2, 3, 4, 5]\n\n# Generate random samples\nrng = tl.check_random_state(1)\nX = tl.tensor(rng.normal(size=(1000, image_height, image_width), loc=0, scale=1))\n\n\n# Parameters of the plot, deduced from the data\nn_rows = len(patterns)\nn_columns = len(ranks) + 1\n# Plot the three images\nfig = plt.figure()\n\nfor i, pattern in enumerate(patterns):\n\n # Generate the original image\n weight_img = gen_image(\n region=pattern, image_height=image_height, image_width=image_width\n )\n weight_img = tl.tensor(weight_img)\n\n # Generate the labels\n y = tl.dot(partial_tensor_to_vec(X, skip_begin=1), tensor_to_vec(weight_img))\n\n # Plot the original weights\n ax = fig.add_subplot(n_rows, n_columns, i * n_columns + 1)\n ax.imshow(tl.to_numpy(weight_img), cmap=plt.cm.OrRd, interpolation=\"nearest\")\n ax.set_axis_off()\n if i == 0:\n ax.set_title(\"Original\\nweights\")\n\n for j, rank in enumerate(ranks):\n\n # Create a tensor Regressor estimator\n estimator = CPRegressor(\n weight_rank=rank, tol=10e-7, n_iter_max=100, reg_W=1, verbose=0\n )\n\n # Fit the estimator to the data\n estimator.fit(X, y)\n\n ax = fig.add_subplot(n_rows, n_columns, i * n_columns + j + 2)\n ax.imshow(\n tl.to_numpy(estimator.weight_tensor_),\n cmap=plt.cm.OrRd,\n interpolation=\"nearest\",\n )\n ax.set_axis_off()\n\n if i == 0:\n ax.set_title(f\"Learned\\nrank = {rank}\")\n\nplt.suptitle(\"CP tensor regression\")\nplt.show()"
1919
]
2020
}
2121
],

dev/_downloads/5a995fc29a1b64970094cc40854ffae2/plot_nn_tucker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@
109109
# To compare the various methods, first we may look at each algorithm
110110
# processing time:
111111

112-
print("time for tensorly nntucker:" + " " + str("{:.2f}".format(time_mu)))
113-
print("time for HALS with fista:" + " " + str("{:.2f}".format(time_fista)))
114-
print("time for HALS with as:" + " " + str("{:.2f}".format(time_as)))
112+
print("time for tensorly nntucker:" + " " + str(f"{time_mu:.2f}"))
113+
print("time for HALS with fista:" + " " + str(f"{time_fista:.2f}"))
114+
print("time for HALS with as:" + " " + str(f"{time_as:.2f}"))
115115

116116
##############################################################################
117117
# All algorithms should run with about the same number of iterations on our
Binary file not shown.

dev/_downloads/7c4762fd973c92c13874f6405624a983/plot_tensor.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
},
3434
"outputs": [],
3535
"source": [
36-
"tensor = tl.tensor(np.arange(24).reshape((3, 4, 2)))\nprint(\"* original tensor:\\n{}\".format(tensor))"
36+
"tensor = tl.tensor(np.arange(24).reshape((3, 4, 2)))\nprint(f\"* original tensor:\\n{tensor}\")"
3737
]
3838
},
3939
{
@@ -51,7 +51,7 @@
5151
},
5252
"outputs": [],
5353
"source": [
54-
"for mode in range(tensor.ndim):\n print(\"* mode-{} unfolding:\\n{}\".format(mode, tl.unfold(tensor, mode)))"
54+
"for mode in range(tensor.ndim):\n print(f\"* mode-{mode} unfolding:\\n{tl.unfold(tensor, mode)}\")"
5555
]
5656
},
5757
{

0 commit comments

Comments
 (0)