(function (global, factory) {
  if (typeof define === "function" && define.amd) {
    define(["exports", "lodash/sum", "rxjs/operators"], factory);
  } else if (typeof exports !== "undefined") {
    factory(exports, require("lodash/sum"), require("rxjs/operators"));
  } else {
    var mod = {
      exports: {}
    };
    factory(mod.exports, global.sum, global.operators);
    global.accuracy = mod.exports;
  }
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _sum, _operators) {
  "use strict";

  Object.defineProperty(_exports, "__esModule", {
    value: true
  });
  _exports.default = void 0;
  _sum = _interopRequireDefault(_sum);

  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

  const computeAccuracy = function computeAccuracy(truePositives, falsePositives, trueNegatives, falseNegatives) {
    const total = (0, _sum.default)([truePositives, trueNegatives, falsePositives, falseNegatives]);
    return (0, _sum.default)([truePositives, trueNegatives]) / total;
  };

  function reducer({
    truePositives,
    falsePositives,
    trueNegatives,
    falseNegatives
  }, [trueLabel, predictedLabel]) {
    const newTruePositives = predictedLabel === 1 && predictedLabel === trueLabel ? truePositives + 1 : truePositives;
    const newFalsePositives = predictedLabel === 1 && predictedLabel !== trueLabel ? falsePositives + 1 : falsePositives;
    const newTrueNegatives = predictedLabel === 0 && predictedLabel === trueLabel ? trueNegatives + 1 : trueNegatives;
    const newFalseNegatives = predictedLabel === 0 && predictedLabel !== trueLabel ? falseNegatives + 1 : falseNegatives;
    return {
      truePositives: newTruePositives,
      falsePositives: newFalsePositives,
      trueNegatives: newTrueNegatives,
      falseNegatives: newFalseNegatives
    };
  }

  const accuracy = function accuracy(initialState = {
    truePositives: 0,
    falsePositives: 0,
    trueNegatives: 0,
    falseNegatives: 0
  }) {
    return source$ => source$.pipe((0, _operators.scan)(reducer, initialState), (0, _operators.map)(counts => computeAccuracy(counts.truePositives, counts.falsePositives, counts.trueNegatives, counts.falseNegatives)));
  };

  var _default = accuracy;
  _exports.default = _default;
});
//# sourceMappingURL=accuracy.js.map