UNPKG

human-logic

Version:
70 lines 2.11 kB
"use strict"; /** * Fuzzy Logic (based on Zadeh operators) * * Fuzzy logical value is a number between `0.0` (0% probability) and `1.0` (100% probability). * @module */ Object.defineProperty(exports, "__esModule", { value: true }); exports.or = exports.and = exports.not = exports.normalize = exports.FUZZY_TRUE = exports.FUZZY_FALSE = void 0; var tslib_1 = require("tslib"); /** * Fuzzy logical value of `false` (zero probability) */ exports.FUZZY_FALSE = 0.0; /** * Fuzzy logical value of `true` (100% probability) */ exports.FUZZY_TRUE = 1.0; /** * Ensures the fuzzy value is between `0.0` and `1.0`. * * @return If `value` is less than `0.0`, returns `0.0`. * If `value` is greater then `1.0`, returns `1.0`. Otherwise returns `value`. * */ function normalize(value) { if (value >= exports.FUZZY_TRUE) return exports.FUZZY_TRUE; if (value <= exports.FUZZY_FALSE) return exports.FUZZY_FALSE; return value; } exports.normalize = normalize; /** * Fuzzy Logical NOT * @return Result of subtraction of provided value from `1.0`. */ function not(value) { return normalize(exports.FUZZY_TRUE - value); } exports.not = not; /** * Fuzzy Logical AND * * @param values Accepts an unlimited number of arguments * @return Result of Fuzzy Logical AND (the minimum of all provided values, defaults to `FUZZY_TRUE`) */ function and() { var values = []; for (var _i = 0; _i < arguments.length; _i++) { values[_i] = arguments[_i]; } return normalize(Math.min.apply(Math, tslib_1.__spreadArray([exports.FUZZY_TRUE], values, false))); } exports.and = and; /** * Fuzzy Logical OR * * @param values Accepts an unlimited number of arguments * @return Result of Fuzzy Logical OR (the maximum of all provided values, defaults to `FUZZY_FALSE`) */ function or() { var values = []; for (var _i = 0; _i < arguments.length; _i++) { values[_i] = arguments[_i]; } return normalize(Math.max.apply(Math, tslib_1.__spreadArray([exports.FUZZY_FALSE], values, false))); } exports.or = or; //# sourceMappingURL=Fuzzy.js.map