| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- /**
- * This is the internal implementation of quantiles: when you know
- * that the order is sorted, you don't need to re-sort it, and the computations
- * are faster.
- *
- * @param {Array<number>} x sample of one or more data points
- * @param {number} p desired quantile: a number between 0 to 1, inclusive
- * @returns {number} quantile value
- * @throws {Error} if p ix outside of the range from 0 to 1
- * @throws {Error} if x is empty
- * @example
- * quantileSorted([3, 6, 7, 8, 8, 9, 10, 13, 15, 16, 20], 0.5); // => 9
- */
- export declare function quantileSorted(x: number[], p: number): number;
- /**
- * 交换数组位置
- * @param arr T[]
- * @param i number
- * @param j number
- */
- export declare function swap<T = any>(arr: T[], i: number, j: number): void;
- /**
- * Rearrange items in `arr` so that all items in `[left, k]` range are the smallest.
- * The `k`-th element will have the `(k - left + 1)`-th smallest value in `[left, right]`.
- *
- * Implements Floyd-Rivest selection algorithm https://en.wikipedia.org/wiki/Floyd-Rivest_algorithm
- *
- * @param {Array<number>} arr input array
- * @param {number} k pivot index
- * @param {number} [left] left index
- * @param {number} [right] right index
- * @returns {void} mutates input array
- * @example
- * var arr = [65, 28, 59, 33, 21, 56, 22, 95, 50, 12, 90, 53, 28, 77, 39];
- * quickselect(arr, 8);
- * // = [39, 28, 28, 33, 21, 12, 22, 50, 53, 56, 59, 65, 90, 77, 95]
- */
- export declare function quickselect(arr: number[], k: any, left?: number, right?: number): void;
- /**
- * The [quantile](https://en.wikipedia.org/wiki/Quantile):
- * this is a population quantile, since we assume to know the entire
- * dataset in this library. This is an implementation of the
- * [Quantiles of a Population](http://en.wikipedia.org/wiki/Quantile#Quantiles_of_a_population)
- * algorithm from wikipedia.
- *
- * Sample is a one-dimensional array of numbers,
- * and p is either a decimal number from 0 to 1 or an array of decimal
- * numbers from 0 to 1.
- * In terms of a k/q quantile, p = k/q - it's just dealing with fractions or dealing
- * with decimal values.
- * When p is an array, the result of the function is also an array containing the appropriate
- * quantiles in input order
- *
- * @param {Array<number>} x sample of one or more numbers
- * @param {Array<number> | number} p the desired quantile, as a number between 0 and 1
- * @returns {number} quantile
- * @example
- * quantile([3, 6, 7, 8, 8, 9, 10, 13, 15, 16, 20], 0.5); // => 9
- */
- declare function quantile(x: number[], p: number): number;
- declare function quantile(x: number[], p: number[]): number[];
- export { quantile };
|