code: def test_mahalanobis_linear_scoring():
      """Test Mahalanobis detector linear scoring method.
  
      Test that the Mahalanobis detector `_compute_linear_proj` method correctly whitens the x_ref data
      and that the score method correctly orders different test points. Test that the detector correctly
      detects true outliers and that the correct proportion of in distribution data is flagged as
      outliers.
      """
      mahalanobis_torch = MahalanobisTorch()
      mean = [8, 8]
      cov = [[2.0, 0.0], [0.0, 1.0]]
      x_ref = torch.tensor(
          np.random.multivariate_normal(mean, cov, 1000)
      )
      mahalanobis_torch.fit(x_ref)
      p = mahalanobis_torch._compute_linear_proj(
          mahalanobis_torch.x_ref
      )
  
      # test that the x_ref is whitened by the data
      assert p.mean() < 0.1
      assert p.std() - 1 < 0.1
  
      x_1 = torch.tensor([[8.0, 8.0]])
      scores_1 = mahalanobis_torch.score(x_1)
  
      x_2 = torch.tensor(np.random.multivariate_normal(mean, cov, 1))
      scores_2 = mahalanobis_torch.score(x_2)
  
      x_3 = torch.tensor([[-10.0, 10.0]])
      scores_3 = mahalanobis_torch.score(x_3)
  
      # test correct ordering of scores given outlyingness of data
      assert scores_1 < scores_2 < scores_3
  
      # test that detector correctly detects true Outlier
      mahalanobis_torch.infer_threshold(x_ref, 0.01)
      x = torch.cat((x_1, x_2, x_3))
      outputs = mahalanobis_torch.predict(x)
      assert torch.all(
          outputs.is_outlier == torch.tensor([False, False, True])
      )
      assert torch.all(
          mahalanobis_torch(x) == torch.tensor([False, False, True])
      )
  
      # test that 0.01 of the in distribution data is flagged as outliers
      x = torch.tensor(np.random.multivariate_normal(mean, cov, 1000))
      outputs = mahalanobis_torch.predict(x)
      assert (outputs.is_outlier.sum() / 1000) - 0.01 < 0.005
  
imports: import pytest
  import torch
  import numpy
  from alibi_detect.od.pytorch.mahalanobis import MahalanobisTorch
  from alibi_detect.exceptions import NotFittedError, ThresholdNotInferredError
label_desc: Use image node_id 1 for calling a global function with example usage: test_mahalanobis_linear_scoring() without return types