public static double Accuracy(FunctionStack functionStack, NdArray x, NdArray y) { double matchCount = 0; NdArray forwardResult = functionStack.Predict(x)[0]; for (int b = 0; b < x.BatchCount; b++) { Real maxval = forwardResult.Data[b * forwardResult.Length]; int maxindex = 0; for (int i = 1; i < forwardResult.Length; i++) { if (maxval < forwardResult.Data[b * forwardResult.Length + i]) { maxval = forwardResult.Data[b * forwardResult.Length + i]; maxindex = i; } } if (maxindex == (int)y.Data[b * y.Length]) { matchCount++; } } return(matchCount / x.BatchCount); }
public static T Accuracy <T>(FunctionStack <T> functionStack, NdArray <T> x, NdArray <int> y, LossFunction <T, int> lossFunction, out T loss) where T : unmanaged, IComparable <T> { NdArray <T> forwardResult = functionStack.Predict(x)[0]; loss = lossFunction.Evaluate(forwardResult, y); return(Accuracy(x, y, forwardResult)); }
public static T Accuracy <T>(FunctionStack <T> functionStack, NdArray <T> x, NdArray <int> y, LossFunction <T, int> lossFunction, out T loss) where T : unmanaged, IComparable <T> { int matchCount = 0; NdArray <T> forwardResult = functionStack.Predict(x)[0]; loss = lossFunction.Evaluate(forwardResult, y); for (int b = 0; b < x.BatchCount; b++) { T maxval = forwardResult.Data[b * forwardResult.Length]; int maxindex = 0; for (int i = 1; i < forwardResult.Length; i++) { if (maxval.CompareTo(forwardResult.Data[b * forwardResult.Length + i]) < 0) { maxval = forwardResult.Data[b * forwardResult.Length + i]; maxindex = i; } } if (maxindex == y.Data[b * y.Length]) { matchCount++; } } return((TVal <T>)matchCount / (TVal <T>)x.BatchCount); }
public static T Accuracy <T>(FunctionStack <T> functionStack, NdArray <T> x, NdArray <int> y) where T : unmanaged, IComparable <T> { return(Accuracy(x, y, functionStack.Predict(x)[0])); }