code: def create_group_matrix(list_groups, input_dim):
      """
      Create the group matrix corresponding to the given list_groups
  
      Parameters
      ----------
      - list_groups : list of list of int
          Each element is a list representing features in the same group.
          One feature should appear in maximum one group.
          Feature that don't get assigned a group will be in their own group of one feature.
      - input_dim : number of feature in the initial dataset
  
      Returns
      -------
      - group_matrix : torch matrix
          A matrix of size (n_groups, input_dim)
          where m_ij represents the importance of feature j in group i
          The rows must some to 1 as each group is equally important a priori.
  
      """
      check_list_groups(list_groups, input_dim)
  
      if len(list_groups) == 0:
          group_matrix = torch.eye(input_dim)
          return group_matrix
      else:
          n_groups = input_dim - int(
              np.sum([len(gp) - 1 for gp in list_groups])
          )
          group_matrix = torch.zeros((n_groups, input_dim))
  
          remaining_features = [
              feat_idx for feat_idx in range(input_dim)
          ]
  
          current_group_idx = 0
          for group in list_groups:
              group_size = len(group)
              for elem_idx in group:
                  # add importrance of element in group matrix and corresponding group
                  group_matrix[current_group_idx, elem_idx] = (
                      1 / group_size
                  )
                  # remove features from list of features
                  remaining_features.remove(elem_idx)
              # move to next group
              current_group_idx += 1
          # features not mentionned in list_groups get assigned their own group of singleton
          for remaining_feat_idx in remaining_features:
              group_matrix[current_group_idx, remaining_feat_idx] = 1
              current_group_idx += 1
          return group_matrix
  
imports: from torch.utils.data import Dataset
  from torch.utils.data import DataLoader, WeightedRandomSampler
  import torch
  import numpy
  import scipy
  import json
  from sklearn.utils import check_array
  import pandas
  import warnings
label_desc: Use image node_id 4 for calling a global function with example usage: create_group_matrix(list_groups, input_dim) and returns: group_matrix, group_matrix