@thi.ng/fuzzy
Version:
Fuzzy logic operators & configurable rule inferencing engine
176 lines • 4.86 kB
TypeScript
import type { FnN2, FnU, FnU2, FnU3, FnU4 } from "@thi.ng/api";
import type { FuzzyFn } from "./api.js";
/**
* HOF {@link FuzzyFn} always yielding given `x` (should be in `[0,1]`
* interval).
*
* @param x -
*/
export declare const constant: (x: number) => FuzzyFn;
/**
* HOF {@link FuzzyFn} which takes a value `p` and tolerance `eps`, then yields
* a discrete window function: `|p - x| <= eps ? 1 : 0`
*
* @param p -
* @param eps -
*/
export declare const point: (p: number, eps?: number) => FuzzyFn;
/**
* HOF {@link FuzzyFn} yielding a rising ramp in `[a,b]` interval, clamped to
*`[0,1]`outputs. Returns 0.0 for inputs <= `a` and 1.0 for inputs >= `b`.
*
* @param a -
* @param b -
*/
export declare const ramp: FnU2<number, FuzzyFn>;
/**
* HOF {@link FuzzyFn} yielding a triangle in the input range `[a..b..c]` with
* `b` defining the position of the peak value (1.0). Returns 0.0 for inputs
* outside the `[a,c]` interval.
*
* @param a -
* @param b -
* @param c -
*/
export declare const triangle: FnU3<number, FuzzyFn>;
/**
* Similar to {@link triangle}, but yielding a trapezoid for the input range
* `[a..b..c..d]` with `b` and `c` defining the peak value range (with 1.0
* outputs). Returns 0.0 for inputs < `a` or > `d`.
*
* @param a -
* @param b -
* @param c -
* @param d -
*/
export declare const trapezoid: FnU4<number, FuzzyFn>;
/**
* HOF {@link FuzzyFn}, yielding sigmoid curve with configurable `steep` and
* positioned such that `f(bias) = 0.5`.
*
* @param bias -
* @param steep -
*/
export declare const sigmoid: FnU2<number, FuzzyFn>;
/**
* HOF {@link FuzzyFn}, yielding gaussian bell curve with its peak at `bias` and
* width defined by `sigma`.
*
* @param bias -
* @param sigma -
*/
export declare const gaussian: FnU2<number, FuzzyFn>;
/**
* Higher-order function: Takes an existing {@link FuzzyFn} `fn` and returns
* a new one producing its negated outcome aka `1 - fn(x)`.
*
* @param fn -
*/
export declare const negate: FnU<FuzzyFn>;
/**
* Inverse of {@link ramp}, i.e. a falling slope from `a` -> `b`.
*
* @param a -
* @param b -
*/
export declare const invRamp: FnU2<number, FuzzyFn>;
/**
* Inverse of {@link sigmoid}.
*
* @param bias -
* @param steep -
*/
export declare const invSigmoid: FnU2<number, FuzzyFn>;
/**
* Higher-order function: Takes an existing {@link FuzzyFn} `fn` and `weight`
* factor. Returns new function which computes: `weight * fn(x)`.
*
* @param fn -
* @param weight -
*/
export declare const weighted: (fn: FuzzyFn, weight: number) => FuzzyFn;
/**
* Higher order function. Returns new function which selects subset of given
* fuzzy set where `fn(x) > alpha`, or else returns 0.
*
* @param fn -
* @param alpha -
*/
export declare const alphaCut: (fn: FuzzyFn, alpha?: number) => FuzzyFn;
/**
* Higher order function. Returns new function which selects subset of given
* fuzzy set where `fn(x) < alpha`, or else returns 0.
*
* @param fn -
* @param alpha -
*/
export declare const invAlphaCut: (fn: FuzzyFn, alpha?: number) => FuzzyFn;
/**
* Higher order function, complex shape generator. Takes a T-norm (or S-norm) as
* reduction function `op` and any number of {@link FuzzyFn}s. Returns new
* `FuzzyFn` which evaluates all given `fns` and combines/reduces their results
* with `op`.
*
* @remarks
* Depending on the use case and choice of `op`, the `initial` value should
* either be set to:
*
* - T-norm like function: 1.0
* - S-norm like function: 0.0
*
* References:
*
* - [Interactive graph](https://www.desmos.com/calculator/pnq6kqzfb5)
* - https://en.wikipedia.org/wiki/T-norm
* - https://github.com/thi-ng/umbrella/blob/develop/packages/fuzzy/src/tnorms.ts
*
* @example
* ```ts
* import { compose, tnormMin, triangle } from "@thi.ng/fuzzy";
*
* const f = compose(tnormMin, 1, triangle(0,2,4), triangle(1,3,5));
* f(1); // 0
* f(2); // 0.5
* f(3); // 0.5
* f(4); // 0
* ```
*
* @example
* ```ts
* import { compose, triangle } from "@thi.ng/fuzzy";
*
* // M-like shape w/ peaks at 3 & 5
* const M = compose(
* Math.max,
* 0,
* triangle(1,3,5),
* triangle(3,5,7)
* )
*
* M(3) // 1
* M(4) // 0.5
* M(5) // 1
* ```
*
* @param op -
* @param initial -
* @param fns -
*/
export declare const compose: (op: FnN2, initial: number, ...fns: FuzzyFn[]) => FuzzyFn;
/**
* Syntax sugar for {@link compose} with an initial value of 1.0. The `op` is
* supposed to be a T-norm.
*
* @param op -
* @param fns -
*/
export declare const intersect: (op: FnN2, ...fns: FuzzyFn[]) => import("@thi.ng/api").FnN;
/**
* Syntax sugar for {@link compose} with an initial value of 0.0. The `op` is
* supposed to be a S-norm.
*
* @param op -
* @param fns -
*/
export declare const union: (op: FnN2, ...fns: FuzzyFn[]) => import("@thi.ng/api").FnN;
//# sourceMappingURL=shapes.d.ts.map