code: def _create_weight_matrix(
      edges_w_weights: List[Tuple],
      variable_to_indices_dict: Dict[Hashable, List[int]],
      weight_distribution: str,
      intercept_distribution: str,
      intercept: bool,
  ) -> np.ndarray:
      """
      Creates a weight matrix for a linear SEM model from the edges of a graph.
      If the edges are unweighted, samples the weight values from a specified
      distribution. Optionally adds an intercept to the weights using a separate
      distribution.
      """
      n_columns = sum(len(x) for x in variable_to_indices_dict.values())
  
      w_mat = np.zeros(
          shape=(n_columns + 1 if intercept else n_columns, n_columns)
      )
      for node_from, node_to, weight in edges_w_weights:
          ix_from = variable_to_indices_dict[node_from]
          ix_to = variable_to_indices_dict[node_to]
          ix_mask_array = np.ix_(ix_from, ix_to)
  
          # we cannot assign the same weight for each category!
          n_weights = len(ix_from) * len(ix_to)
          if weight is None:
              if weight_distribution == "uniform":
                  # zero mean, unit variance:
                  w_mat[ix_mask_array] = np.random.uniform(
                      -np.sqrt(12) / 2,
                      np.sqrt(12) / 2,
                      size=(len(ix_from), len(ix_to)),
                  )
              elif weight_distribution in ("gaussian", "normal"):
                  w_mat[ix_mask_array] = np.random.normal(
                      loc=0, scale=1, size=(len(ix_from), len(ix_to))
                  )
              else:
                  _raise_dist_error(
                      "weight",
                      intercept_distribution,
                      ["uniform", "gaussian", "normal"],
                  )
  
          else:
              if n_weights == 1:
                  w_mat[ix_mask_array] = weight
              elif n_weights > 1:
                  # assign weight randomly to a category (through the
                  # normalization, this affects all categories from or to)
                  sparse_mask = np.random.uniform(
                      size=(len(ix_from), len(ix_to))
                  )
                  sparse_mask = (
                      sparse_mask == np.min(sparse_mask)
                  ).astype(int)
                  w_mat[ix_mask_array] = sparse_mask * weight
      if intercept:
          if intercept_distribution == "uniform":
              # zero mean, unit variance:
              w_mat[-1, :] = np.random.uniform(
                  -np.sqrt(12) / 2, np.sqrt(12) / 2, size=[1, n_columns]
              )
          elif intercept_distribution in ("gaussian", "normal"):
              w_mat[-1, :] = np.random.normal(
                  loc=0, scale=1, size=[1, n_columns]
              )
          else:
              _raise_dist_error(
                  "intercept",
                  intercept_distribution,
                  ["uniform", "gaussian", "normal"],
              )
  
      return w_mat
  
imports: from typing import Dict, Hashable, List, Optional, Tuple, Union
  import networkx
  import numpy
  import pandas
  from sklearn.gaussian_process.kernels import RBF, Kernel
  from causalnex.structure import StructureModel
  from causalnex.structure.categorical_variable_mapper import VariableFeatureMapper, validate_schema
label_desc: Use image node_id 11 for calling a global function with example usage: _create_weight_matrix(edges_w_weights, variable_to_indices_dict, weight_distribution, intercept_distribution, intercept) and returns: w_mat