Skip to content

Commit

Permalink
feat(math): add more parametric T-norms
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Dec 13, 2020
1 parent f15d8d7 commit 38bd40e
Showing 1 changed file with 67 additions and 25 deletions.
92 changes: 67 additions & 25 deletions packages/math/src/tnorms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 38bd40e

Please sign in to comment.