|
| 1 | +/* |
| 2 | +* @license Apache-2.0 |
| 3 | +* |
| 4 | +* Copyright (c) 2019 The Stdlib Authors. |
| 5 | +* |
| 6 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +* you may not use this file except in compliance with the License. |
| 8 | +* You may obtain a copy of the License at |
| 9 | +* |
| 10 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +* |
| 12 | +* Unless required by applicable law or agreed to in writing, software |
| 13 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +* See the License for the specific language governing permissions and |
| 16 | +* limitations under the License. |
| 17 | +*/ |
| 18 | + |
| 19 | +// TypeScript Version: 2.0 |
| 20 | + |
| 21 | +/// <reference types="@stdlib/types"/> |
| 22 | + |
| 23 | +interface Summary { |
| 24 | + /** |
| 25 | + * Window size. |
| 26 | + */ |
| 27 | + window: number; |
| 28 | + |
| 29 | + /** |
| 30 | + * Maximum value. |
| 31 | + */ |
| 32 | + max: number; |
| 33 | + |
| 34 | + /** |
| 35 | + * Minimum value. |
| 36 | + */ |
| 37 | + min: number; |
| 38 | + |
| 39 | + /** |
| 40 | + * Range. |
| 41 | + */ |
| 42 | + range: number; |
| 43 | + |
| 44 | + /** |
| 45 | + * Mid-range. |
| 46 | + */ |
| 47 | + midrange: number; |
| 48 | + |
| 49 | + /** |
| 50 | + * Sum. |
| 51 | + */ |
| 52 | + sum: number; |
| 53 | + |
| 54 | + /** |
| 55 | + * Arithmetic mean. |
| 56 | + */ |
| 57 | + mean: number; |
| 58 | + |
| 59 | + /** |
| 60 | + * Unbiased sample variance. |
| 61 | + */ |
| 62 | + variance: number; |
| 63 | + |
| 64 | + /** |
| 65 | + * Corrected sample standard deviation. |
| 66 | + */ |
| 67 | + stdev: number; |
| 68 | + |
| 69 | + /** |
| 70 | + * Corrected sample skewness. |
| 71 | + */ |
| 72 | + skewness: number; |
| 73 | + |
| 74 | + /** |
| 75 | + * Corrected sample excess kurtosis. |
| 76 | + */ |
| 77 | + kurtosis: number; |
| 78 | +} |
| 79 | + |
| 80 | + |
| 81 | +/** |
| 82 | +* If provided a value, the accumulator function returns an updated summary; otherwise, the accumulator function returns the current summary. |
| 83 | +* |
| 84 | +* ## Notes |
| 85 | +* |
| 86 | +* - The returned summary is an object containing the following fields: |
| 87 | +* |
| 88 | +* - window: window size. |
| 89 | +* - max: maximum value. |
| 90 | +* - min: minimum value. |
| 91 | +* - range: range. |
| 92 | +* - midrange: mid-range. |
| 93 | +* - sum: sum. |
| 94 | +* - mean: arithmetic mean. |
| 95 | +* - variance: unbiased sample variance. |
| 96 | +* - stdev: corrected sample standard deviation. |
| 97 | +* - skewness: corrected sample skewness. |
| 98 | +* - kurtosis: corrected sample excess kurtosis. |
| 99 | +* |
| 100 | +* |
| 101 | +* @param x - value |
| 102 | +* @returns updated summary |
| 103 | +*/ |
| 104 | +type accumulator = ( x?: number ) => Summary | null; |
| 105 | + |
| 106 | +/** |
| 107 | +* Returns an accumulator function which incrementally computes a moving statistical summary. |
| 108 | +* |
| 109 | +* ## Notes |
| 110 | +* |
| 111 | +* - The `W` parameter defines the number of values over which to compute the moving statistical summary. |
| 112 | +* - If provided a value, the accumulator function returns an updated moving statistical summary. If not provided a value, the accumulator function returns the current moving statistical summary. |
| 113 | +* - As `W` values are needed to fill the window buffer, the first `W-1` returned summaries are calculated from smaller sample sizes. Until the window is full, each returned summary is calculated from all provided values. |
| 114 | +* |
| 115 | +* @param W - window size |
| 116 | +* @throws must provide a positive integer |
| 117 | +* @returns accumulator function |
| 118 | +* |
| 119 | +* @example |
| 120 | +* var accumulator = incrmsummary( 3 ); |
| 121 | +* |
| 122 | +* var summary = accumulator(); |
| 123 | +* // returns {} |
| 124 | +* |
| 125 | +* summary = accumulator( 2.0 ); |
| 126 | +* // returns {...} |
| 127 | +* |
| 128 | +* summary = accumulator( -5.0 ); |
| 129 | +* // returns {...} |
| 130 | +* |
| 131 | +* summary = accumulator(); |
| 132 | +* // returns {...} |
| 133 | +*/ |
| 134 | +declare function incrmsummary( W: number ): accumulator; |
| 135 | + |
| 136 | + |
| 137 | +// EXPORTS // |
| 138 | + |
| 139 | +export = incrmsummary; |
0 commit comments