aiwg
Version:
Deployment tool and support utility for AI context. Copies agents, skills, commands, rules, and behaviors into the paths each AI platform reads (Claude Code, Codex, Copilot, Cursor, Warp, OpenClaw, and 6 more) so one source of truth works across 10 platfo
186 lines • 5.61 kB
TypeScript
/**
* TrendAnalyzer - Statistical analysis for NFR trend detection
*
* Provides statistical methods for analyzing time-series data, detecting
* trends, outliers, change points, and forecasting future values.
*
* Features:
* - Moving average calculation (simple and exponential)
* - Outlier detection (IQR and Z-score methods)
* - Linear regression for trend lines
* - Simple forecasting using trend extrapolation
* - Change point detection using statistical tests
*
* @module testing/trend-analyzer
*/
/**
* Time-series data point
*/
export interface TimeSeriesPoint {
/** Timestamp (Unix milliseconds) */
timestamp: number;
/** Measured value */
value: number;
}
/**
* Time-series dataset
*/
export type TimeSeries = TimeSeriesPoint[];
/**
* Linear trend line (y = mx + b)
*/
export interface TrendLine {
/** Slope (change per unit time) */
slope: number;
/** Y-intercept */
intercept: number;
/** R-squared value (goodness of fit, 0-1) */
rSquared: number;
}
/**
* Forecast result with confidence
*/
export interface ForecastResult {
/** Predicted value */
value: number;
/** Lower bound of prediction interval */
lowerBound: number;
/** Upper bound of prediction interval */
upperBound: number;
/** Confidence level (0-1) */
confidence: number;
}
/**
* Change point detection result
*/
export interface ChangePoint {
/** Index in time series where change occurred */
index: number;
/** Timestamp of change point */
timestamp: number;
/** Mean before change */
meanBefore: number;
/** Mean after change */
meanAfter: number;
/** Statistical significance (p-value) */
significance: number;
}
/**
* Outlier detection method
*/
export type OutlierMethod = 'iqr' | 'zscore';
/**
* TrendAnalyzer - Statistical analysis for NFR trends
*
* @example
* ```typescript
* const analyzer = new TrendAnalyzer();
*
* // Calculate moving average
* const samples = [10, 12, 11, 13, 15, 14, 16];
* const smoothed = analyzer.calculateMovingAverage(samples, 3);
*
* // Detect outliers
* const outliers = analyzer.detectOutliers(samples, 'iqr');
*
* // Fit trend line
* const timeSeries = samples.map((v, i) => ({ timestamp: i * 1000, value: v }));
* const trend = analyzer.fitTrendLine(timeSeries);
* console.log(`Trend: ${trend.slope > 0 ? 'increasing' : 'decreasing'}`);
* ```
*/
export declare class TrendAnalyzer {
/**
* Calculate simple moving average
*
* @param samples - Array of values
* @param windowSize - Size of moving window
* @returns Array of moving averages (same length as input, padded with original values)
* @throws {Error} If windowSize is invalid
*/
calculateMovingAverage(samples: number[], windowSize: number): number[];
/**
* Calculate exponential moving average
*
* @param samples - Array of values
* @param alpha - Smoothing factor (0-1, higher = more weight on recent values)
* @returns Array of exponential moving averages
* @throws {Error} If alpha is out of range
*/
calculateExponentialMovingAverage(samples: number[], alpha?: number): number[];
/**
* Detect outliers using IQR or Z-score method
*
* @param samples - Array of values
* @param method - Detection method ('iqr' or 'zscore')
* @returns Boolean array indicating outliers (true = outlier)
* @throws {Error} If method is invalid
*/
detectOutliers(samples: number[], method?: OutlierMethod): boolean[];
/**
* Fit linear trend line to time series data
*
* Uses least squares regression to find best-fit line.
*
* @param data - Time series data points
* @returns Trend line parameters and R-squared
* @throws {Error} If insufficient data points
*/
fitTrendLine(data: TimeSeries): TrendLine;
/**
* Forecast future value using trend extrapolation
*
* Uses linear regression trend line to predict future value.
*
* @param data - Historical time series data
* @param horizon - Number of time units into future (milliseconds)
* @returns Forecast with prediction interval
* @throws {Error} If insufficient data or invalid horizon
*/
forecastValue(data: TimeSeries, horizon: number): ForecastResult;
/**
* Detect change point in time series
*
* Uses a sliding window approach to find significant shifts in mean.
*
* @param data - Time series data
* @param minSegmentSize - Minimum size of segments before/after change point
* @returns Change point if detected, null otherwise
*/
detectChangePoint(data: TimeSeries, minSegmentSize?: number): ChangePoint | null;
/**
* Calculate standard deviation of samples
*
* @param samples - Array of values
* @returns Standard deviation
*/
private calculateStdDev;
/**
* Calculate mean of samples
*
* @param samples - Array of values
* @returns Mean value
*/
private calculateMean;
/**
* Calculate percentile from sorted values
*
* @param sortedValues - Pre-sorted array of values
* @param percentile - Percentile to calculate (0-100)
* @returns Percentile value
*/
private calculatePercentile;
/**
* Detect outliers using IQR method
*
* @private
*/
private detectOutliersIQR;
/**
* Detect outliers using Z-score method
*
* @private
*/
private detectOutliersZScore;
}
//# sourceMappingURL=trend-analyzer.d.ts.map