code: def constrained_logistic_fit(
      X: NDArray[Float],
      y: NDArray[Float],
      alpha_arr: NDArray[Float],
      guess: NDArray[Float],
      n_cov: Int,
  ) -> scipy.optimize.OptimizeResult:
      """
      Fits a logistic regression model using design matrix X and binary label y, with ridge penalization specified
      by the penalty parameters in alpha_arr (with one entry per column in X).  The optimization procedure starts from
      the initial state specified in the guess array.  The first n_cov columns in X are assumed to be fixed effects and
      the corresponding parameters are frozen with their initial values in guess.
  
      Args:
           X: [n_row, n_col] design matrix
           y: [n_row] binary label vector
           alpha_arr : array of n_col ridge penalty values
           guess : array of n_coll initial parameter guesses
           n_cov : number of columns in X (starting from the left) to consider fixed, and freeze at the initial guess
              during optimization.
  
      Returns:
          scipy optimize result containing optimized paramters from the fit.
      """
      if guess.size == 0:
          guess = np.zeros(X.shape[1])
  
      def objective(beta):
          z = X @ beta
          p = 1 / (1 + np.exp(-z))
          eps = 1e-15
          ll = (
              y * np.log(p + eps) + (1 - y) * np.log(1 - p + eps)
          ).sum()
          return -(ll - np.dot(alpha_arr * beta, beta) / 2) / y.size
  
      def gradient(beta):
          z = X @ beta
          p = 1 / (1 + np.exp(-z))
          grad = -(np.dot((y - p), X) - beta * alpha_arr) / y.size
          if n_cov > 0:
              grad[:n_cov] = 0
          return grad
  
      return scipy.optimize.minimize(
          objective, guess, jac=gradient, method="L-BFGS-B"
      )
  
imports: import itertools
  import math
  import re
  import warnings
  from typing import Any, Dict, Iterable, List, Tuple
  import numpy
  import pandas
  import pyspark.sql.functions
  import scipy.optimize
  from nptyping import Float, Int, NDArray
  from pyspark.sql import DataFrame, Row
  from pyspark.sql.window import Window
  from typeguard import typechecked
label_desc: Use image node_id 5 for calling a global function with example usage: constrained_logistic_fit(X, y, alpha_arr, guess, n_cov) and returns: scipy, unknown, grad