/** * Lightweight ML functions for process mining, powered by micro-ml. * * All functions are async (micro-ml uses WASM initialization). * No heavy dependencies — no sklearn, no ONNX, no TensorFlow. * * Usage: * ```ts * import { predictRemainingTime, clusterTraces, detectAnomalies } from "./predictive.js"; * * const remaining = await predictRemainingTime(log); * const clusters = await clusterTraces(log, { k: 3 }); * const anomalies = await detectAnomalies(log); * ``` */ import type { EventLog } from "./types.js"; /** Result of remaining time prediction for a single case. */ export interface RemainingTimePrediction { case_id: string; event_index: number; predicted_remaining_ms: number; actual_remaining_ms?: number; } /** Result of trend analysis on a numeric series. */ export interface TrendResult { direction: "up" | "down" | "flat"; slope: number; strength: number; r_squared: number; forecast: number[]; } /** Result of next-activity prediction for a single case. */ export interface NextActivityPrediction { case_id: string; event_index: number; predicted_activity: string; confidence: number; } /** Cluster assignment for a trace. */ export interface TraceCluster { case_id: string; cluster: number; is_noise: boolean; } /** Clustering result with metadata. */ export interface ClusteringResult { clusters: TraceCluster[]; n_clusters: number; n_noise: number; centroids: number[][]; inertia: number; } /** Anomaly detection result. */ export interface AnomalyResult { case_ids: string[]; normal_ids: string[]; n_anomalies: number; n_clusters: number; } /** Seasonality detection result. */ export interface SeasonalityResult { period: number; strength: number; trend: number[]; seasonal: number[]; residual: number[]; } /** Feature vector for a single trace (used internally). */ export interface TraceFeatures { case_id: string; features: number[]; } /** * Predict remaining case time using linear regression on trace position. * * For each event in each trace, predicts the total remaining case duration * based on how far through the trace the event is (event_index / trace_length). * * Mirrors `pm4py.predict_case_remaining_time()` (lightweight version). * * @returns Predictions with case_id, event_index, predicted remaining ms, and actual remaining ms. */ export declare function predictRemainingTime(log: EventLog): Promise; /** * Predict the next activity using a decision tree classifier. * * Features: [trace_length_so_far, activity_index, position_fraction]. * Target: index of the actual next activity. * * Mirrors `pm4py.predict_next_activity()` (lightweight version). * * @returns Predictions with predicted activity and confidence score. */ export declare function predictNextActivity(log: EventLog): Promise; /** * Cluster traces by their feature profiles using k-means. * * Mirrors `pm4py.cluster_log()` (lightweight version). * * @param log Event log to cluster. * @param options.k Number of clusters (default 3). * @returns Cluster assignments with centroids and inertia. */ export declare function clusterTraces(log: EventLog, options?: { k?: number; }): Promise; /** * Detect anomalous traces using DBSCAN density-based clustering. * * Traces not assigned to any cluster are flagged as anomalies. * * Mirrors a lightweight version of pm4py's outlier detection. * * @param log Event log to analyze. * @param options.eps DBSCAN neighborhood radius (default 0.5). * @param options.minPoints Minimum points for a cluster (default 2). * @returns Anomaly detection result with flagged case IDs. */ export declare function detectAnomalies(log: EventLog, options?: { eps?: number; minPoints?: number; }): Promise; /** * Analyze the trend of case durations over time. * * Uses linear regression on case durations sorted by arrival time. * * @returns Trend direction, slope, strength (r-squared), and forecast values. */ export declare function analyzeDurationTrend(log: EventLog, forecastPeriods?: number): Promise; /** * Forecast future case arrival rate. * * Uses trend forecast on case arrival counts per time bucket. * * @param log Event log. * @param periods Number of future periods to forecast. * @returns Trend result with forecast values. */ export declare function forecastCaseArrival(log: EventLog, periods?: number): Promise; /** * Smooth a numeric series using exponential moving average. * * Useful for smoothing fitness trends, arrival rates, or other time-series metrics. * * @param data Numeric series to smooth. * @param window Smoothing window size (default 5). * @returns Smoothed series. */ export declare function smoothSeries(data: number[], window?: number, method?: "ema" | "sma"): Promise; /** * Find peaks (local maxima) in a numeric series. * * Useful for detecting sudden spikes in process metrics (e.g., case duration outliers). * * @param data Numeric series. * @returns Indices of peak values. */ export declare function findMetricPeaks(data: number[]): Promise; /** * Find troughs (local minima) in a numeric series. * * @param data Numeric series. * @returns Indices of trough values. */ export declare function findMetricTroughs(data: number[]): Promise; /** * Detect seasonality in case arrival rates. * * @param log Event log. * @returns Period and strength of detected seasonal pattern. */ export declare function detectArrivalSeasonality(log: EventLog): Promise; /** * Compute rate of change (percentage change) for a numeric series. * * Useful for monitoring drift in fitness scores, case durations, etc. * * @param data Numeric series. * @param periods Number of periods to look back (default 1). * @returns Rate of change values. */ export declare function computeRateOfChange(data: number[], periods?: number): Promise; //# sourceMappingURL=predictive.d.ts.map