.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/02_matrix_views/plot_05_seriation.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 or to run this example in your browser via Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_02_matrix_views_plot_05_seriation.py: Seriation of the incidence matrix ================================= The incidence matrix of the wire harness manufacturing space (31 resources, 70 activities) is unreadable in its original order. The iterative barycentric seriation of HAT-VIS, correspondence analysis and hierarchical clustering with optimal leaf ordering reorder rows and columns so that co-occurring resources and activities form blocks. The Moore stress (lower is better) and the bond energy (higher is better) quantify the improvement. .. GENERATED FROM PYTHON SOURCE LINES 14-31 .. code-block:: Python import matplotlib.pyplot as plt import pandas as pd import hatvis as hv from hatvis.plotting import plot_incidence H = hv.datasets.load_wire_harness() # [snippet:orders] quality = {} orders = {"original": (H.nodes, H.edges)} for method in ("barycentric", "correspondence", "hierarchical"): orders[method] = hv.seriate(H, method) for name, (rows, cols) in orders.items(): quality[name] = hv.seriation.seriation_quality(H, rows, cols) print(pd.DataFrame(quality).T) # [/snippet:orders] .. rst-class:: sphx-glr-script-out .. code-block:: none moore stress bond energy original 644.0 162.0 barycentric 569.0 201.0 correspondence 581.0 195.0 hierarchical 398.0 289.0 .. GENERATED FROM PYTHON SOURCE LINES 32-36 .. code-block:: Python fig, axes = plt.subplots(1, 4, figsize=(15, 7.5)) for ax, (name, oc) in zip(axes, orders.items(), strict=False): plot_incidence(H, order=oc, ax=ax, transpose=True, labels=False, title=name) plt.tight_layout() .. image-sg:: /auto_examples/02_matrix_views/images/sphx_glr_plot_05_seriation_001.png :alt: original, barycentric, correspondence, hierarchical :srcset: /auto_examples/02_matrix_views/images/sphx_glr_plot_05_seriation_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.731 seconds) .. _sphx_glr_download_auto_examples_02_matrix_views_plot_05_seriation.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/ComplexSystemsIntelligence/hatvis/main?urlpath=lab/tree/notebooks/auto_examples/02_matrix_views/plot_05_seriation.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_05_seriation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_05_seriation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_05_seriation.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_