code: def test_AndAggregator(self):
      aggregator = AndAggregator()
  
      # simple case
      # aggregator must have an accuracy of 0 for input with 2 components
      # (only 1 and only 0) and ground truth is only 1
      assert (
          abs(
              aggregator.eval_accuracy(
                  self.onlyones,
                  self.series_1_and_0,
                  metric="accuracy",
              )
              - 0
          )
          < 1e-05
      )
      # aggregator must have an accuracy of 0 for input with 2 components
      # (only 1 and only 0) and ground truth is only 0
      assert (
          abs(
              aggregator.eval_accuracy(
                  self.onlyzero,
                  self.series_1_and_0,
                  metric="accuracy",
              )
              - 1
          )
          < 1e-05
      )
  
      # aggregator must have an accuracy of 1 for the input containing only 1
      assert (
          abs(
              aggregator.eval_accuracy(
                  self.onlyones,
                  self.mts_onlyones,
                  metric="accuracy",
              )
              - 1
          )
          < 1e-05
      )
      # aggregator must have an accuracy of 1 for the input containing only 1
      assert (
          abs(
              aggregator.eval_accuracy(
                  self.onlyones,
                  self.mts_onlyones,
                  metric="recall",
              )
              - 1
          )
          < 1e-05
      )
      # aggregator must have an accuracy of 1 for the input containing only 1
      assert (
          abs(
              aggregator.eval_accuracy(
                  self.onlyones,
                  self.mts_onlyones,
                  metric="precision",
              )
              - 1
          )
          < 1e-05
      )
  
      # single series case (random example)
      # aggregator must found 27 anomalies in the input mts_anomalies1
      assert (
          aggregator.predict(self.mts_anomalies1)
          .sum(axis=0)
          .all_values()
          .flatten()[0]
          == 27
      )
  
      # aggregator must have an accuracy of 0.44 for the input mts_anomalies1
      assert (
          abs(
              aggregator.eval_accuracy(
                  self.real_anomalies,
                  self.mts_anomalies1,
                  metric="accuracy",
              )
              - 0.44
          )
          < 1e-05
      )
      # aggregator must have an recall of 0.21568 for the input mts_anomalies1
      assert (
          abs(
              aggregator.eval_accuracy(
                  self.real_anomalies,
                  self.mts_anomalies1,
                  metric="recall",
              )
              - 0.21568
          )
          < 1e-05
      )
      # aggregator must have an f1 of 0.28205 for the input mts_anomalies1
      assert (
          abs(
              aggregator.eval_accuracy(
                  self.real_anomalies, self.mts_anomalies1, metric="f1"
              )
              - 0.28205
          )
          < 1e-05
      )
      # aggregator must have an precision of 0.40740 for the input mts_anomalies1
      assert (
          abs(
              aggregator.eval_accuracy(
                  self.real_anomalies,
                  self.mts_anomalies1,
                  metric="precision",
              )
              - 0.40740
          )
          < 1e-05
      )
  
      # multiple series case (random example)
      # aggregator must found [27,24] anomalies in the input [mts_anomalies1, mts_anomalies2]
      values = aggregator.predict(
          [self.mts_anomalies1, self.mts_anomalies2]
      )
      np.testing.assert_array_almost_equal(
          [v.sum(axis=0).all_values().flatten()[0] for v in values],
          [27, 24],
          decimal=1,
      )
  
      # aggregator must have an accuracy of [0.44,0.53] for the input [mts_anomalies1, mts_anomalies2]
      np.testing.assert_array_almost_equal(
          np.array(
              aggregator.eval_accuracy(
                  [self.real_anomalies, self.real_anomalies],
                  [self.mts_anomalies1, self.mts_anomalies2],
                  metric="accuracy",
              )
          ),
          np.array([0.44, 0.53]),
          decimal=1,
      )
      # aggregator must have an recall of [0.215686,0.27451] for the input [mts_anomalies1, mts_anomalies2]
      np.testing.assert_array_almost_equal(
          np.array(
              aggregator.eval_accuracy(
                  [self.real_anomalies, self.real_anomalies],
                  [self.mts_anomalies1, self.mts_anomalies2],
                  metric="recall",
              )
          ),
          np.array([0.215686, 0.27451]),
          decimal=1,
      )
      # aggregator must have an f1 of [0.282051,0.373333] for the input [mts_anomalies1, mts_anomalies2]
      np.testing.assert_array_almost_equal(
          np.array(
              aggregator.eval_accuracy(
                  [self.real_anomalies, self.real_anomalies],
                  [self.mts_anomalies1, self.mts_anomalies2],
                  metric="f1",
              )
          ),
          np.array([0.282051, 0.373333]),
          decimal=1,
      )
      # aggregator must have an precision of [0.407407, 0.583333] for the input [mts_anomalies1, mts_anomalies2]
      np.testing.assert_array_almost_equal(
          np.array(
              aggregator.eval_accuracy(
                  [self.real_anomalies, self.real_anomalies],
                  [self.mts_anomalies1, self.mts_anomalies2],
                  metric="precision",
              )
          ),
          np.array([0.407407, 0.583333]),
          decimal=1,
      )
  
file_path: darts/darts/tests/ad/test_aggregators.py
imports: from typing import Sequence
  import numpy
  import pytest
  from sklearn.ensemble import GradientBoostingClassifier
  from darts import TimeSeries
  from darts.ad.aggregators.and_aggregator import AndAggregator
  from darts.ad.aggregators.ensemble_sklearn_aggregator import EnsembleSklearnAggregator
  from darts.ad.aggregators.or_aggregator import OrAggregator
  from darts.models import MovingAverageFilter
label_desc: Use image node_id 7 for calling the TestADAggregators obj's underlying member method code with example usage: obj.test_AndAggregator() without return types