code: def runOptimiser(
      K, u, preOptw, initialValue, optimizer, maxWeight=10000
  ):
      """
      Args:
          K (double 2d array): Similarity/distance matrix
          u (double array): Mean similarity of each prototype
          preOptw (double): Weight vector
          initialValue (double): Initialize run
          optimizer (string): qpsolver ('cvxpy' or 'osqp')
          maxWeight (double): Upper bound on weight
  
      Returns:
          Prototypes, weights and objective values
      """
  
      #     Standard QP:
      #         minimize
      #             (1/2) * x.T * P * x + q.T * x
      #         subject to
      #             G * x <= h
      #             A * x == b
  
      #     QP Solved by Protodash:
      #         minimize
      #             (1/2) * x.T * K * x + (-u).T * x
      #         subject to
      #             G * x <= h
  
      assert (
          optimizer == "cvxpy" or optimizer == "osqp"
      ), "Please set optimizer as 'cvxpy' or 'osqp'"
  
      d = u.shape[0]
      lb = np.zeros((d, 1))
      ub = maxWeight * np.ones((d, 1))
  
      # x0 = initial value, provided optimizer supports it.
      x0 = np.append(preOptw, initialValue / K[d - 1, d - 1])
  
      G = np.vstack((np.identity(d), -1 * np.identity(d)))
      h = np.vstack((ub, -1 * lb)).ravel()
  
      # variable shapes: K = (d,d), u = (d,) G = (2d, d), h = (2d,)
  
      if optimizer == "cvxpy":
          x = cp.Variable(d)
          prob = cp.Problem(
              cp.Minimize((1 / 2) * cp.quad_form(x, K) + (-u).T @ x),
              [G @ x <= h],
          )
          prob.solve()
  
          xv = x.value.reshape(-1, 1)
          xreturn = x.value
  
      elif optimizer == "osqp":
          Ks = sparse.csc_matrix(K)
          Gs = sparse.csc_matrix(G)
          l_inf = -np.inf * np.ones(len(h))
  
          solver = OSQP()
          solver.setup(
              P=Ks,
              q=-u,
              A=Gs,
              l=l_inf,
              u=h,
              eps_abs=1e-4,
              eps_rel=1e-4,
              polish=True,
              verbose=False,
          )
          solver.warm_start(x=x0)
          res = solver.solve()
  
          xv = res.x.reshape(-1, 1)
          xreturn = res.x
  
      # compute objective function value
      P = K
      q = -u.reshape(-1, 1)
      obj_value = 1 / 2 * np.matmul(np.matmul(xv.T, P), xv) + np.matmul(
          q.T, xv
      )
  
      return (xreturn, obj_value[0, 0])
  
file_path: AIX360/aix360/algorithms/protodash/PDASH_utils.py
imports: from __future__ import print_function
  import numpy
  from numpy import array, ndarray
  import xport
  from sklearn.preprocessing import OneHotEncoder
  from scipy.spatial.distance import cdist
  import cvxpy
  from scipy import sparse
  from osqp import OSQP
label_desc: Use image node_id 1 for calling a global function with example usage: runOptimiser(K, u, preOptw, initialValue, optimizer, maxWeight) and returns: xreturn,  obj_value