Skip to content

Commit

Permalink
minor fixes and cleanups in lode examples
Browse files Browse the repository at this point in the history
  • Loading branch information
PicoCentauri committed Oct 27, 2023
1 parent 51b048c commit 20e90e0
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions examples/lode_linear/lode_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@

# %%
#
# Convert target properties to equistore format
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Convert target properties to metatensor format
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# If we want to train models using the
# `equisolve <https://github.com/lab-cosmo/equisolve>`_ package, we need to
Expand Down Expand Up @@ -197,8 +197,8 @@
#
# .. code:: python
#
# descriptor_co = AtomicComposition(per_structure=True).compute(**compute_args) co =
# descriptor_co.keys_to_properties(["species_center"])
# descriptor_co = AtomicComposition(per_structure=True).compute(**compute_args)
# co = descriptor_co.keys_to_properties(["species_center"])
#
# Stack all the features together for linear model
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -267,24 +267,27 @@

# %%
#
# For doing the split we define two ``Labels`` instances
# For doing the split we define two ``Labels`` instances and combine them in a
# :py:class:`List`.

samples_train = metatensor.Labels(["structure"], np.reshape(idx_train, (-1, 1)))
samples_test = metatensor.Labels(["structure"], np.reshape(idx_test, (-1, 1)))
grouped_labels = [samples_train, samples_test]


# %%
#
# That we use as input to the :py:func:`equistore.slice()` function
# That we use as input to the :py:func:`metatensor.split()` function

X_sr_train = metatensor.slice(X_sr, axis="samples", labels=samples_train)
X_sr_test = metatensor.slice(X_sr, axis="samples", labels=samples_test)
X_sr_train, X_sr_test = metatensor.split(
X_sr, axis="samples", grouped_labels=grouped_labels
)

X_lr_train = metatensor.slice(X_lr, axis="samples", labels=samples_train)
X_lr_test = metatensor.slice(X_lr, axis="samples", labels=samples_test)
X_lr_train, X_lr_test = metatensor.split(
X_lr, axis="samples", grouped_labels=grouped_labels
)

y_train = metatensor.slice(y, axis="samples", labels=samples_train)
y_test = metatensor.slice(y, axis="samples", labels=samples_test)
y_train, y_test = metatensor.split(y, axis="samples", grouped_labels=grouped_labels)


# %%
Expand Down

0 comments on commit 20e90e0

Please sign in to comment.