code: def _simplex_project(v, s=1):
      assert s > 0, "Radius s must be strictly positive (%d <= 0)" % s
      (n,) = v.shape  # will raise ValueError if v is not 1-D
      # check if we are already on the simplex
      if _is_on_simplex(v, s):
          return v
      # get the array of cumulative sums of a sorted (decreasing) copy of v
      u = np.sort(v)[::-1]
      cssv = np.cumsum(u)
      # get the number of > 0 components of the optimal solution
      rho = np.nonzero(u * np.arange(1, n + 1) > (cssv - s))[0][-1]
      # compute the Lagrange multiplier associated to the simplex constraint
      theta = (cssv[rho] - s) / (rho + 1.0)
      # compute the projection by thresholding v using theta
      w = (v - theta).clip(min=0)
      return w
  
file_path: cornac/cornac/models/ctr/ctr.py
imports: import numpy
  from ...utils import get_rng
label_desc: Use image node_id 4 for calling a global function with example usage: _simplex_project(v, s) and returns: w, v