.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/logging.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_logging.py: Logging Example --------------- In this example we demonstrate how to enable logging in zen mapper. The bulk of the example is taken from :doc:`/examples/basic`, see that for discussion about the mapper bit. .. GENERATED FROM PYTHON SOURCE LINES 10-18 Enable logging ============== We use the `builtin python logging library `_ to log internal activity. The simplest way to enable logging is to use `basicConfig`. A complete breakdown of the logging library is beyond the scope of this example however the official logging documentation is rather complete. Zen mapper logs to the `zen_mapper` logger. .. GENERATED FROM PYTHON SOURCE LINES 18-23 .. code-block:: Python import logging logging.basicConfig(level=logging.INFO) .. GENERATED FROM PYTHON SOURCE LINES 24-26 Generating data =============== .. GENERATED FROM PYTHON SOURCE LINES 26-34 .. code-block:: Python import numpy as np import matplotlib.pyplot as plt theta = np.linspace(0, 2 * np.pi, 50) data = np.c_[np.cos(theta), np.sin(theta)] plt.scatter(data[:, 0], data[:, 1]) plt.show() .. image-sg:: /examples/images/sphx_glr_logging_001.png :alt: logging :srcset: /examples/images/sphx_glr_logging_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 35-37 Running mapper =============== .. GENERATED FROM PYTHON SOURCE LINES 37-64 .. code-block:: Python import networkx as nx from zen_mapper.adapters import to_networkx from sklearn.cluster import AgglomerativeClustering from zen_mapper.adapters import sk_learn from zen_mapper import mapper, Width_Balanced_Cover projection = data[:, 0] cover_scheme = Width_Balanced_Cover(n_elements=3, percent_overlap=0.4) cover = cover_scheme(projection) sk = AgglomerativeClustering( linkage="single", n_clusters=None, distance_threshold=0.2, ) clusterer = sk_learn(sk) result = mapper( data=data, projection=projection, cover_scheme=cover_scheme, clusterer=clusterer, dim=1, ) .. rst-class:: sphx-glr-script-out .. code-block:: none INFO:zen_mapper:Computing the width balanced cover INFO:zen_mapper:Computing the width balanced cover INFO:zen_mapper:Clustering cover element 0 INFO:zen_mapper:Found 1 clusters INFO:zen_mapper:Clustering cover element 1 INFO:zen_mapper:Found 2 clusters INFO:zen_mapper:Clustering cover element 2 INFO:zen_mapper:Found 1 clusters INFO:zen_mapper:Computing the nerve INFO:zen_mapper:Found 4 0-complexes INFO:zen_mapper:Searching for 1-complexes INFO:zen_mapper:Found 4 1-complexes .. GENERATED FROM PYTHON SOURCE LINES 65-67 Visualizing the mapper graph ============================ .. GENERATED FROM PYTHON SOURCE LINES 67-70 .. code-block:: Python graph = to_networkx(result.nerve) nx.draw(graph) .. image-sg:: /examples/images/sphx_glr_logging_002.png :alt: logging :srcset: /examples/images/sphx_glr_logging_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.793 seconds) .. _sphx_glr_download_examples_logging.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: logging.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: logging.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: logging.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_