跳转至

ADR-006:GNN 增强的 CSI 模式识别

状态

已在 ADR-023 中部分实现;并由 ADR-027 扩展

注意: ADR-023 在 COCO 骨架图上实现了一个 2 层 GCN,用于空间推理。ADR-027(MERIDIAN)通过梯度反转层添加域对抗正则化,迫使 GCN 学习环境不变图特征,从而摆脱房间特定的多径模式。

日期

2026-02-28

背景

ADR-004 引入了基于 HNSW 的相似性搜索,用于 CSI 模式匹配。虽然 HNSW 提供了快速的最近邻检索,但它将每个向量独立处理。然而,CSI 模式具有丰富的关系结构:

  1. 时间邻接性:相隔 10ms 捕获的 CSI 帧比相隔 10s 的帧更相关。序列模式揭示了运动轨迹。

  2. 空间相关性:由于频率接近,相邻子载波上的 CSI 读数高度相关。天线对捕获不同的空间视角。

  3. 跨会话相似性:周二的“走向厨房”模式应有助于周三的识别,但环境基线可能已经变化。

  4. 多人纠缠:当存在多个人时,CSI 模式是叠加的。解纠缠需要理解哪些模式片段共同出现。

标准 HNSW 无法捕获这些关系。每个查询仅基于向量距离返回邻居,忽略了模式之间如何相互关联的图结构。

RuVector 的 GNN 增强

RuVector 实现了一个位于 HNSW 索引之上的图神经网络层:

Standard HNSW: Query → Distance-based neighbors → Results
GNN-Enhanced:  Query → Distance-based neighbors → GNN refinement → Improved results

该 GNN 在 <1ms 内执行三个操作: 1. 消息传递:每个节点从其 HNSW 邻居聚合信息 2. 注意力加权:多头注意力识别哪些邻居对当前查询上下文最相关 3. 表示更新:节点嵌入基于邻域上下文进行细化

此外,时间学习跟踪查询序列以发现: - 在会话中经常一起出现的向量 - 时间顺序模式(A 通常先于 B) - 改变相关性排名的会话上下文

决策

我们将集成 RuVector 的 GNN 层,以三种核心能力增强 CSI 模式识别:关系搜索、时间序列建模和多人解纠缠。

用于 CSI 的 GNN 架构

┌─────────────────────────────────────────────────────────────────────┐
│                 GNN-Enhanced CSI Pattern Graph                       │
├─────────────────────────────────────────────────────────────────────┤
│                                                                      │
│  Layer 1: HNSW Spatial Graph                                        │
│  ┌───────────────────────────────────────────────────────┐          │
│  │  Nodes = CSI feature vectors                          │          │
│  │  Edges = HNSW neighbor connections (distance-based)   │          │
│  │  Node features = [amplitude | phase | doppler | PSD]  │          │
│  └───────────────────────────────────────────────────────┘          │
│                          │                                           │
│                          ▼                                           │
│  Layer 2: Temporal Edges                                            │
│  ┌───────────────────────────────────────────────────────┐          │
│  │  Additional edges between temporally adjacent vectors  │          │
│  │  Edge weight = 1/Δt (closer in time = stronger)       │          │
│  │  Direction = causal (past → future)                    │          │
│  └───────────────────────────────────────────────────────┘          │
│                          │                                           │
│                          ▼                                           │
│  Layer 3: GNN Message Passing (2 rounds)                            │
│  ┌───────────────────────────────────────────────────────┐          │
│  │  Round 1: h_i = σ(W₁·h_i + Σⱼ α_ij · W₂·h_j)       │          │
│  │  Round 2: h_i = σ(W₃·h_i + Σⱼ α'_ij · W₄·h_j)      │          │
│  │  α_ij = softmax(LeakyReLU(a^T[W·h_i || W·h_j]))     │          │
│  │  (Graph Attention Network mechanism)                   │          │
│  └───────────────────────────────────────────────────────┘          │
│                          │                                           │
│                          ▼                                           │
│  Layer 4: Refined Representations                                   │
│  ┌───────────────────────────────────────────────────────┐          │
│  │  Updated vectors incorporate neighborhood context      │          │
│  │  Re-rank search results using refined distances       │          │
│  └───────────────────────────────────────────────────────┘          │
└─────────────────────────────────────────────────────────────────────┘

三种集成模式

模式 1:查询时细化(默认)

GNN 在检索后细化 HNSW 结果。不修改已存储的向量。

pub struct GnnQueryRefiner {
    /// GNN weights (small: ~50K parameters)
    gnn_weights: GnnModel,

    /// Number of message passing rounds
    num_rounds: usize,  // 2

    /// Attention heads for neighbor weighting
    num_heads: usize,  // 4

    /// How many HNSW neighbors to consider in GNN
    neighborhood_size: usize,  // 20 (retrieve 20, GNN selects best 5)
}

impl GnnQueryRefiner {
    /// Refine HNSW results using graph context
    pub fn refine(&self, query: &[f32], hnsw_results: &[SearchResult]) -> Vec<SearchResult> {
        // Build local subgraph from query + HNSW results
        let subgraph = self.build_local_subgraph(query, hnsw_results);

        // Run message passing
        let refined = self.message_pass(&subgraph, self.num_rounds);

        // Re-rank based on refined representations
        self.rerank(query, &refined)
    }
}

延迟:在 HNSW 搜索基础上增加 +0.2ms(100K 向量的总延迟 <1.5ms)。

模式 2:时间序列识别

跟踪 CSI 向量序列,以识别跨越多个帧的活动模式:

/// Temporal pattern recognizer using GNN edges
pub struct TemporalPatternRecognizer {
    /// Sliding window of recent query vectors
    window: VecDeque<TimestampedVector>,

    /// Maximum window size (in frames)
    max_window: usize,  // 100 (10 seconds at 10 Hz)

    /// Temporal edge decay factor
    decay: f64,  // 0.95 (edges weaken with time)

    /// Known activity sequences (learned from data)
    activity_templates: HashMap<String, Vec<Vec<f32>>>,
}

impl TemporalPatternRecognizer {
    /// Feed new CSI vector and check for activity pattern matches
    pub fn observe(&mut self, vector: &[f32], timestamp: f64) -> Vec<ActivityMatch> {
        self.window.push_back(TimestampedVector { vector: vector.to_vec(), timestamp });

        // Build temporal subgraph from window
        let temporal_graph = self.build_temporal_graph();

        // GNN aggregates temporal context
        let sequence_embedding = self.gnn_aggregate(&temporal_graph);

        // Match against known activity templates
        self.match_activities(&sequence_embedding)
    }
}

可检测的活动模式:

活动 所需帧数 CSI 特征
行走 10-30 周期性多普勒振荡
跌倒 5-15 尖锐幅度尖峰 → 静止
坐下 10-20 反射高度逐渐下降
呼吸(静止) 30-100 微周期性相位变化
手势(挥手) 5-15 局部高频幅度变化

模式 3:多人解耦

当存在 N>1 个人时,CSI 是叠加信号。GNN 学习对模式片段进行聚类:

/// Multi-person CSI disentanglement using GNN clustering
pub struct MultiPersonDisentangler {
    /// Maximum expected simultaneous persons
    max_persons: usize,  // 10

    /// GNN-based spectral clustering
    cluster_gnn: GnnModel,

    /// Per-person tracking state
    person_tracks: Vec<PersonTrack>,
}

impl MultiPersonDisentangler {
    /// Separate CSI features into per-person components
    pub fn disentangle(&mut self, features: &CsiFeatures) -> Vec<PersonFeatures> {
        // Decompose CSI into subcarrier groups using GNN attention
        let subcarrier_graph = self.build_subcarrier_graph(features);

        // GNN clusters subcarriers by person contribution
        let clusters = self.cluster_gnn.cluster(&subcarrier_graph, self.max_persons);

        // Extract per-person features from clustered subcarriers
        clusters.iter().map(|c| self.extract_person_features(features, c)).collect()
    }
}

GNN 学习循环

GNN 通过 RuVector 内置学习机制在每次查询中不断改进:

Query → HNSW retrieval → GNN refinement → User action (click/confirm/reject)
                                              │
                                              ▼
                                    Update GNN weights via:
                                    1. Positive: confirmed results get higher attention
                                    2. Negative: rejected results get lower attention
                                    3. Temporal: successful sequences reinforce edges

对于 WiFi-DensePose,“用户操作”被替换为: - 时间一致性:如果第 N+1 帧确认了第 N 帧的检测,则强化 - 多 AP 一致性:如果两个 AP 对检测达成一致,则同时强化两者 - 物理合理性:如果姿态满足骨骼约束,则强化

性能预算

组件 参数 内存 延迟(每次查询)
GNN 权重(2 层,4 头) 52K 208 KB 0.15 ms
时间图(100 帧窗口) N/A ~130 KB 0.05 ms
多人聚类 18K 72 KB 0.3 ms
GNN 总开销 70K 410 KB 0.5 ms

影响

积极影响

  • 上下文感知搜索:结果考虑时间和空间关系,而不仅仅是向量距离
  • 活动识别:时间 GNN 支持序列级模式匹配
  • 多人支持:GNN 聚类可分离重叠的 CSI 模式
  • 自我改进:每次查询都提供学习信号以优化注意力权重
  • 轻量级:70K 参数,410 KB 内存,0.5ms 延迟开销

负面影响

  • 需要训练数据:GNN 权重需要在 CSI 模式图上进行初始训练
  • 复杂性:三种模式增加了测试和调试范围
  • 图维护:必须修剪时间边以防止无界增长
  • 近似性:用于多人的 GNN 聚类是近似的;可能错误地合并/拆分

与其他 ADR 的交互

  • ADR-004(HNSW):GNN 在 HNSW 图结构上运行;依赖 HNSW 可用
  • ADR-005(SONA):GNN 权重可通过 SONA LoRA 进行环境特定调优
  • ADR-003(RVF):GNN 权重与推理权重一起存储在模型容器中
  • ADR-010(Witness):GNN 权重更新记录在见证链中

参考资料

本页原文 Markdown:在 AtomGit 查看·内容源自开源项目 wi/RuView