-
Notifications
You must be signed in to change notification settings - Fork 0
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
Circle CI
committed
Dec 25, 2024
1 parent
e23cff5
commit b4fbe0e
Showing
56 changed files
with
235 additions
and
273 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
}, | ||
"outputs": [], | ||
"source": [ | ||
"# Author: Hugues Van Assel <[email protected]>\n#\n# License: BSD 3-Clause License\n\nimport matplotlib.pyplot as plt\nfrom sklearn.datasets import load_digits\n\nfrom torchdr.spectral import PCA\nfrom torchdr import AffinityMatcher, ScalarProductAffinity" | ||
"# Author: Hugues Van Assel <[email protected]>\n#\n# License: BSD 3-Clause License\n\nimport matplotlib.pyplot as plt\nfrom sklearn.datasets import load_digits\n\nfrom torchdr import AffinityMatcher, ScalarProductAffinity\nfrom torchdr.spectral import PCA" | ||
] | ||
}, | ||
{ | ||
|
Binary file modified
BIN
-54 Bytes
(100%)
dev/_downloads/07fcc19ba03226cd3d83d4e40ec44385/auto_examples_python.zip
Binary file not shown.
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 |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
}, | ||
"outputs": [], | ||
"source": [ | ||
"# Author: Hugues Van Assel <[email protected]>\n#\n# License: BSD 3-Clause License\n\nimport torch\nimport matplotlib.pyplot as plt\nfrom matplotlib import cm\n\nfrom torchdr import (\n NormalizedGaussianAffinity,\n EntropicAffinity,\n)" | ||
"# Author: Hugues Van Assel <[email protected]>\n#\n# License: BSD 3-Clause License\n\nimport matplotlib.pyplot as plt\nimport torch\nfrom matplotlib import cm\n\nfrom torchdr import EntropicAffinity, NormalizedGaussianAffinity" | ||
] | ||
}, | ||
{ | ||
|
@@ -65,7 +65,7 @@ | |
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Entropic affinity (adaptive bandwidth)\n\nTo remedy this issue, we can use an **entropic affinity**. The entropic affinity\nemploys an **adaptive bandwidth** that depends on the local density of points.\nBy controling the entropy of each row of the affinity matrix, it ensures that\n**each point has the same number of effective neighbors** (given by\nthe ``perplexity`` parameter) regardless of the local density around it.\n\nIn ``TorchDR``, this object is available here :\n:class:`torchdr.EntropicAffinity`.\n\n" | ||
"## Entropic affinity (adaptive bandwidth)\n\nTo remedy this issue, we can use an **entropic affinity**. The entropic affinity\nemploys an **adaptive bandwidth** that depends on the local density of points.\nBy controlling the entropy of each row of the affinity matrix, it ensures that\n**each point has the same number of effective neighbors** (given by\nthe ``perplexity`` parameter) regardless of the local density around it.\n\nIn ``TorchDR``, this object is available here :\n:class:`torchdr.EntropicAffinity`.\n\n" | ||
] | ||
}, | ||
{ | ||
|
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 modified
BIN
-27 Bytes
(100%)
dev/_downloads/26989111dccd2d4534f75f59dd77f104/demo_ea_adaptivity.zip
Binary file not shown.
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 |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
}, | ||
"outputs": [], | ||
"source": [ | ||
"# Author: Titouan Vayer <[email protected]>\n# Hugues Van Assel <[email protected]>\n#\n# License: BSD 3-Clause License" | ||
"# Author: Titouan Vayer <[email protected]>\n# Hugues Van Assel <[email protected]>\n#\n# License: BSD 3-Clause License\n\nimport urllib.request" | ||
] | ||
}, | ||
{ | ||
|
@@ -26,7 +26,7 @@ | |
}, | ||
"outputs": [], | ||
"source": [ | ||
"import matplotlib.pyplot as plt\n\nfrom torchdr import (\n AffinityMatcher,\n SNE,\n UMAP,\n TSNE,\n EntropicAffinity,\n NormalizedGaussianAffinity,\n)\nimport numpy as np\nimport urllib.request" | ||
"import matplotlib.pyplot as plt\nimport numpy as np\n\nfrom torchdr import (\n SNE,\n TSNE,\n UMAP,\n AffinityMatcher,\n EntropicAffinity,\n NormalizedGaussianAffinity,\n)" | ||
] | ||
}, | ||
{ | ||
|
@@ -62,7 +62,7 @@ | |
}, | ||
"outputs": [], | ||
"source": [ | ||
"params = {\n \"optimizer\": \"Adam\",\n \"optimizer_kwargs\": None,\n \"max_iter\": 100,\n \"lr\": 1e0,\n}\n\nsne = SNE(early_exaggeration=1, **params)\n\numap = UMAP(early_exaggeration=1, **params)\n\ntsne = TSNE(early_exaggeration=1, **params)\n\nall_methods = {\n \"TSNE\": tsne,\n \"SNE\": sne,\n \"UMAP\": umap,\n}\n\nfor method_name, method in all_methods.items():\n print(\"--- Computing {} ---\".format(method_name))\n method.fit(X)" | ||
"params = {\n \"optimizer\": \"Adam\",\n \"optimizer_kwargs\": None,\n \"max_iter\": 100,\n \"lr\": 1e0,\n}\n\nsne = SNE(early_exaggeration=1, **params)\n\numap = UMAP(early_exaggeration=1, **params)\n\ntsne = TSNE(early_exaggeration=1, **params)\n\nall_methods = {\n \"TSNE\": tsne,\n \"SNE\": sne,\n \"UMAP\": umap,\n}\n\nfor method_name, method in all_methods.items():\n print(f\"--- Computing {method_name} ---\")\n method.fit(X)" | ||
] | ||
}, | ||
{ | ||
|
@@ -80,7 +80,7 @@ | |
}, | ||
"outputs": [], | ||
"source": [ | ||
"fig = plt.figure(figsize=(12, 4))\n\nfor i, (method_name, method) in enumerate(all_methods.items()):\n ax = fig.add_subplot(1, 3, i + 1)\n emb = method.embedding_.detach().numpy() # get the embedding\n ax.scatter(emb[:, 0], emb[:, 1], c=Y, s=10)\n ax.set_title(\"{0}\".format(method_name), fontsize=24)\n ax.set_xticks([])\n ax.set_yticks([])\nplt.tight_layout()" | ||
"fig = plt.figure(figsize=(12, 4))\n\nfor i, (method_name, method) in enumerate(all_methods.items()):\n ax = fig.add_subplot(1, 3, i + 1)\n emb = method.embedding_.detach().numpy() # get the embedding\n ax.scatter(emb[:, 0], emb[:, 1], c=Y, s=10)\n ax.set_title(f\"{method_name}\", fontsize=24)\n ax.set_xticks([])\n ax.set_yticks([])\nplt.tight_layout()" | ||
] | ||
}, | ||
{ | ||
|
@@ -98,7 +98,7 @@ | |
}, | ||
"outputs": [], | ||
"source": [ | ||
"sne_affinity_matcher = AffinityMatcher(\n n_components=2,\n # SNE matches an EntropicAffinity\n affinity_in=EntropicAffinity(sparsity=False),\n # with a Gaussian kernel normalized by row\n affinity_out=NormalizedGaussianAffinity(normalization_dim=1),\n loss_fn=\"cross_entropy_loss\", # and the cross_entropy loss\n **params,\n)\nsne_affinity_matcher.fit(X)\n\nfig = plt.figure(figsize=(8, 4))\ntwo_sne_dict = {\"SNE\": sne, \"SNE (with affinity matcher)\": sne_affinity_matcher}\nfor i, (method_name, method) in enumerate(two_sne_dict.items()):\n ax = fig.add_subplot(1, 2, i + 1)\n emb = method.embedding_.detach().numpy() # get the embedding\n ax.scatter(emb[:, 0], emb[:, 1], c=Y, s=10)\n ax.set_title(\"{0}\".format(method_name), fontsize=15)\n ax.set_xticks([])\n ax.set_yticks([])\nplt.tight_layout()" | ||
"sne_affinity_matcher = AffinityMatcher(\n n_components=2,\n # SNE matches an EntropicAffinity\n affinity_in=EntropicAffinity(sparsity=False),\n # with a Gaussian kernel normalized by row\n affinity_out=NormalizedGaussianAffinity(normalization_dim=1),\n loss_fn=\"cross_entropy_loss\", # and the cross_entropy loss\n **params,\n)\nsne_affinity_matcher.fit(X)\n\nfig = plt.figure(figsize=(8, 4))\ntwo_sne_dict = {\"SNE\": sne, \"SNE (with affinity matcher)\": sne_affinity_matcher}\nfor i, (method_name, method) in enumerate(two_sne_dict.items()):\n ax = fig.add_subplot(1, 2, i + 1)\n emb = method.embedding_.detach().numpy() # get the embedding\n ax.scatter(emb[:, 0], emb[:, 1], c=Y, s=10)\n ax.set_title(f\"{method_name}\", fontsize=15)\n ax.set_xticks([])\n ax.set_yticks([])\nplt.tight_layout()" | ||
] | ||
}, | ||
{ | ||
|
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
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 modified
BIN
-55 Bytes
(100%)
dev/_downloads/6f1e7a639e0699d6164445b55e6c116d/auto_examples_jupyter.zip
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
dev/_downloads/9c98a10e6c0743947672bcab8d552167/demo_pca_via_affinity_matcher.zip
Binary file not shown.
Binary file modified
BIN
-32 Bytes
(100%)
dev/_downloads/a326ed5e0cfd78a82e54fd5203079d4a/demo_tsne_swiss_roll.zip
Binary file not shown.
Binary file modified
BIN
-50 Bytes
(100%)
dev/_downloads/ccd90bc6ee7cbcb51bd8b71882fb5168/demo_ne_methods_affinity_matcher.zip
Binary file not shown.
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
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
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 |
---|---|---|
|
@@ -82,26 +82,25 @@ | |
<div itemprop="articleBody"> | ||
|
||
<h1>Source code for torchdr.affinity.base</h1><div class="highlight"><pre> | ||
<span></span><span class="c1"># -*- coding: utf-8 -*-</span> | ||
<span class="sd">"""Base classes for affinity matrices."""</span> | ||
<span></span><span class="sd">"""Base classes for affinity matrices."""</span> | ||
|
||
<span class="c1"># Author: Hugues Van Assel <[email protected]></span> | ||
<span class="c1">#</span> | ||
<span class="c1"># License: BSD 3-Clause License</span> | ||
|
||
<span class="kn">from</span> <span class="nn">abc</span> <span class="kn">import</span> <span class="n">ABC</span> | ||
|
||
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> | ||
<span class="kn">import</span> <span class="nn">torch</span> | ||
|
||
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> | ||
<span class="kn">from</span> <span class="nn">torchdr.utils</span> <span class="kn">import</span> <span class="p">(</span> | ||
<span class="n">LazyTensorType</span><span class="p">,</span> | ||
<span class="n">handle_keops</span><span class="p">,</span> | ||
<span class="n">pairwise_distances</span><span class="p">,</span> | ||
<span class="n">pykeops</span><span class="p">,</span> | ||
<span class="n">symmetric_pairwise_distances</span><span class="p">,</span> | ||
<span class="n">symmetric_pairwise_distances_indices</span><span class="p">,</span> | ||
<span class="n">pairwise_distances</span><span class="p">,</span> | ||
<span class="n">to_torch</span><span class="p">,</span> | ||
<span class="n">LazyTensorType</span><span class="p">,</span> | ||
<span class="n">pykeops</span><span class="p">,</span> | ||
<span class="n">handle_keops</span><span class="p">,</span> | ||
<span class="p">)</span> | ||
|
||
|
||
|
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 |
---|---|---|
|
@@ -82,36 +82,36 @@ | |
<div itemprop="articleBody"> | ||
|
||
<h1>Source code for torchdr.affinity.entropic</h1><div class="highlight"><pre> | ||
<span></span><span class="c1"># -*- coding: utf-8 -*-</span> | ||
<span class="sd">"""Affinity matrices with entropic constraints."""</span> | ||
<span></span><span class="sd">"""Affinity matrices with entropic constraints."""</span> | ||
|
||
<span class="c1"># Author: Hugues Van Assel <[email protected]></span> | ||
<span class="c1"># Titouan Vayer <[email protected]></span> | ||
<span class="c1"># Rémi Flamary <[email protected]></span> | ||
<span class="c1">#</span> | ||
<span class="c1"># License: BSD 3-Clause License</span> | ||
|
||
<span class="kn">import</span> <span class="nn">torch</span> | ||
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> | ||
<span class="kn">from</span> <span class="nn">tqdm</span> <span class="kn">import</span> <span class="n">tqdm</span> | ||
<span class="kn">import</span> <span class="nn">warnings</span> | ||
<span class="kn">import</span> <span class="nn">contextlib</span> | ||
<span class="kn">import</span> <span class="nn">math</span> | ||
<span class="kn">import</span> <span class="nn">warnings</span> | ||
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Tuple</span> | ||
|
||
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span> | ||
<span class="kn">import</span> <span class="nn">torch</span> | ||
<span class="kn">from</span> <span class="nn">tqdm</span> <span class="kn">import</span> <span class="n">tqdm</span> | ||
|
||
<span class="kn">from</span> <span class="nn">torchdr.affinity.base</span> <span class="kn">import</span> <span class="n">LogAffinity</span><span class="p">,</span> <span class="n">SparseLogAffinity</span> | ||
<span class="kn">from</span> <span class="nn">torchdr.utils</span> <span class="kn">import</span> <span class="p">(</span> | ||
<span class="n">OPTIMIZERS</span><span class="p">,</span> | ||
<span class="n">batch_transpose</span><span class="p">,</span> | ||
<span class="n">check_NaNs</span><span class="p">,</span> | ||
<span class="n">entropy</span><span class="p">,</span> | ||
<span class="n">false_position</span><span class="p">,</span> | ||
<span class="n">wrap_vectors</span><span class="p">,</span> | ||
<span class="n">sum_matrix_vector</span><span class="p">,</span> | ||
<span class="n">kmin</span><span class="p">,</span> | ||
<span class="n">kmax</span><span class="p">,</span> | ||
<span class="n">check_NaNs</span><span class="p">,</span> | ||
<span class="n">kmin</span><span class="p">,</span> | ||
<span class="n">logsumexp_red</span><span class="p">,</span> | ||
<span class="n">batch_transpose</span><span class="p">,</span> | ||
<span class="n">OPTIMIZERS</span><span class="p">,</span> | ||
<span class="n">sum_matrix_vector</span><span class="p">,</span> | ||
<span class="n">wrap_vectors</span><span class="p">,</span> | ||
<span class="p">)</span> | ||
<span class="kn">from</span> <span class="nn">torchdr.affinity.base</span> <span class="kn">import</span> <span class="n">LogAffinity</span><span class="p">,</span> <span class="n">SparseLogAffinity</span> | ||
|
||
|
||
<span class="nd">@wrap_vectors</span> | ||
|
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 |
---|---|---|
|
@@ -82,25 +82,19 @@ | |
<div itemprop="articleBody"> | ||
|
||
<h1>Source code for torchdr.affinity.knn_normalized</h1><div class="highlight"><pre> | ||
<span></span><span class="c1"># -*- coding: utf-8 -*-</span> | ||
<span class="sd">"""Affinity matrices with normalizations using nearest neighbor distances."""</span> | ||
<span></span><span class="sd">"""Affinity matrices with normalizations using nearest neighbor distances."""</span> | ||
|
||
<span class="c1"># Author: Hugues Van Assel <[email protected]></span> | ||
<span class="c1"># Cédric Vincent-Cuaz <[email protected]></span> | ||
<span class="c1">#</span> | ||
<span class="c1"># License: BSD 3-Clause License</span> | ||
|
||
<span class="kn">import</span> <span class="nn">torch</span> | ||
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Tuple</span> | ||
|
||
<span class="kn">import</span> <span class="nn">torch</span> | ||
|
||
<span class="kn">from</span> <span class="nn">torchdr.affinity.base</span> <span class="kn">import</span> <span class="n">Affinity</span><span class="p">,</span> <span class="n">LogAffinity</span> | ||
<span class="kn">from</span> <span class="nn">torchdr.utils</span> <span class="kn">import</span> <span class="p">(</span> | ||
<span class="n">kmin</span><span class="p">,</span> | ||
<span class="n">wrap_vectors</span><span class="p">,</span> | ||
<span class="n">batch_transpose</span><span class="p">,</span> | ||
<span class="n">logsumexp_red</span><span class="p">,</span> | ||
<span class="n">sum_red</span><span class="p">,</span> | ||
<span class="p">)</span> | ||
<span class="kn">from</span> <span class="nn">torchdr.utils</span> <span class="kn">import</span> <span class="n">batch_transpose</span><span class="p">,</span> <span class="n">kmin</span><span class="p">,</span> <span class="n">logsumexp_red</span><span class="p">,</span> <span class="n">sum_red</span><span class="p">,</span> <span class="n">wrap_vectors</span> | ||
|
||
|
||
<span class="nd">@wrap_vectors</span> | ||
|
Oops, something went wrong.