code: def create_marginals(cpds, data_vals):
      cpd_d = cpds["d"]
      p_d = {i: cpd_d[i, 0] for i in range(len(cpd_d))}
  
      cpd_e = cpds["e"]
      p_e = {i: cpd_e[i, 0] for i in range(len(cpd_e))}
  
      cpd_b = cpds["b"]
      c_b = np.array(
          [
              [
                  p_d[d] * p_e[e]
                  for d in range(len(cpd_d))
                  for e in range(len(cpd_e))
              ]
              for _ in range(len(cpd_b))
          ]
      )
      p_b = dict(enumerate((c_b * cpd_b).sum(axis=1)))
  
      cpd_a = cpds["a"]
      c_a = np.array(
          [
              [
                  p_b[b] * p_d[d]
                  for b in range(len(cpd_b))
                  for d in range(len(cpd_d))
              ]
              for _ in range(len(cpd_a))
          ]
      )
      p_a = dict(enumerate((c_a * cpd_a).sum(axis=1)))
  
      cpd_c = cpds["c"]
      c_c = np.array(
          [
              [
                  p_b[b] * p_d[d] * p_e[e]
                  for b in range(len(cpd_b))
                  for d in range(len(cpd_d))
                  for e in range(len(cpd_e))
              ]
              for _ in range(len(cpd_c))
          ]
      )
      p_c = dict(enumerate((c_c * cpd_c).sum(axis=1)))
  
      marginals = {
          "a": {data_vals["a"][k]: v for k, v in p_a.items()},
          "b": {data_vals["b"][k]: v for k, v in p_b.items()},
          "c": {data_vals["c"][k]: v for k, v in p_c.items()},
          "d": {data_vals["d"][k]: v for k, v in p_d.items()},
          "e": {data_vals["e"][k]: v for k, v in p_e.items()},
      }
  
      return marginals
  
imports: import itertools
  from typing import Dict
  import numpy
  import pandas
  import pytest
  from pgmpy.models import BayesianNetwork
  from sklearn.datasets import load_iris
  from causalnex.discretiser import Discretiser
  from causalnex.network import BayesianNetwork
  from causalnex.structure import StructureModel
  from causalnex.structure.notears import from_pandas
label_desc: Use image node_id 12 for calling a global function with example usage: create_marginals(cpds, data_vals) and returns: marginals