Tests that the normalization of the output is done correctly.
(
descriptor_func, system, normalization, norm_rel=None, norm_abs=None
)
| 592 | |
| 593 | |
| 594 | def 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 | |
| 620 | def assert_centers(descriptor_func): |
no test coverage detected