code: def estimateimpl(
      n,
      sumw,
      sumwsq,
      sumwr,
      sumwsqr,
      sumwany,
      sumwsqany,
      wmin,
      wmax,
      rmin=0,
      rmax=1,
      raiseonerr=False,
      censored=False,
  ):
      from math import inf
  
      assert wmin >= 0
      assert wmin < 1
      assert wmax > 1
      assert rmax >= rmin
  
      wfake = wmax if sumw < n else wmin
  
      if wfake == inf:
          gammastar = -(1 + n) / n
          betastar = 0
          gstar = 1 + 1 / n
      else:
          a = (wfake + sumw) / (1 + n)
          b = (wfake**2 + sumwsq) / (1 + n)
          assert a * a < b
          gammastar = (b - a) / (a * a - b)
          betastar = (1 - a) / (a * a - b)
          gstar = (n + 1) * (a - 1) ** 2 / (b - a * a)
  
      vhat = (-gammastar * sumwr - betastar * sumwsqr) / (1 + n)
      missing = max(
          0, 1 - (-gammastar * sumw - betastar * sumwsq) / (1 + n)
      )
  
      if censored:
          # vhat = E[w r 1_{r is not None}] / E[w 1_{r is not None}]
  
          vnumhat = vhat
          vdenomhat = (-gammastar * sumwany - betastar * sumwsqany) / (
              1 + n
          )
  
          # Minimize[{ (x + a r) / (y + a),  y >= 0, 0 <= a <= m }, a]
          #
          # extrema is always at endpoints of interval
  
          vmincandidates = []
          vmaxcandidates = []
          if vdenomhat > 0:
              vmincandidates.append(vnumhat / vdenomhat)
              vmaxcandidates.append(vnumhat / vdenomhat)
  
          if vdenomhat + missing > 0:
              vmincandidates.append(
                  (vnumhat + missing * rmin) / (vdenomhat + missing)
              )
              vmaxcandidates.append(
                  (vnumhat + missing * rmax) / (vdenomhat + missing)
              )
  
          vmin = min(vmincandidates, default=None)
          vmax = max(vmaxcandidates, default=None)
          vhat = (
              None
              if vmin is None or vmax is None
              else (vmin + vmax) / 2
          )
      else:
          vmin = vhat + missing * rmin
          vmax = vhat + missing * rmax
          vhat += missing * (rmin + rmax) / 2
  
      vmin, vmax, vhat = (
          None if x is None else min(rmax, max(rmin, x))
          for x in (vmin, vmax, vhat)
      )
  
      return vhat, {
          "primal": gstar,
          "gammastar": gammastar,
          "betastar": betastar,
          "vmin": vmin,
          "vmax": vmax,
          "num": n,
          "qfunc": lambda c, w, r: (c / (1 + n))
          * (-gammastar - betastar * w),
      }
  
label_desc: Use image node_id 2 for calling the CrMinusTwo obj's underlying member method code with example usage: obj.estimateimpl(n, sumw, sumwsq, sumwr, sumwsqr, sumwany, sumwsqany, wmin, wmax, rmin, rmax, raiseonerr, censored) and returns: vhat,  dict