code: def __init__(
      self,
      input_dim: int,
      output_dim: int,
      num_history: int = 1,
      *,
      dt: DecisionTreeClassifier,
      encoder_settings: Optional[Dict[str, MLEncoderSettings]] = None,
      global_encoder_settings: Optional[MLGlobalEncoderSettings] = None,
  ):
      if DecisionTreeClassifier is None:
          raise ValueError("`scikit-learn` is needed for `NDT`")
      super().__init__(
          encoder_settings=encoder_settings,
          global_encoder_settings=global_encoder_settings,
      )
      if self.encoder is not None:
          input_dim += self.encoder.dim_increment
      input_dim *= num_history
      tree_structure = export_structure(dt)
      # dt statistics
      num_leaves = sum(
          [1 if pair[1] == -1 else 0 for pair in tree_structure]
      )
      num_internals = num_leaves - 1
      # transform
      b = np.zeros(num_internals, dtype=np.float32)
      w1 = np.zeros([input_dim, num_internals], dtype=np.float32)
      w2 = np.zeros([num_internals, num_leaves], dtype=np.float32)
      w3 = np.zeros([num_leaves, output_dim], dtype=np.float32)
      node_list: List[int] = []
      node_sign_list: List[int] = []
      node_id_cursor = leaf_id_cursor = 0
      for depth, feat_dim, rs in tree_structure:
          if feat_dim != -1:
              if depth == len(node_list):
                  node_sign_list.append(-1)
                  node_list.append(node_id_cursor)
                  w1[feat_dim, node_id_cursor] = 1
                  b[node_id_cursor] = -rs
                  node_id_cursor += 1
              else:
                  node_list = node_list[: depth + 1]
                  node_sign_list = node_sign_list[:depth] + [1]
          else:
              for node_id, node_sign in zip(node_list, node_sign_list):
                  w2[node_id, leaf_id_cursor] = node_sign / len(
                      node_list
                  )
              w3[leaf_id_cursor] = rs / np.sum(rs)
              leaf_id_cursor += 1
      w1_, w2_, w3_, b_ = map(to_torch, [w1, w2, w3, b])
      # construct planes & routes
      self.to_planes = Linear(
          input_dim, num_internals, init_method=None
      )
      self.to_routes = Linear(
          num_internals, num_leaves, bias=False, init_method=None
      )
      self.to_leaves = Linear(num_leaves, output_dim, init_method=None)
      with torch.no_grad():
          self.to_planes.linear.bias.data = b_
          self.to_planes.linear.weight.data = w1_.t()
          self.to_routes.linear.weight.data = w2_.t()
          self.to_leaves.linear.weight.data = w3_.t()
          uniform = F.log_softmax(
              torch.zeros(output_dim, dtype=torch.float32), dim=0
          )
          self.to_leaves.linear.bias.data = uniform
      # activations
      self.planes_activation = Activation.make("sign")
      self.routes_activation = Activation.make("one_hot")
  
imports: import torch
  import numpy
  import torch.nn.functional
  from typing import Dict
  from typing import List
  from typing import Iterator
  from typing import Optional
  from cftool.array import to_numpy
  from cftool.array import to_torch
  from .base import MLModel
  from ...schema import MLEncoderSettings
  from ...schema import MLGlobalEncoderSettings
  from ...modules.blocks import Linear
  from ...modules.blocks import Activation
label_desc: Use image node_id 1 to create a new NDT object from inherited base classes: MLModel with example: obj = NDT(input_dim, output_dim, num_history)