code: def test_categorical_from_structure_weighted(X, w):
      structure = ((), (0,), (1, 3), ())
      distributions = _from_structure(
          X, sample_weight=w, structure=structure
      )
      model = BayesianNetwork(distributions, structure=structure)
  
      assert isinstance(model.distributions[0], Categorical)
      assert isinstance(model.distributions[1], ConditionalCategorical)
      assert isinstance(model.distributions[2], ConditionalCategorical)
      assert isinstance(model.distributions[3], Categorical)
  
      p0 = model.distributions[0].probs
      p1 = model.distributions[1].probs[0]
      p2 = model.distributions[2].probs[0]
      p3 = model.distributions[3].probs
  
      assert_array_almost_equal(p0, [[0.6719, 0.3281]], 4)
      assert_array_almost_equal(
          p1, [[0.2674, 0.6047, 0.1279], [0.2381, 0.5238, 0.2381]], 4
      )
      assert_array_almost_equal(
          p2,
          [
              [[0.0000, 1.0000], [0.6667, 0.3333]],
              [[0.7561, 0.2439], [1.0000, 0.0000]],
              [[0.4762, 0.5238], [0.5000, 0.5000]],
          ],
          4,
      )
      assert_array_almost_equal(p3, [[0.5078, 0.4922]], 4)
  
imports: import numpy
  import torch
  import pytest
  from pomegranate.bayesian_network import BayesianNetwork
  from pomegranate.bayesian_network import _from_structure
  from pomegranate.bayesian_network import _learn_structure
  from pomegranate.bayesian_network import _categorical_exact
  from pomegranate.bayesian_network import _categorical_chow_liu
  from pomegranate.distributions import Categorical
  from pomegranate.distributions import ConditionalCategorical
  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_categorical_from_structure_weighted(X, w) without return types