Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor fixes and cleanups in lode examples #30

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading