rascaline icon indicating copy to clipboard operation
rascaline copied to clipboard

FPS sample selection in the tutorial

Open SanggyuChong opened this issue 2 years ago • 3 comments

Hello,

I'd like to suggest the addition of a function, to the tutorial, that performs farthest point selection for the atomic environments as one prepares for the construction of sparse kernel models. @PicoCentauri have kindly provided me with the code below, which, again, we think could be a nice addition to the tutorial:

def fps_sample_selection(descriptor, n_to_select):

    blocks = []
    for _, block in descriptor:
        # create a separate FPS selector for each block
        fps = FPS(n_to_select=n_to_select)
        mask = fps.fit(block.values.T).get_support()
        selected_samples = block.samples[mask]
        # The only important data here is the properties, so we create empty
        # sets of samples and components.
        blocks.append(
            TensorBlock(
                values=np.empty((1, len(selected_samples))).T,
                samples=selected_samples,
                components=[],
                properties=Labels.single(),
            )
        )

    return TensorMap(descriptor.keys, blocks)

Thank you!

  • Raymond

SanggyuChong avatar Feb 10 '23 15:02 SanggyuChong