<jupyter_start><jupyter_text>Lambas: Parameterisation and Dimensional Reduction of REE Data**Intro** [Start](0.0_StartHere.ipynb) • [Intro](1.1_Introduction.ipynb) **pyrolite** [Geochem](2.1_pyroliteGeochem.ipynb) • [Visualisation](2.2_pyroliteVis.ipynb) • [alphaMELTS](2.3_pyroliteMELTS.ipynb) • [lambdas](2.4_lambdas.ipynb)   **Machine Learning** [Intro](4.0_MachineLearning.ipynb) • [Features](4.1_Features.ipynb) •  [High-D Vis](4.3_HighDVis.ipynb) • [Classification](4.4_Classification.ipynb)   **GitHub** [geochem4nickel](https://github.com/morganjwilliams/geochem4nickel) • [pyrolite](https://github.com/morganjwilliams/pyrolite)  @metasomite  Lambdas: Parameterisation and Dimensional Reduction of REE Data Orthogonal polynomial decomposition can be used for dimensional reduction of smooth function over an independent variable, producing an array of independent values representing the relative weights for each order of component polynomial. In geochemistry, the most applicable use case is for reduction Rare Earth Element (REE) profiles ([O'Neill2016]). The REE are a collection of elements with broadly similar physicochemical properties (the lanthanides), which vary with ionic radii. Given their similar behaviour and typically smooth function of normalised abundance vs. ionic radii, the REE profiles and their shapes can be effectively parameterised and dimensionally reduced (14 elements summarised by 3-4 shape parameters).[O'Neill2016]: https://doi.org/10.1093/petrology/egw047 "<NAME>., 2016. The Smoothness and Shapes of Chondrite-normalized Rare Earth Element Patterns in Basalts. J Petrology 57, 1463–1508. https://doi.org/10.1093/petrology/egw047" This is effectively fitting a sum of weighted independent polynomials to the REE profile, where the weights are then used to represent the curve. This provides a meaningful way to describe REE profile shape. Below is an example of how this can be visualised using the weighted contributions for increasing orders of polynomials.  Here we use some example data from [Ueki2018] and reduce the REE data to lambda values, and plot the resulting dimensionally reduced data.[Ueki2018]: https://doi.org/10.1029/2017GC007401 "<NAME>., <NAME>., <NAME>., 2018. Geochemical Discrimination and Characteristics of Magmatic Tectonic Settings: A Machine-Learning-Based Approach. Geochemistry, Geophysics, Geosystems 19, 1327–1347."<jupyter_code>import matplotlib.pyplot as plt
import pandas as pd
import pyrolite.plot
from pyrolite.geochem.ind import REE

df = pd.read_csv("https://storage.googleapis.com/aegc2019/ueki2018.csv").head(500)<jupyter_output><empty_output><jupyter_text>This dataset includes rocks with a range of REE profiles, but doesn't have data for all of the rare earths. We can calcuate the profile with fewer elmeents, but expect that the resulting values are less precise (especially for any higher order terms), and generally avoid comparing these to lambdas derived from complete REE profiles where possible.<jupyter_code>df.pyrochem.normalize_to("Chondrite_PON").pyroplot.REE(
    index="elements", color="g", alpha=0.1
)<jupyter_output><empty_output><jupyter_text>pyrolite includes a convenient function for calculating lambdas:<jupyter_code>lambdas = df.pyrochem.lambda_lnREE(
    exclude=["Eu", "Pm"], degree=4, norm_to="Chondrite_PON"
)
fig, ax = plt.subplots(1, 3, figsize=(9, 3))
ax_labels = [chr(955) + "$_{}$".format(str(d)) for d in range(4)]
columns = [chr(955) + str(d) for d in range(4)]

for ix, a in enumerate(ax):
    a.scatter(lambdas[columns[ix]], lambdas[columns[ix + 1]], alpha=0.05, c="k")
    a.set_xlabel(ax_labels[ix])
    a.set_ylabel(ax_labels[ix + 1])

plt.tight_layout()
fig.suptitle("lambda Polynomial Coefficients", y=1.05);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10223048327137546, 'fraction_numerical': 0.03664365374402549, 'mean_word_length': 6.094161958568738, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 6, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '155494', 'license': 'MIT', 'n_tokens_mistral': 1286, 'n_tokens_neox': 1151, 'n_words': 385, 'path': 'notebooks/2.4_lambdas.ipynb', 'repo_name': 'morganjwilliams/geochem4nickel', 'size': '3781'}