code: def p_mpjpe(predicted, target, rot=True, trans=True, scale=True):
      """
      Pose error: MPJPE after rigid alignment (scale, rotation, and translation),
      often referred to as "Protocol #2" in many papers.
      """
      assert predicted.shape == target.shape
  
      muX = np.mean(target, axis=1, keepdims=True)
      muY = np.mean(predicted, axis=1, keepdims=True)
  
      X0 = target - muX
      Y0 = predicted - muY
  
      normX = np.sqrt(np.sum(X0**2, axis=(1, 2), keepdims=True))
      normY = np.sqrt(np.sum(Y0**2, axis=(1, 2), keepdims=True))
  
      X0 /= normX
      Y0 /= normY
  
      H = np.matmul(X0.transpose(0, 2, 1), Y0)
      U, s, Vt = np.linalg.svd(H)
      V = Vt.transpose(0, 2, 1)
      R = np.matmul(V, U.transpose(0, 2, 1))
  
      # Avoid improper rotations (reflections), i.e. rotations with det(R) = -1
      sign_detR = np.sign(np.expand_dims(np.linalg.det(R), axis=1))
      V[:, :, -1] *= sign_detR
      s[:, -1] *= sign_detR.flatten()
      R = np.matmul(V, U.transpose(0, 2, 1))  # Rotation
  
      tr = np.expand_dims(np.sum(s, axis=1, keepdims=True), axis=2)
  
      a = tr * normX / normY  # Scale
      t = muX - a * np.matmul(muY, R)  # Translation
  
      # Perform rigid transformation on the input
      if rot:
          predicted_aligned = np.matmul(predicted, R)
      else:
          predicted_aligned = predicted
  
      if scale:
          predicted_aligned = a * predicted_aligned
      if trans:
          predicted_aligned = predicted_aligned + t
      # predicted_aligned = a * np.matmul(predicted, R) + t
  
      # Return MPJPE
      return np.mean(
          np.linalg.norm(
              predicted_aligned - target, axis=len(target.shape) - 1
          )
      )
  
imports: import os
  import torch
  import torch.optim
  import numpy
  from sklearn.metrics import auc
label_desc: Use image node_id 2 for calling a global function with example usage: p_mpjpe(predicted, target, rot, trans, scale) and returns: np