<jupyter_start><jupyter_text>Example for the usage of the `skcosmo.metrics.global_reconstruction_error` as global feature reconstruction error (GFRE) and `skcosmo.metrics.global_reconstruction_distortion` global feature reconstruction distortion (GFRD)<jupyter_code>import numpy as np
import matplotlib.pyplot as plt

from skcosmo.datasets import load_degenerate_CH4_manifold
from skcosmo.metrics import (
    global_reconstruction_error,
    global_reconstruction_distortion,
)

# load features
degenerate_manifold = load_degenerate_CH4_manifold()
soap_features = degenerate_manifold.data.SOAP_power_spectrum
bispectrum_features = degenerate_manifold.data.SOAP_bispectrum
gfre_matrix = np.zeros((2, 2))
print("Computing GFRE...")
gfre_matrix[0, 0] = global_reconstruction_error(soap_features, soap_features)
gfre_matrix[0, 1] = global_reconstruction_error(soap_features, bispectrum_features)
gfre_matrix[1, 0] = global_reconstruction_error(bispectrum_features, soap_features)
gfre_matrix[1, 1] = global_reconstruction_error(
    bispectrum_features, bispectrum_features
)
print("Computing GFRE finished.")
gfrd_matrix = np.zeros((2, 2))
print("Computing GFRD...")
gfrd_matrix[0, 0] = global_reconstruction_distortion(soap_features, soap_features)
gfrd_matrix[0, 1] = global_reconstruction_distortion(soap_features, bispectrum_features)
gfrd_matrix[1, 0] = global_reconstruction_distortion(bispectrum_features, soap_features)
gfrd_matrix[1, 1] = global_reconstruction_distortion(
    bispectrum_features, bispectrum_features
)
print("Computing GFRD finished.")<jupyter_output><empty_output><jupyter_text>It can be seen that the reconstruction of the 4-body features using 3-body features has a nonnegligible error showing that 4-body features adds additional information in a linear regression sense for this dataset. Furthermore, it can be seen that 3-body features can be reconstructed using 4-body with a negligible error but high distortion.<jupyter_code>fig, axes = plt.subplots(1, 2, figsize=(16, 4))
pcm1 = axes[0].imshow(gfre_matrix, vmin=0, vmax=0.25)
pcm2 = axes[1].imshow(gfrd_matrix, vmin=0, vmax=0.25)
axes[0].set_ylabel("F")
axes[0].set_xlabel("F'")
axes[1].set_xlabel("F'")
axes[0].set_title("GFRE(F, F')")
axes[1].set_title("GFRD(F, F')")
axes[0].set_xticks([0, 1])
axes[0].set_xticklabels(["3-body", "4-body"])
axes[1].set_xticks([0, 1])
axes[1].set_xticklabels(["3-body", "4-body"])
axes[0].set_yticks([0, 1])
axes[0].set_yticklabels(["3-body", "4-body"])
axes[1].set_yticks([0, 1])
axes[1].set_yticklabels(["", ""])

fig.subplots_adjust(right=0.8)
cbar_ax = fig.add_axes([0.85, 0.15, 0.05, 0.7])
fig.colorbar(pcm2, cax=cbar_ax)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.126163007071083, 'fraction_numerical': 0.03163379233345739, 'mean_word_length': 8.174061433447099, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '66842', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1030, 'n_tokens_neox': 957, 'n_words': 190, 'path': 'examples/metrics/plot_gfrm.ipynb', 'repo_name': 'andreanelli/scikit-cosmo', 'size': '2687'}