parameters: (y_true, y_pred, alpha=0.5, const=K.epsilon())
return_statement: return coef_val
docstring: Weighted Sørensen–Dice coefficient.
      
      Input
      ----------
          y_true, y_pred: predicted outputs and targets.
          const: a constant that smooths the loss gradient and reduces numerical instabilities.
docstring_summary: Weighted Sørensen–Dice coefficient.
      
      Input
      ----------
          y_true, y_pred: predicted outputs and targets.
          const: a constant that smooths the loss gradient and reduces numerical instabilities.
docstring_tokens: Weighted Sørensen–Dice coefficient . Input ---------- y_true y_pred : predicted outputs and targets . const : a constant that smooths the loss gradient and reduces numerical instabilities .
function: def tversky_coef(y_true, y_pred, alpha=0.5, const=K.epsilon()):
      '''
      Weighted Sørensen–Dice coefficient.
      
      Input
      ----------
          y_true, y_pred: predicted outputs and targets.
          const: a constant that smooths the loss gradient and reduces numerical instabilities.
          
      '''
      
      # flatten 2-d tensors
      y_true_pos = tf.reshape(y_true, [-1])
      y_pred_pos = tf.reshape(y_pred, [-1])
      
      # get true pos (TP), false neg (FN), false pos (FP).
      true_pos  = tf.reduce_sum(y_true_pos * y_pred_pos)
      false_neg = tf.reduce_sum(y_true_pos * (1-y_pred_pos))
      false_pos = tf.reduce_sum((1-y_true_pos) * y_pred_pos)
      
      # TP/(TP + a*FN + b*FP); a+b = 1
      coef_val = (true_pos + const)/(true_pos + alpha*false_neg + (1-alpha)*false_pos + const)
      
      return coef_val
function_tokens: def tversky_coef ( y_true , y_pred , alpha = 0.5 , const = K . epsilon ( ) ) : # flatten 2-d tensors y_true_pos = tf . reshape ( y_true , [ - 1 ] ) y_pred_pos = tf . reshape ( y_pred , [ - 1 ] ) # get true pos (TP), false neg (FN), false pos (FP). true_pos = tf . reduce_sum ( y_true_pos * y_pred_pos ) false_neg = tf . reduce_sum ( y_true_pos * ( 1 - y_pred_pos ) ) false_pos = tf . reduce_sum ( ( 1 - y_true_pos ) * y_pred_pos ) # TP/(TP + a*FN + b*FP); a+b = 1 coef_val = ( true_pos + const ) / ( true_pos + alpha * false_neg + ( 1 - alpha ) * false_pos + const ) return coef_val