def score(self, features: torch.Tensor, feature_shapes: tuple) -> torch.Tensor:
        """Compute anomaly scores.

        Scores are either PCA-based feature reconstruction error (FRE) scores or
        Gaussian density-based NLL scores.

        Args:
            features (torch.Tensor): Features for scoring with shape
                ``(n_samples, n_features)``.
            feature_shapes (tuple): Shape of features tensor for anomaly map.

        Returns:
            tuple[torch.Tensor, Optional[torch.Tensor]]: Tuple containing
                (scores, anomaly_maps). Anomaly maps are None for NLL scoring.
        """
        feats_projected = self.pca_model.transform(features)
        if self.score_type == "nll":
            score = self.gaussian_model.score_samples(feats_projected)
        elif self.score_type == "fre":
            feats_reconstructed = self.pca_model.inverse_transform(feats_projected)
            fre = torch.square(features - feats_reconstructed).reshape(feature_shapes)
            score_map = torch.unsqueeze(torch.sum(fre, dim=1), 1)
            score = torch.sum(torch.square(features - feats_reconstructed), dim=1)
        else:
            msg = f"unsupported score type: {self.score_type}"
            raise ValueError(msg)

        return (score, None) if self.score_type == "nll" else (score, score_map)
Compute anomaly scores.

        Scores are either PCA-based feature reconstruction error (FRE) scores or
        Gaussian density-based NLL scores.

        Args:
            features (torch.Tensor): Features for scoring with shape
                ``(n_samples, n_features)``.
            feature_shapes (tuple): Shape of features tensor for anomaly map.

        Returns:
            tuple[torch.Tensor, Optional[torch.Tensor]]: Tuple containing
                (scores, anomaly_maps). Anomaly maps are None for NLL scoring.
        
src/anomalib/models/image/dfm/torch_model.py