def isotonic_regression(y, sample_weight=None, y_min=None, y_max=None, increasing=True):
 order = (np.s_[:] if increasing else np.s_[::(-1)])
 y = np.array(y[order], dtype=np.float64)
 if (sample_weight is None):
  sample_weight = np.ones(len(y), dtype=np.float64)
 else:
  sample_weight = np.array(sample_weight[order], dtype=np.float64)
 _inplace_contiguous_isotonic_regression(y, sample_weight)
 if ((y_min is not None) or (y_max is not None)):
  if (y_min is None):
   y_min = (- np.inf)
  if (y_max is None):
   y_max = np.inf
  np.clip(y, y_min, y_max, y)
 return y[order]

def isotonic_regression ( y , sample_weight = None , y_min = None , y_max = None , increasing = True ) : order = ( np . s_ [ : ] if increasing else np . s_ [ : : ( - 1 ) ] ) y = np . array ( y [ order ] , dtype = np . float64 ) if ( sample_weight is None ) : sample_weight = np . ones ( len ( y ) , dtype = np . float64 ) else : sample_weight = np . array ( sample_weight [ order ] , dtype = np . float64 ) _inplace_contiguous_isotonic_regression ( y , sample_weight ) if ( ( y_min is not None ) or ( y_max is not None ) ) : if ( y_min is None ) : y_min = ( - np . inf ) if ( y_max is None ) : y_max = np . inf np . clip ( y , y_min , y_max , y ) return y [ order ]
solve the isotonic regression model:: min sum w[i] ** 2 subject to y_min = y_[1] <= y_[2] .