跳转到内容
RailWise KB已发布

AI异常检测与预警工具

RailWise AI异常检测与预警工具基于统计学和机器学习算法,实时监测测量数据异常,自动判定预警等级,并提供智能处置建议。支持多种检测算法和灵活的预警规则配置。

复核 2026-07-09入门公开可引用RailWise 技术团队
ai-guide

AI异常检测与预警工具是 RailWise 提供的专业监测数据异常检测和预警系统,面向工程监测领域的工程师和技术人员。工具基于统计学和机器学习算法,能够实时监测测量数据异常,自动判定预警等级,并提供智能处置建议,帮助用户及时发现和处理潜在的安全风险。

场景 说明 检测重点
盾构施工监测 盾构穿越期间的变形监测 沉降加速、突变
桥梁健康监测 桥梁结构长期监测 趋势突变、周期性异常
基坑工程监测 基坑开挖期间的监测 支撑轴力突变、水位异常
隧道收敛监测 隧道断面变形监测 收敛速率异常
高边坡监测 边坡稳定性监测 位移加速、裂缝扩展
数据质量监控 测量数据质量监控 仪器故障、操作失误
项目 版本
AI异常检测与预警工具 2.5.0
Python 3.11+
Scikit-learn 1.4+
PyTorch 2.2+
Statsmodels 0.14+
Redis 7+

功能模块 说明 技术实现
实时异常检测 实时监测数据流异常 流式处理 + 在线检测
批量异常检测 历史数据异常检测 批量处理 + 离线检测
预警等级判定 自动判定预警等级 规则引擎 + 机器学习
智能处置建议 提供处置建议 知识图谱 + 规则库
预警通知 多渠道预警通知 消息队列 + 推送服务
预警升级 预警自动升级/降级 时间窗口 + 趋势分析
误报过滤 减少误报 多算法交叉验证
检测算法管理 算法选择、参数调优 算法库 + 配置中心
参数类型 检测维度 异常类型
垂直位移 累计值、变化速率 突变、加速、振荡
水平位移 X/Y方向、合位移 方向突变、速率异常
收敛 收敛量、收敛速率 收敛加速、收敛停滞
倾斜 倾斜度、倾斜方向 倾斜加速、方向突变
支撑轴力 轴力值、变化量 轴力突变、持续下降
地下水位 水位高程、变化速率 水位骤降、持续上升
裂缝 缝宽、开合速率 裂缝扩展、突变
温度 温度值、温差 温度异常影响

┌─────────────────────────────────────────────────────────────────────┐
│ AI异常检测与预警工具架构 │
├─────────────────────────────────────────────────────────────────────┤
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ 数据采集 │ │ 规则配置 │ │ 用户界面 │ │
│ │ - TSM API │ │ - 阈值规则 │ │ - Web界面 │ │
│ │ - 消息队列 │ │ - 算法配置 │ │ - 移动端 │ │
│ │ - 文件导入 │ │ - 通知配置 │ │ - API接口 │ │
│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
│ │ │ │ │
│ └──────────────────┼──────────────────┘ │
│ ▼ │
│ ┌──────────────────────────────┐ │
│ │ 异常检测引擎 │ │
│ │ 数据预处理 → 特征提取 → 检测 │ │
│ └──────────────┬───────────────┘ │
│ │ │
│ ┌───────────────────┼───────────────────┐ │
│ ▼ ▼ ▼ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ 统计检测层 │ │ 机器学习层 │ │ 深度学习层 │ │
│ │ - 3σ准则 │ │ - Isolation │ │ - LSTM │ │
│ │ - Grubbs │ │ Forest │ │ - Autoencoder│ │
│ │ - IQR │ │ - LOF │ │ - Transformer│ │
│ │ - CUSUM │ │ - One-Class │ │ - GAN │ │
│ │ - EWMA │ │ SVM │ │ │ │
│ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │
│ │ │ │ │
│ └──────────────────┼──────────────────┘ │
│ ▼ │
│ ┌──────────────────────────────┐ │
│ │ 预警判定引擎 │ │
│ │ 多算法融合 → 等级判定 → 建议 │ │
│ └──────────────┬───────────────┘ │
│ │ │
│ ┌──────────────┴───────────────┐ │
│ │ 通知与响应层 │ │
│ │ 邮件 / 短信 / App / 微信 / 钉钉 │ │
│ └──────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────┘

项目 最低要求 推荐配置
Python 3.11 3.12
内存 8 GB 32 GB
磁盘 2 GB 20 GB
GPU 可选 NVIDIA CUDA 12+
Redis 6 7
Terminal window
# 创建虚拟环境
python -m venv railwise-anomaly
source railwise-anomaly/bin/activate
# 安装异常检测工具
pip install railwise-anomaly
# 安装完整版(包含深度学习)
pip install "railwise-anomaly[deep-learning]"
# 验证安装
python -c "import railwise_anomaly; print(railwise_anomaly.__version__)"
Terminal window
# 核心依赖
pip install numpy pandas scikit-learn scipy
# 深度学习(可选)
pip install torch torchvision
# 实时处理
pip install redis celery
# 可视化
pip install matplotlib plotly

from railwise_anomaly import AnomalyDetector
# 创建检测器
detector = AnomalyDetector(
api_key="rw_anomaly_xxxxxxxx",
base_url="https://api.railwise.cn/v2",
config={
"algorithms": ["isolation_forest", "lstm", "grubbs"],
"confidence_threshold": 0.95,
"min_anomaly_duration": 2, # 至少连续2个异常点
"notification_channels": ["email", "app"]
}
)
# 配置实时检测
detector.configure_realtime(
project_id="proj_rw_2026_001",
point_ids=["P1", "P2", "P3", "P4", "P5"],
check_interval=60, # 每60秒检测一次
window_size=24 # 使用最近24个数据点
)
# 启动实时检测
detector.start_realtime()
# 注册回调函数
@detector.on_anomaly
def handle_anomaly(anomaly):
print(f"检测到异常!")
print(f" 测点: {anomaly.point_id}")
print(f" 时间: {anomaly.timestamp}")
print(f" 类型: {anomaly.type}")
print(f" 严重程度: {anomaly.severity}")
print(f" 置信度: {anomaly.confidence:.2%}")
print(f" 建议: {anomaly.recommendation}")
# 停止检测
# detector.stop_realtime()
# 历史数据异常检测
results = detector.detect_batch(
project_id="proj_rw_2026_001",
point_ids=["P1", "P2", "P3"],
date_range=("2026-07-01", "2026-07-08"),
algorithms=["isolation_forest", "grubbs", "lstm"],
voting="majority" # 多数投票
)
# 查看结果
for result in results:
print(f"测点 {result.point_id}:")
print(f" 异常数: {len(result.anomalies)}")
for anomaly in result.anomalies:
print(f" {anomaly.timestamp}: {anomaly.description}")
from railwise_anomaly import AlertClassifier
# 创建预警分类器
classifier = AlertClassifier(
thresholds={
"yellow": 5.0, # 黄色预警阈值
"orange": 10.0, # 橙色预警阈值
"red": 15.0 # 红色预警阈值
},
rate_thresholds={
"yellow": 2.0, # 黄色预警速率阈值 (mm/天)
"orange": 5.0,
"red": 10.0
}
)
# 判定预警等级
alert = classifier.classify(
point_id="P7",
cumulative_value=18.5, # 累计变形值
rate=8.5, # 变形速率 (mm/天)
acceleration=1.2 # 变形加速度
)
print(f"预警等级: {alert.level}") # red
print(f"预警原因: {alert.reason}")
print(f"建议措施: {alert.recommendations}")
from railwise_anomaly import NotificationManager
# 创建通知管理器
nm = NotificationManager()
# 配置通知渠道
nm.configure_channel("email", {
"smtp_server": "smtp.railwise.cn",
"from": "alerts@railwise.cn",
"to": ["engineer@railwise.cn", "manager@railwise.cn"]
})
nm.configure_channel("sms", {
"provider": "aliyun",
"template_code": "SMS_12345678",
"phone_numbers": ["138****1234"]
})
nm.configure_channel("app", {
"push_service": "firebase",
"topics": ["proj_rw_2026_001_alerts"]
})
# 发送预警通知
nm.send_alert(alert, channels=["email", "app"])

基于正态分布假设,超出均值±3倍标准差的数据视为异常。

from railwise_anomaly.algorithms import ThreeSigmaDetector
detector = ThreeSigmaDetector(
sigma_threshold=3.0,
window_size=30, # 滑动窗口大小
min_samples=10 # 最小样本数
)
anomalies = detector.detect(data)

适用场景: 数据量充足、近似正态分布的监测数据

优点: 简单直观,计算速度快 缺点: 对非正态分布数据效果差

用于检测单变量数据中的离群值。

from railwise_anomaly.algorithms import GrubbsDetector
detector = GrubbsDetector(
alpha=0.05, # 显著性水平
max_outliers=5 # 最多检测5个异常值
)
anomalies = detector.detect(data)

适用场景: 小样本数据的离群值检测

检测均值偏移的累积和控制图。

from railwise_anomaly.algorithms import CUSUMDetector
detector = CUSUMDetector(
target_mean=0.0, # 目标均值
threshold=5.0, # 累积和阈值
drift=0.5 # 允许漂移
)
anomalies = detector.detect(data)

适用场景: 检测微小的均值偏移

基于随机划分的异常检测算法,异常点更容易被孤立。

from railwise_anomaly.algorithms import IsolationForestDetector
detector = IsolationForestDetector(
n_estimators=100,
contamination=0.05, # 预期异常比例
max_samples=256,
random_state=42
)
# 训练
detector.fit(training_data)
# 检测
anomalies = detector.detect(data)

适用场景: 高维数据、复杂数据分布

优点: 对高维数据效果好,无需假设分布 缺点: 需要调参,对局部异常不敏感

基于局部密度的异常检测算法。

from railwise_anomaly.algorithms import LOFDetector
detector = LOFDetector(
n_neighbors=20,
contamination=0.05
)
anomalies = detector.detect(data)

适用场景: 局部密度差异明显的数据

使用LSTM自编码器检测时间序列异常。

from railwise_anomaly.algorithms import LSTMAutoencoderDetector
detector = LSTMAutoencoderDetector(
sequence_length=24, # 序列长度
hidden_size=64,
epochs=100,
threshold_method="percentile", # 阈值确定方法
threshold_percentile=95
)
# 训练
detector.fit(training_data)
# 检测
anomalies = detector.detect(data)

适用场景: 复杂时间序列模式

优点: 能捕捉复杂时序模式 缺点: 需要大量训练数据,计算资源要求高

基于Transformer架构的异常检测。

from railwise_anomaly.algorithms import TransformerDetector
detector = TransformerDetector(
d_model=128,
nhead=8,
num_layers=3,
sequence_length=48
)
detector.fit(training_data)
anomalies = detector.detect(data)

适用场景: 长序列依赖、复杂模式


alert_rules.yaml
project_id: "proj_rw_2026_001"
project_name: "绕城高速管廊工程1标段"
thresholds:
settlement:
yellow: 5.0 # mm
orange: 10.0
red: 15.0
displacement:
yellow: 5.0
orange: 10.0
red: 15.0
convergence:
yellow: 10.0
orange: 20.0
red: 30.0
tilt:
yellow: 2.0 # ‰
orange: 3.0
red: 5.0
rate_thresholds:
settlement:
yellow: 2.0 # mm/天
orange: 5.0
red: 10.0
displacement:
yellow: 2.0
orange: 5.0
red: 10.0
acceleration_thresholds:
settlement:
yellow: 0.5 # mm/天²
orange: 1.0
red: 2.0
# 预警升级规则
escalation_rules:
- condition: "yellow_count >= 3"
action: "escalate_to_orange"
- condition: "orange_duration >= 24h"
action: "escalate_to_red"
- condition: "red_count >= 1"
action: "immediate_notification"
# 通知规则
notification_rules:
yellow:
channels: ["app"]
recipients: ["project_team"]
delay: 0
orange:
channels: ["email", "app"]
recipients: ["project_team", "technical_director"]
delay: 0
red:
channels: ["email", "sms", "app"]
recipients: ["project_team", "technical_director", "general_manager"]
delay: 0
# 从文件加载规则
detector.load_rules("./alert_rules.yaml")
# 或动态配置规则
detector.configure_rules({
"thresholds": {
"settlement": {"yellow": 5.0, "orange": 10.0, "red": 15.0}
},
"notification": {
"red": {"channels": ["email", "sms"], "immediate": True}
}
})

from railwise_anomaly import StreamingDetector
# 创建流式检测器
stream = StreamingDetector(
detector=detector,
buffer_size=100, # 缓冲区大小
processing_interval=30 # 处理间隔(秒)
)
# 注册数据源
stream.register_source(
name="tsm_stream",
type="websocket",
url="wss://tsm.railwise.cn/stream",
api_key="rw_tsm_xxxxxxxx"
)
# 启动流式检测
stream.start()
# 监控统计
import time
while True:
stats = stream.get_stats()
print(f"处理数据点: {stats.processed_count}")
print(f"检测到异常: {stats.anomaly_count}")
print(f"当前预警: {stats.active_alerts}")
time.sleep(60)
from railwise_anomaly import EdgeDetector
# 创建边缘检测器(部署在本地设备)
edge = EdgeDetector(
model_path="./models/anomaly_model.onnx",
threshold=0.8,
device="cpu" # 或 "cuda"
)
# 本地检测
result = edge.detect(local_data)
# 仅上传异常结果到云端
if result.is_anomaly:
edge.upload_alert(result)

from railwise_tsm import TSMClient
from railwise_anomaly import AnomalyDetector
# 创建TSM客户端
tsm = TSMClient(
base_url="https://tsm.railwise.cn",
api_key="rw_tsm_xxxxxxxx"
)
# 创建检测器
detector = AnomalyDetector(tsm_client=tsm)
# 配置自动检测
detector.configure_auto_detect(
project_id="proj_rw_2026_001",
detect_interval=300, # 每5分钟检测
algorithms=["isolation_forest", "grubbs"],
auto_alert=True # 自动发送预警
)
# 启动自动检测
detector.start_auto_detect()
# 注册TSM回调
@detector.on_alert
def handle_tsm_alert(alert):
# 在TSM中创建预警记录
tsm.create_alert_record(
project_id=alert.project_id,
point_id=alert.point_id,
level=alert.level,
value=alert.value,
threshold=alert.threshold,
recommendation=alert.recommendation
)
# 更新测点状态
tsm.update_point_status(
point_id=alert.point_id,
status=alert.level
)

数据特点 推荐算法 说明
单变量、正态分布 3σ / Grubbs 简单高效
单变量、非正态 IQR / CUSUM 不依赖分布假设
多变量、高维 Isolation Forest 处理高维数据
局部密度差异 LOF 检测局部异常
复杂时序模式 LSTM 捕捉时序依赖
长序列依赖 Transformer 处理长序列
# 使用网格搜索调优
from sklearn.model_selection import GridSearchCV
param_grid = {
'n_estimators': [50, 100, 200],
'contamination': [0.01, 0.05, 0.1],
'max_samples': [128, 256, 512]
}
grid_search = GridSearchCV(
estimator=IsolationForestDetector(),
param_grid=param_grid,
scoring='f1',
cv=5
)
grid_search.fit(training_data)
print(f"最优参数: {grid_search.best_params_}")
  • 使用多算法交叉验证
  • 设置最小异常持续时间
  • 结合业务规则过滤
  • 定期回顾和调整阈值
# 多算法融合
detector = AnomalyDetector(
algorithms=["isolation_forest", "grubbs", "lstm"],
voting="majority", # 多数投票
min_agreement=2 # 至少2个算法同意
)
  • 使用增量学习更新模型
  • 对大数据集使用采样
  • 启用GPU加速(深度学习模型)
  • 使用Redis缓存中间结果

限制项 说明
训练数据 深度学习模型需要至少1000条历史数据
检测延迟 实时检测有30-60秒延迟
误报率 统计方法约5-10%,机器学习方法约2-5%
计算资源 LSTM/Transformer需要GPU加速
模型更新 建议每月重新训练模型
数据质量 异常检测效果受数据质量影响

注意: 异常检测结果需由工程师审核确认,避免误报导致不必要的应急响应。


根据数据特点选择:

  • 数据量小、简单分布 → 统计方法
  • 数据量大、复杂模式 → 机器学习方法
  • 时序依赖强 → 深度学习方法
  1. 提高阈值
  2. 增加最小异常持续时间
  3. 使用多算法交叉验证
  4. 检查数据质量
detector.configure(
threshold=0.9, # 提高阈值
min_duration=3, # 至少3个连续异常点
voting="unanimous" # 所有算法一致才报警
)
  1. 降低阈值
  2. 增加算法灵敏度
  3. 使用更多检测算法
  4. 检查训练数据是否包含类似异常模式
from railwise_anomaly.evaluation import evaluate_detector
metrics = evaluate_detector(
detector=detector,
test_data=test_data,
ground_truth=labels,
metrics=["precision", "recall", "f1", "auc_roc"]
)
print(f"精确率: {metrics.precision:.3f}")
print(f"召回率: {metrics.recall:.3f}")
print(f"F1分数: {metrics.f1:.3f}")
print(f"AUC-ROC: {metrics.auc_roc:.3f}")

版本 日期 变更内容
2.5.0 2026-07-08 新增Transformer检测器;优化实时检测性能;新增边缘检测模式
2.0.0 2026-04-20 新增LSTM检测器;支持流式检测;新增预警升级规则
1.5.0 2026-01-15 新增Isolation Forest和LOF;支持多算法融合
1.0.0 2025-10-10 初始版本发布;支持3σ、Grubbs、CUSUM等统计方法


技术支持: 如有疑问,请联系 RailWise 技术支持团队

引用与复核把知识带回真实工程判断

引用时保留页面与来源线索;涉及标准条文、阈值、频率和项目结论,请回到现行依据与责任人复核。

查看 Agent 使用规则