code: def _cal_score(xx, clf):
      depths = np.zeros((xx.shape[0], len(clf.estimators_)))
      depth_sum = np.zeros(xx.shape[0])
      deviations = np.zeros((xx.shape[0], len(clf.estimators_)))
      leaf_samples = np.zeros((xx.shape[0], len(clf.estimators_)))
  
      for ii, estimator_tree in enumerate(clf.estimators_):
          tree = estimator_tree.tree_
          n_node = tree.node_count
  
          if n_node == 1:
              continue
  
          # get feature and threshold of each node in the iTree
          # in feature_lst, -2 indicates the leaf node
          feature_lst, threshold_lst = (
              tree.feature.copy(),
              tree.threshold.copy(),
          )
  
          # compute depth and score
          leaves_index = estimator_tree.apply(xx)
          node_indicator = estimator_tree.decision_path(xx)
  
          # The number of training samples in each test sample leaf
          n_node_samples = estimator_tree.tree_.n_node_samples
  
          # node_indicator is a sparse matrix with shape (n_samples, n_nodes),
          # indicating the path of input data samples
          # each layer would result in a non-zero element in this matrix,
          # and then the row-wise summation is the depth of data sample
          n_samples_leaf = estimator_tree.tree_.n_node_samples[
              leaves_index
          ]
          d = (
              np.ravel(node_indicator.sum(axis=1))
              + _average_path_length(n_samples_leaf)
              - 1.0
          )
          depths[:, ii] = d
          depth_sum += d
  
          # decision path of data matrix XX
          node_indicator = np.array(node_indicator.todense())
  
          # set a matrix with shape [n_sample, n_node],
          # representing the feature value of each sample on each node
          # set the leaf node as -2
          value_mat = np.array(
              [xx[i][feature_lst] for i in range(xx.shape[0])]
          )
          value_mat[:, np.where(feature_lst == -2)[0]] = -2
          th_mat = np.array([threshold_lst for _ in range(xx.shape[0])])
  
          mat = np.abs(value_mat - th_mat) * node_indicator
  
          exist = mat != 0
          dev = mat.sum(axis=1) / (exist.sum(axis=1) + 1e-6)
          deviations[:, ii] = dev
  
      scores = 2 ** (
          -depth_sum
          / (
              len(clf.estimators_)
              * _average_path_length([clf.max_samples_])
          )
      )
      deviation = np.mean(deviations, axis=1)
      leaf_sample = (
          clf.max_samples_ - np.mean(leaf_samples, axis=1)
      ) / clf.max_samples_
  
      scores = scores * deviation
      # scores = scores * deviation * leaf_sample
      return scores
  
imports: from __future__ import division
  from __future__ import print_function
  import numpy
  import torch
  from sklearn.utils import check_array
  from sklearn.utils.validation import check_is_fitted
  from sklearn.ensemble import IsolationForest
  from sklearn.preprocessing import StandardScaler, MinMaxScaler
  from torch.utils.data import DataLoader
  from .base import BaseDetector
  from ..utils.torch_utility import get_activation_by_name
label_desc: Use image node_id 1 for calling a global function with example usage: _cal_score(xx, clf) and returns: scores