code: def __init__(
      self,
      model,
      input_record,
      name="adaptive_weight",
      optimizer=None,
      weights=None,
      enable_diagnose=False,
      estimation_method="log_std",
      pos_optim_method="log_barrier",
      reg_lambda=0.1,
      **kwargs,
  ):
      super().__init__(model, name, input_record, **kwargs)
      self.output_schema = schema.Scalar(
          np.float32, self.get_next_blob_reference("adaptive_weight")
      )
      self.data = self.input_record.field_blobs()
      self.num = len(self.data)
      self.optimizer = optimizer
      if weights is not None:
          assert len(weights) == self.num
      else:
          weights = [1.0 / self.num for _ in range(self.num)]
      assert min(weights) > 0, "initial weights must be positive"
      self.weights = np.array(weights).astype(np.float32)
      self.estimation_method = str(estimation_method).lower()
      # used in positivity-constrained parameterization as when the estimation method
      # is inv_var, with optimization method being either log barrier, or grad proj
      self.pos_optim_method = str(pos_optim_method).lower()
      self.reg_lambda = float(reg_lambda)
      self.enable_diagnose = enable_diagnose
      self.init_func = getattr(self, self.estimation_method + "_init")
      self.weight_func = getattr(
          self, self.estimation_method + "_weight"
      )
      self.reg_func = getattr(self, self.estimation_method + "_reg")
      self.init_func()
      if self.enable_diagnose:
          self.weight_i = [
              self.get_next_blob_reference("adaptive_weight_%d" % i)
              for i in range(self.num)
          ]
          for i in range(self.num):
              self.model.add_ad_hoc_plot_blob(self.weight_i[i])
  
file_path: pytorch/caffe2/python/layers/adaptive_weight.py
imports: import numpy
  from caffe2.python import core, schema
  from caffe2.python.layers.layers import ModelLayer
  from caffe2.python.regularizer import BoundedGradientProjection, LogBarrier
label_desc: Use image node_id 1 to create a new AdaptiveWeight object from inherited base classes: ModelLayer with example: obj = AdaptiveWeight(model, input_record, name, optimizer, weights, enable_diagnose, estimation_method, pos_optim_method, reg_lambda)