code: def _average_path_length(n_samples_leaf):
      """
      The average path length in a n_samples iTree, which is equal to
      the average path length of an unsuccessful BST search since the
      latter has the same structure as an isolation tree.
      Parameters
      ----------
      n_samples_leaf : array-like of shape (n_samples,)
              The number of training samples in each test sample leaf, for
              each estimators.
  
      Returns
      -------
      average_path_length : ndarray of shape (n_samples,)
      """
  
      n_samples_leaf = check_array(n_samples_leaf, ensure_2d=False)
  
      n_samples_leaf_shape = n_samples_leaf.shape
      n_samples_leaf = n_samples_leaf.reshape((1, -1))
      average_path_length = np.zeros(n_samples_leaf.shape)
  
      mask_1 = n_samples_leaf <= 1
      mask_2 = n_samples_leaf == 2
      not_mask = ~np.logical_or(mask_1, mask_2)
  
      average_path_length[mask_1] = 0.0
      average_path_length[mask_2] = 1.0
      average_path_length[not_mask] = (
          2.0
          * (np.log(n_samples_leaf[not_mask] - 1.0) + np.euler_gamma)
          - 2.0
          * (n_samples_leaf[not_mask] - 1.0)
          / n_samples_leaf[not_mask]
      )
  
      return average_path_length.reshape(n_samples_leaf_shape)
  
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 2 for calling a global function with example usage: _average_path_length(n_samples_leaf) and returns: average_path_length