code: private TableFactor marginalizeMessage(TableFactor message, int[] relevant, MarginalizationMethod marginalize) {
      TableFactor result = message;
  
      for (int i : message.neighborIndices) {
        boolean contains = false;
        for (int j : relevant) {
          if (i == j) {
            contains = true;
            break;
          }
        }
        if (!contains) {
          switch (marginalize) {
            case SUM:
              result = result.sumOut(i);
              break;
            case MAX:
              result = result.maxOut(i);
              break;
          }
        }
      }
  
      return result;
    }
docs: This is a key step in message passing. When we are calculating a message, we want to marginalize out all variables
  not relevant to the recipient of the message. This function does that.
  
  @param message     the message to marginalize
  @param relevant    the variables that are relevant
  @return the marginalized message