模块更新于 2026-11-21· 浏览 4· 下载 0
HOCA 高阶调控上下文
从稳定教师表征学习潜在超边关联,经池化、残差混合和回分配,构造超出记录邻域的上下文。它是训练期辅助视图,不新增已观察调控边,也不直接给出因果关系。
结构图

从稳定教师表征学习潜在超边关联,经池化、残差混合和回分配,构造超出记录邻域的上下文。它是训练期辅助视图,不新增已观察调控边,也不直接给出因果关系。
论文信息
- 论文:GRASP: Adaptive Context with Regulatory Partner Supervision for GRN Inference
核心痛点
参考调控图不完整,局部消息传递和删边视图无法越过原有拓扑;仅对齐同一基因也未充分利用已知调控伙伴。
模块亮点
- 从稳定教师表征学习潜在超边关联,经池化、残差混合和回分配,构造超出记录邻域的上下文。它是训练期辅助视图,不新增已观察调控边,也不直接给出因果关系。
适用场景
单细胞表达与部分参考监督下的调控链接排序,其他任务需单独验证。完整框架还需要伙伴对比与有方向的解码器。
插入位置建议
- 放在停止梯度的教师基因嵌入之后、跨视图对比之前。保持基因顺序一致,由外部管理教师冻结和动量更新,并将验证测试基因对的两个方向都隔离于训练图。
适用任务
- 单细胞表达与部分参考监督下的调控链接排序
- 其他任务需单独验证。完整框架还需要伙伴对比与有方向的解码器
完整代码
hoca.py
"""HigherOrderContextAggregation —— GRASP 的高阶上下文聚合模块。
论文:GRASP: Adaptive Context with Regulatory Partner Supervision for GRN Inference (ICLR 2027)。
问题:单细胞转录组上有监督基因调控网络推断时,消息传递只能沿参考图已有边传播,参考拓扑不完整,
局部上下文有界。方法:用稳定的教师基因表征经 W 学习 K 个潜在超边关联 S,把基因池化为超边表征 U,
经 Lh 层残差混合作跨超边信息交互,再由 S 把上下文重新分配到基因,得到超出已记录邻域的高阶表征。
本模块即该映射 F(Z),可插拔地补足任意图编码器的局部上下文。
"""
import sys
import torch
import torch.nn as nn
import torch.nn.functional as F
class HigherOrderContextAggregation(nn.Module):
"""Latent-hyperedge higher-order context: Z -> Zh (Eq. 2-4).
S = Z W (N x K gene-hyperedge association)
U0 = S^T Z (K x d pooled hyperedge states)
U_l+1 = U_l + rho(R_l U_l + b_l 1_d^T) (Lh residual mixings)
Zh = rho(S U_Lh) (N x d redistributed context)
"""
def __init__(self, dim: int, num_hyperedges: int = 32, num_layers: int = 2,
negative_slope: float = 0.2):
super().__init__()
if dim <= 0 or num_hyperedges <= 0 or num_layers <= 0:
raise ValueError("dim, num_hyperedges and num_layers must be positive")
self.dim = dim
self.num_hyperedges = num_hyperedges
self.num_layers = num_layers
self.negative_slope = negative_slope
# W in R^{d x K}: gene -> latent hyperedge association, no bias per Eq. (2)
self.assoc = nn.Linear(dim, num_hyperedges, bias=False)
# R_l in R^{K x K} and b_l in R^{K} for every residual mapping of Eq. (3)
self.mix_weights = nn.ParameterList(
[nn.Parameter(torch.empty(num_hyperedges, num_hyperedges)) for _ in range(num_layers)]
)
self.mix_bias = nn.ParameterList(
[nn.Parameter(torch.zeros(num_hyperedges)) for _ in range(num_layers)]
)
for r in self.mix_weights:
nn.init.xavier_uniform_(r)
def forward(self, z: torch.Tensor, return_hyperedges: bool = False):
"""z: (N, d) or (B, N, d) teacher gene representations (stop-grad upstream).
Returns Zh with the same leading shape and last dim d; optionally the
final hyperedge states U of shape (K, d) / (B, K, d).
"""
squeeze = z.dim() == 2
if squeeze:
z = z.unsqueeze(0) # (1, N, d)
if z.dim() != 3:
raise ValueError(f"expected (N, d) or (B, N, d), got {tuple(z.shape)}")
b, n, d = z.shape
if d != self.dim:
raise ValueError(f"expected feature dim {self.dim}, got {d}")
s = self.assoc(z) # (B, N, K) association weights
# Context pooling: U0 = S^T Z -> (B, K, d)
u = torch.einsum("bnk,bnd->bkd", s, z)
for r, bias in zip(self.mix_weights, self.mix_bias):
# Higher-order interaction across hyperedges: U += rho(R U + b 1_d^T)
mixed = torch.einsum("kj,bjd->bkd", r, u) + bias.view(1, -1, 1)
u = u + F.leaky_relu(mixed, self.negative_slope)
# Context redistribution back to genes: Zh = rho(S U) -> (B, N, d)
zh = F.leaky_relu(torch.einsum("bnk,bkd->bnd", s, u), self.negative_slope)
if squeeze:
zh, u = zh.squeeze(0), u.squeeze(0)
return (zh, u) if return_hyperedges else zh
if __name__ == "__main__":
sys.stdout.reconfigure(encoding="utf-8")
torch.manual_seed(0)
dim, num_genes, batch = 16, 24, 3
module = HigherOrderContextAggregation(dim=dim, num_hyperedges=8, num_layers=2)
z_batch = torch.randn(batch, num_genes, dim) # (B, N, d)
zh_batch = module(z_batch)
print(f"input z: {tuple(z_batch.shape)} -> output zh: {tuple(zh_batch.shape)}")
z_single = torch.randn(num_genes, dim) # (N, d)
zh_single, u_single = module(z_single, return_hyperedges=True)
print(f"input z: {tuple(z_single.shape)} -> output zh: {tuple(zh_single.shape)}, "
f"hyperedges U: {tuple(u_single.shape)}")
# permutation equivariance sanity check (Theorem 1(i))
perm = torch.randperm(num_genes)
err = (module(z_single[perm]) - zh_single[perm]).abs().max().item()
print(f"permutation equivariance max error: {err:.2e}")
assert zh_batch.shape == (batch, num_genes, dim)
assert torch.isfinite(zh_batch).all() and torch.isfinite(zh_single).all()
assert err < 1e-5
print("shape check passed")
环境与依赖
Python 3.9+
继续浏览
下一篇IFAdapter 实例特征控制在扩散交叉注意力中注入实例级外观 token 与实例语义图,按边界框控制每个实例的细粒度特征。相关资源
模块2026-11-20
ContraNorm 对比归一化层
对抗维度崩溃:把对比学习的均匀性损失搬到表示本身,一步梯度展开得到前向公式:x 减去 scale × softmax(相似度)x 再接 LayerNorm,把挤在一起的表示"撑开",能提升表示的方差与有效秩
Transformer图神经网络ContraNorm
图神经网络MIT
模块2026-11-20
EFIGNN 显式特征交互感知图神经网络
显式学任意阶交互:每层做无激活函数的图卷积聚合邻居信息,再哈达玛乘上 1 阶特征之和,交互阶数随层数递增,2 层学 2 阶、4 层学 4 阶
图神经网络EFIGNN特征交互
图神经网络MIT
模块2026-11-20
GCKM 图卷积核机器
卷积套核函数:每层先用归一化邻接矩阵做邻居聚合,再用高斯核把特征隐式映射到高维空间,后续逐层只在核矩阵上递归计算
图神经网络GCKM核方法
图神经网络MIT