.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/decomposition/sketchmap.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_decomposition_sketchmap.py: Sketch-map example using pre-selected high-dimensional landmarks ================================================================== This example demonstrates a minimal, sphinx-gallery friendly usage of the `SketchMap` estimator. It loads the provided landmark file, fits the estimator on the landmark set (using per-sample `sample_weights`) and plots the resulting 2D embedding. Notes ----- - The lightweight Python implementation of Sketch-map lives in `skmatter.decomposition._sketchmap`. - The example fits only the landmark set (callers that want a subset should pre-select and pass that array to `fit`). .. GENERATED FROM PYTHON SOURCE LINES 22-29 .. code-block:: Python import numpy as np from matplotlib import pyplot as plt from matplotlib import cm from skmatter.decomposition import SketchMap .. GENERATED FROM PYTHON SOURCE LINES 30-32 Load example landmark data. The file included with the examples contains high-dimensional descriptors and the last column holds a per-sample weight. .. GENERATED FROM PYTHON SOURCE LINES 32-38 .. code-block:: Python data_file = "highd-landmarks" data = np.loadtxt(data_file) X_land = data[:, :-1] weights = data[:, -1] .. GENERATED FROM PYTHON SOURCE LINES 39-41 Fit SketchMap on the landmark set and provide `sample_weights`. We fit on the landmarks only here (no FPS or internal selection). .. GENERATED FROM PYTHON SOURCE LINES 41-46 .. code-block:: Python sm = SketchMap(n_components=2, auto_histogram=True, preopt_steps=50) sm.fit(X_land, sample_weights=weights, mixing_ratio=0.2, n_components=2) T = sm.embedding_ .. GENERATED FROM PYTHON SOURCE LINES 47-48 Plot the resulting embedding colored by the per-sample weight. .. GENERATED FROM PYTHON SOURCE LINES 48-58 .. code-block:: Python cmap = cm.get_cmap("viridis") fig, ax = plt.subplots(figsize=(6, 5)) sc = ax.scatter(T[:, 0], T[:, 1], c=weights, s=40, cmap=cmap, edgecolor="k") ax.set_title("Sketch-map embedding (example)") ax.set_xlabel("Sketchmap 1") ax.set_ylabel("Sketchmap 2") cbar = fig.colorbar(sc, ax=ax) cbar.set_label("landmark weight") fig.tight_layout() plt.show() .. image-sg:: /examples/decomposition/images/sphx_glr_sketchmap_001.png :alt: Sketch-map embedding (example) :srcset: /examples/decomposition/images/sphx_glr_sketchmap_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/docs/checkouts/readthedocs.org/user_builds/scikit-matter/checkouts/284/examples/decomposition/sketchmap.py:48: MatplotlibDeprecationWarning: The get_cmap function was deprecated in Matplotlib 3.7 and will be removed in 3.11. Use ``matplotlib.colormaps[name]`` or ``matplotlib.colormaps.get_cmap()`` or ``pyplot.get_cmap()`` instead. cmap = cm.get_cmap("viridis") .. _sphx_glr_download_examples_decomposition_sketchmap.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: sketchmap.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: sketchmap.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: sketchmap.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_