code: def test_weighted_average_aggregator():
      """Test the AverageAggregator
  
      - Test the AverageAggregator correctly aggregates data passed to it
      - Test the AverageAggregator throws an error if the weights are not valid
      - Test the AverageAggregator can be torch scripted
      """
      weights = abs(torch.randn((10)))
  
      with pytest.raises(ValueError) as err:
          aggregator = ensemble.AverageAggregator(weights=weights)
      assert err.value.args[0] == "Weights must sum to 1."
  
      # test the aggregator correctly weights the scores when computing the
      # average
      weights /= weights.sum()
      aggregator = ensemble.AverageAggregator(weights=weights)
      scores = torch.randn((3, 10))
      aggregated_scores = aggregator(scores)
      torch.allclose(aggregated_scores, (weights @ scores.T))
      assert aggregated_scores.shape == (3,)
  
      # test the scriptability of the aggregator
      aggregator = torch.jit.script(aggregator)
      aggregated_scores_2 = aggregator(scores)
      assert torch.all(aggregated_scores_2 == aggregated_scores)
  
file_path: alibi-detect/alibi_detect/od/tests/test_ensemble.py
imports: import pytest
  import torch
  from alibi_detect.od.pytorch import ensemble
  from alibi_detect.exceptions import NotFittedError
label_desc: Use image node_id 4 for calling a global function with example usage: test_weighted_average_aggregator() without return types