From 38bd40e1595e318c6472a526e03c8c8a06ebf396 Mon Sep 17 00:00:00 2001 From: Karsten Schmidt Date: Sun, 13 Dec 2020 22:03:29 +0000 Subject: [PATCH] feat(math): add more parametric T-norms --- packages/math/src/tnorms.ts | 92 +++++++++++++++++++++++++++---------- 1 file changed, 67 insertions(+), 25 deletions(-) diff --git a/packages/math/src/tnorms.ts b/packages/math/src/tnorms.ts index cfafa5e40c..0629c85c79 100644 --- a/packages/math/src/tnorms.ts +++ b/packages/math/src/tnorms.ts @@ -3,73 +3,115 @@ import { norm } from "./fit"; // https://en.wikipedia.org/wiki/T-norm -export const tnormMin: FnN2 = (a, b) => Math.min(a, b); +export const tnormMin: FnN2 = (x, y) => Math.min(x, y); -export const tnormProduct: FnN2 = (a, b) => a * b; +export const tnormProduct: FnN2 = (x, y) => x * y; -export const tnormLukasiewicz: FnN2 = (a, b) => Math.max(0, a + b - 1); +export const tnormLukasiewicz: FnN2 = (x, y) => Math.max(0, x + y - 1); -export const tnormDrastic: FnN2 = (a, b) => (a === 1 ? b : b === 1 ? a : 0); +export const tnormDrastic: FnN2 = (x, y) => (x === 1 ? y : y === 1 ? x : 0); -export const tnormNilpotent: FnN2 = (a, b) => (a + b > 1 ? Math.min(a, b) : 0); +export const tnormNilpotent: FnN2 = (x, y) => (x + y > 1 ? Math.min(x, y) : 0); /** * HOF T-norm. Parametric Hamacher with `p` controlling curvature. * * @remarks - * Interactive graph: https://www.desmos.com/calculator/rklntdutlt + * Interactive graph: https://www.desmos.com/calculator/4bneccqs3p * - * @param p - curve param (default: 2) + * @param p - curve param [0..∞], default: 2 */ -export const tnormHamacher = (p = 2): FnN2 => (a, b) => - a === 0 && b === 0 ? 0 : (a * b) / (p + (1 - p) * (a + b - a * b)); +export const tnormHamacher = (p = 2): FnN2 => (x, y) => + x === 0 && y === 0 ? 0 : (x * y) / (p + (1 - p) * (x + y - x * y)); +/** + * HOF T-norm. Parametric Yager with `p` controlling curvature. + * + * @remarks + * Interactive graph: https://www.desmos.com/calculator/4bneccqs3p + * + * @param p - curve param [0..∞], default: 2 + */ +export const tnormYager = (p = 2): FnN2 => + p === 0 + ? () => 0 + : (x, y) => Math.max(0, 1 - ((1 - x) ** p + (1 - y) ** p) ** (1 / p)); + +/** + * HOF T-norm. Parametric Dombi with `p` controlling curvature. + * + * @remarks + * Interactive graph: https://www.desmos.com/calculator/4bneccqs3p + * + * @param p - curve param [0..∞], default: 2 + */ +export const tnormDombi = (p = 2): FnN2 => + p === 0 + ? () => 0 + : (x, y) => + x === 0 || y === 0 + ? 0 + : 1 / + (1 + (((1 - x) / x) ** p + ((1 - y) / y) ** p) ** (1 / p)); + +/** + * HOF T-norm. Parametric Aczél–Alsina with `p` controlling curvature. + * + * @remarks + * Interactive graph: https://www.desmos.com/calculator/4bneccqs3p + * + * @param p - curve param [0..∞], default: 2 + */ +export const tnormAczelAlsina = (p = 2): FnN2 => (x, y) => + Math.exp( + -((Math.abs(Math.log(x)) ** p + Math.abs(Math.log(y)) ** p) ** (1 / p)) + ); /** * S-norm (T-conorm), dual of {@link tnormMin}. * - * @param a - * @param b + * @param x + * @param y */ -export const snormMax: FnN2 = (a, b) => Math.max(a, b); +export const snormMax: FnN2 = (x, y) => Math.max(x, y); /** * S-norm (T-conorm), dual of {@link tnormProduct}, probabilistic sum: * `a + b - a * b` * - * @param a - * @param b + * @param x + * @param y */ -export const snormProbabilistic: FnN2 = (a, b) => a + b - a * b; +export const snormProbabilistic: FnN2 = (x, y) => x + y - x * y; /** * S-norm (T-conorm), dual of {@link tnormLukasiewicz}. * - * @param a - * @param b + * @param x + * @param y */ -export const snormBoundedSum: FnN2 = (a, b) => Math.min(a + b, 1); +export const snormBoundedSum: FnN2 = (x, y) => Math.min(x + y, 1); /** * S-norm (T-conorm), dual of {@link tnormDrastic}. */ -export const snormDrastic: FnN2 = (a, b) => (a === 0 ? b : b === 0 ? a : 1); +export const snormDrastic: FnN2 = (x, y) => (x === 0 ? y : y === 0 ? x : 1); /** * S-norm (T-conorm), dual of {@link tnormNilpotent}. * - * @param a - * @param b + * @param x + * @param y */ -export const snormNilpotent: FnN2 = (a, b) => (a + b < 1 ? Math.max(a, b) : 1); +export const snormNilpotent: FnN2 = (x, y) => (x + y < 1 ? Math.max(x, y) : 1); /** * S-norm (T-conorm), dual of {@link tnormHamacher}, iff that T-norm's curve * param is `p=2`. * - * @param a - * @param b + * @param x + * @param y */ -export const snormEinstein: FnN2 = (a, b) => (a + b) / (1 + a * b); +export const snormEinstein: FnN2 = (x, y) => (x + y) / (1 + x * y); /** * HOF t-norm. Constructs a new t-norm based on given t-norms for disjoint