code: def penalized_wls(endog, exog, penalty_matrix, weights):
      """weighted least squares with quadratic penalty
  
      Parameters
      ----------
      endog : ndarray
          response or endogenous variable
      exog : ndarray
          design matrix, matrix of exogenous or explanatory variables
      penalty_matrix : ndarray, 2-Dim square
          penality matrix for quadratic penalization. Note, the penalty_matrix
          is multiplied by two to match non-pirls fitting methods.
      weights : ndarray
          weights for WLS
  
      Returns
      -------
      results : Results instance of WLS
      """
      y, x, s = endog, exog, penalty_matrix
      # TODO: I do not understand why I need 2 * s
      aug_y, aug_x, aug_weights = make_augmented_matrix(
          y, x, 2 * s, weights
      )
      wls_results = lm.WLS(aug_y, aug_x, aug_weights).fit()
      # TODO: use MinimalWLS during iterations, less overhead
      # However, MinimalWLS does not return normalized_cov_params
      #   which we need at the end of the iterations
      # call would be
      # wls_results = reg_tools._MinimalWLS(aug_y, aug_x, aug_weights).fit()
      wls_results.params = wls_results.params.ravel()
  
      return wls_results
  
imports: from collections.abc import Iterable
  import copy
  import numpy
  from scipy import optimize
  import pandas
  import statsmodels.base.wrapper
  from statsmodels.discrete.discrete_model import Logit
  from statsmodels.genmod.generalized_linear_model import GLM, GLMResults, GLMResultsWrapper, _check_convergence
  import statsmodels.regression.linear_model
  from statsmodels.tools.sm_exceptions import PerfectSeparationError, ValueWarning
  from statsmodels.tools.decorators import cache_readonly
  from statsmodels.tools.data import _is_using_pandas
  from statsmodels.tools.linalg import matrix_sqrt
  from statsmodels.base._penalized import PenalizedMixin
  from statsmodels.gam.gam_penalties import MultivariateGamPenalty
  from statsmodels.gam.gam_cross_validation.gam_cross_validation import MultivariateGAMCVPath
  from statsmodels.gam.gam_cross_validation.cross_validators import KFold
label_desc: Use image node_id 2 for calling a global function with example usage: penalized_wls(endog, exog, penalty_matrix, weights) and returns: wls_results