code: def test_summarize_weighted(X, w, probs):
      for probs_ in probs, None:
          d = ConditionalCategorical(probs_)
          d.summarize(X[:4], sample_weight=w[:4])
          assert_array_almost_equal(d._w_sum[0], [0.0, 3.9])
          assert_array_almost_equal(d._w_sum[1], [0.0, 0.0, 3.9])
          assert_array_almost_equal(d._w_sum[2], [1.1, 2.8])
  
          assert_array_almost_equal(
              d._xw_sum[0], [[0.0, 0.0], [3.9, 0.0]]
          )
          assert_array_almost_equal(
              d._xw_sum[1], [[0.0, 0.0], [0.0, 0.0], [2.8, 1.1]]
          )
          assert_array_almost_equal(
              d._xw_sum[2], [[1.1, 0.0], [0.0, 2.8]]
          )
  
          d.summarize(X[4:], sample_weight=w[4:])
          assert_array_almost_equal(d._w_sum[0], [2.3, 11.2])
          assert_array_almost_equal(d._w_sum[1], [0.0, 9.6, 3.9])
          assert_array_almost_equal(d._w_sum[2], [8.9, 4.6])
  
          assert_array_almost_equal(
              d._xw_sum[0], [[2.3, 0.0], [9.4, 1.8]]
          )
          assert_array_almost_equal(
              d._xw_sum[1], [[0.0, 0.0], [4.1, 5.5], [2.8, 1.1]]
          )
          assert_array_almost_equal(
              d._xw_sum[2], [[8.9, 0.0], [0.0, 4.6]]
          )
  
          d = ConditionalCategorical(probs_)
          d.summarize(X, sample_weight=w)
          assert_array_almost_equal(d._w_sum[0], [2.3, 11.2])
          assert_array_almost_equal(d._w_sum[1], [0.0, 9.6, 3.9])
          assert_array_almost_equal(d._w_sum[2], [8.9, 4.6])
  
          assert_array_almost_equal(
              d._xw_sum[0], [[2.3, 0.0], [9.4, 1.8]]
          )
          assert_array_almost_equal(
              d._xw_sum[1], [[0.0, 0.0], [4.1, 5.5], [2.8, 1.1]]
          )
          assert_array_almost_equal(
              d._xw_sum[2], [[8.9, 0.0], [0.0, 4.6]]
          )
  
imports: import numpy
  import torch
  import pytest
  from pomegranate.distributions import ConditionalCategorical
  from ._utils import _test_initialization_raises_one_parameter
  from ._utils import _test_initialization
  from ._utils import _test_predictions
  from ._utils import _test_raises
  from nose.tools import assert_raises
  from numpy.testing import assert_array_almost_equal
label_desc: Use image node_id 18 for calling a global function with example usage: test_summarize_weighted(X, w, probs) without return types