class_docstr: Class for NOTEARS MLP (Multi-layer Perceptron) model.
  The model weights consist of dag_layer and loc_lin_layer weights respectively.
  dag_layer weight is the weight of the first fully connected layer which determines the causal structure.
  loc_lin_layer weights are the weight of hidden layers after the first fully connected layer
class_docstr_tok: ["Class","for","NOTEARS","MLP","(","Multi-layer","Perceptron",")","model",".","The","model","weights","consist","of","dag_layer","and","loc_lin_layer","weights","respectively",".","dag_layer","weight","is","the","weight","of","the","first","fully","connected","layer","which","determines","the","causal","structure",".","loc_lin_layer","weights","are","the","weight","of","hidden","layers","after","the","first","fully","connected","layer"]
docstr: Take average 2-norm-squared of all weight parameters of the model.
  NOTE: regularisation needs to be scaled up by the number of features
  because the loss scales with feature number.
  
  Returns:
      l2 regularisation term.
docstr_tok: ["Take","average","2-norm-squared","of","all","weight","parameters","of","the","model",".","NOTE",":","regularisation","needs","to","be","scaled","up","by","the","number","of","features","because","the","loss","scales","with","feature","number",".","Returns",":","l2","regularisation","term","."]
code: def _l2_reg(self, n_features: int) -> torch.Tensor:
      """
      Take average 2-norm-squared of all weight parameters of the model.
      NOTE: regularisation needs to be scaled up by the number of features
      because the loss scales with feature number.
  
      Returns:
          l2 regularisation term.
      """
      reg = 0.0
      reg += torch.sum(self.dag_layer_weight**2)
  
      for layer in self.loc_lin_layer_weights:
          reg += torch.sum(layer.weight**2)
  
      # calculate the total number of elements used in the above sums
      n_elements = self.dag_layer_weight.numel()
  
      for layer in self.loc_lin_layer_weights:
          n_elements = n_elements + layer.weight.numel()
  
      return reg / n_elements * n_features
  
imports: import logging
  from typing import Iterable, List, Tuple, Union
  import numpy
  import scipy.optimize
  import torch
  from sklearn.base import BaseEstimator
  from torch import nn
  from causalnex.structure.pytorch.dist_type._base import DistTypeBase
  from causalnex.structure.pytorch.nonlinear import LocallyConnected
label_desc: Use image node_id 13 for calling the NotearsMLP obj's underlying member method code with example usage: obj._l2_reg(n_features) and returns: unknown