MCPcopy Create free account
hub / github.com/SINGROUP/dscribe / assert_normalization

Function assert_normalization

tests/conftest.py:594–617  ·  view source on GitHub ↗

Tests that the normalization of the output is done correctly.

(
    descriptor_func, system, normalization, norm_rel=None, norm_abs=None
)

Source from the content-addressed store, hash-verified

592
593
594def assert_normalization(
595 descriptor_func, system, normalization, norm_rel=None, norm_abs=None
596):
597 """Tests that the normalization of the output is done correctly."""
598 desc_raw = descriptor_func(normalization="none", periodic=True)([system])
599 features_raw = desc_raw.create(system)
600 desc_normalized = descriptor_func(normalization=normalization, periodic=True)(
601 [system]
602 )
603 features_normalized = desc_normalized.create(system)
604 is_local = isinstance(desc_normalized, DescriptorLocal)
605 if is_local:
606 features_raw = features_raw[0]
607 features_normalized = features_normalized[0]
608
609 norm = np.linalg.norm(features_normalized)
610 if norm_rel is not None and norm_abs is not None:
611 raise ValueError("Provide only relative or absolute norm")
612 if norm_rel is not None:
613 norm_raw = np.linalg.norm(features_raw)
614 assert norm_raw != 0
615 assert norm / norm_raw == pytest.approx(norm_rel, 0, 1e-8)
616 if norm_abs is not None:
617 assert norm == pytest.approx(norm_abs, 0, 1e-8)
618
619
620def assert_centers(descriptor_func):

Callers 2

test_normalizationFunction · 0.90
test_normalizationFunction · 0.90

Calls 1

createMethod · 0.45

Tested by

no test coverage detected