accuracy

calc accuracy for 1 class (single 0-1 output)

  1. float accuracy(Tensor!(T, Shape, useGrad1) output, Tensor!(T, Shape, useGrad2) label)
    float
    accuracy
    (
    T
    size_t[] Shape
    UseGradient useGrad1
    UseGradient useGrad2
    )
    (
    Tensor!(T, Shape, useGrad1) output
    ,
    Tensor!(T, Shape, useGrad2) label
    )
    if (
    Shape.length == 2 &&
    Shape[1] == 1
    )
  2. float accuracy(Tensor!(T, Shape, useGrad1) output, Tensor!(T, Shape, useGrad2) label)

Examples

ditto

auto xt = tensor!([0, 1])([0.1, 0.9, 0.8, 0.2]);
auto y0 = tensor!([0, 1])([1.0, 0.0, 0.0, 1.0]); // true: 0
auto y1 = tensor!([0, 1])([1.0, 0.0, 1.0, 1.0]); // true: 1
auto y2 = tensor!([0, 1])([1.0, 1.0, 1.0, 1.0]); // true: 2
auto y3 = tensor!([0, 1])([1.0, 1.0, 1.0, 0.0]); // true: 3
auto y4 = tensor!([0, 1])([0.0, 1.0, 1.0, 0.0]); // true: 4

assert(accuracy(xt, y0) == 0.0f);
assert(accuracy(xt, y1) == 0.25f);
assert(accuracy(xt, y2) == 0.5f);
assert(accuracy(xt, y3) == 0.75f);
assert(accuracy(xt, y4) == 1.0f);

Meta