public static KerasSymbol CategorialHinge(KerasSymbol y_true, KerasSymbol y_pred) { var pos = K.Sum(y_true * y_pred, axis: -1); var neg = K.Max((1 - y_true) * y_pred, axis: -1); return(K.Maximum(0, neg - pos + 1)); }
public static KerasSymbol Softmax(KerasSymbol x, int axis = -1) { var ndim = K.NDim(x); if (ndim == 2) { return(K.Softmax(x)); } else if (ndim > 2) { var e = K.Exp(x - K.Max(x, axis: axis, keepdims: true)); var s = K.Sum(e, axis: axis, keepdims: true); return(e / s); } else if (ndim == 0) { // x dim is not inferred yet return(K.Softmax(x)); } else { throw new Exception($"Cannot apply softmax to a tensor that is 1D. Received input: {x}"); } }
public static KerasSymbol MultiHotSparseCategoricalAccuracy(KerasSymbol y_true, KerasSymbol y_pred) { return(K.Cast(K.Equal(K.Max(y_true, axis: -1), K.Cast(K.Argmax(y_pred, axis: -1), K.FloatX())), K.FloatX())); }