class_docstr: Class defining categorical distribution type functionality
docstr: Used to prevent spurious cycles between expanded columns and other features.
  For example, A_cat1 -> B -> A_cat2 would not be penalized by the h(W) constraint.
  
  This modification solves that by adding the expanded columns of the
  squared adjacency matrix onto the original column. This effectively superimposes
  All expanded column connections onto a single connection
  
  Args:
      square_weight_mat: The squared adjacency matrix used in h(W).
  
  Returns:
      The modified W matrix.
docstr_tok: ["Used","to","prevent","spurious","cycles","between","expanded","columns","and","other","features",".","For","example",",","A_cat1","-",">","B","-",">","A_cat2","would","not","be","penalized","by","the","h","(","W",")","constraint",".","This","modification","solves","that","by","adding","the","expanded","columns","of","the","squared","adjacency","matrix","onto","the","original","column",".","This","effectively","superimposes","All","expanded","column","connections","onto","a","single","connection","Args",":","square_weight_mat",":","The","squared","adjacency","matrix","used","in","h","(","W",")",".","Returns",":","The","modified","W","matrix","."]
code: def modify_h(self, square_weight_mat: torch.Tensor) -> torch.Tensor:
      """
      Used to prevent spurious cycles between expanded columns and other features.
      For example, A_cat1 -> B -> A_cat2 would not be penalized by the h(W) constraint.
  
      This modification solves that by adding the expanded columns of the
      squared adjacency matrix onto the original column. This effectively superimposes
      All expanded column connections onto a single connection
  
      Args:
          square_weight_mat: The squared adjacency matrix used in h(W).
  
      Returns:
          The modified W matrix.
      """
      orig_idx = self.idx_group[0]
      expand_idx = self.idx_group[1:]
  
      # Add on the edges from expanded nodes.
      square_weight_mat[orig_idx, :] = square_weight_mat[
          orig_idx, :
      ] + torch.sum(square_weight_mat[expand_idx, :], dim=0)
      # Add on the edges to expanded nodes.
      square_weight_mat[:, orig_idx] = square_weight_mat[
          :, orig_idx
      ] + torch.sum(square_weight_mat[:, expand_idx], dim=1)
  
      return square_weight_mat
  
imports: from copy import deepcopy
  from typing import Dict, List, Tuple
  import numpy
  import torch
  from sklearn.preprocessing import OneHotEncoder
  from torch import nn
  from causalnex.structure.pytorch.dist_type._base import DistTypeBase, ExpandColumnsMixin
  from causalnex.structure.structuremodel import StructureModel
label_desc: Use image node_id 5 for calling the DistTypeCategorical obj's underlying member method code with example usage: obj.modify_h(square_weight_mat) and returns: square_weight_mat