基于时序卷积与判别性字典学习的齿轮箱变工况故障诊断【附代码】
✨ 本团队擅长数据搜集与处理、建模仿真、程序设计、仿真代码、EI、SCI写作与指导毕业论文、期刊论文经验交流。✅ 专业定制毕设、代码✅如需沟通交流查看文章底部二维码1时序空洞卷积金字塔与多尺度感受野齿轮箱在不同转速和负载下故障冲击间隔变化剧烈固定感受野的卷积难以同时覆盖高速下的密集冲击和低速下的稀疏冲击。提出一种时序空洞卷积金字塔包含四个并行分支空洞率分别为1、2、4、8每个分支均由因果卷积实现保证仅利用过去信息适用于在线诊断。四个分支的输出通过可学习权重融合权重由当前信号的频谱质心网络动态生成实现感受野自适应调整。此外在每个空洞卷积后加入批归一化和Swish激活函数。在齿轮箱故障数据集5种故障类型转速范围300-1800rpm上该金字塔结构使跨转速诊断准确率达到93.6%比固定空洞率模型高出11.2%。2判别性字典学习与稀疏编码鲁棒性增强为了进一步提升变工况下的特征稳定性在卷积特征提取后引入基于判别性字典学习的稀疏编码层。该层包含一个过完备字典矩阵将每个样本的特征投影到稀疏系数上然后通过字典原子的类别标签约束稀疏系数使得同类样本的稀疏模式相似。训练时同时更新字典和编码器参数并加入稀疏正则化和字典相干性惩罚。在测试时直接计算稀疏系数作为新的特征表示。该字典学习层对工况变化引起的特征漂移有抑制作用实验表明加入字典后转速迁移任务中准确率提升了7.8%。3元迁移学习与快速适应新齿轮箱不同齿轮箱之间由于结构和尺寸差异直接迁移诊断模型效果较差。采用模型无关元学习框架在多个源齿轮箱上训练模型使其在新齿轮箱上只需少量样本即可快速适应。元训练时每个任务来自不同齿轮箱的部分数据内循环用支持集更新模型参数外循环用查询集计算元损失。同时将字典学习层的字典原子作为跨任务共享的基元而分类器参数作为任务特定参数。在新齿轮箱数据上每类仅需5个样本微调5步即可达到92.1%的准确率而从头训练需要每类50个样本才能达到同等精度。import torch import torch.nn as nn import torch.nn.functional as F class DilatedPyramid(nn.Module): def __init__(self, in_c, out_c, dilations[1,2,4,8]): super().__init__() self.convs nn.ModuleList() for d in dilations: padding d * (3-1) // 2 self.convs.append(nn.Conv1d(in_c, out_c, 3, dilationd, paddingpadding)) self.gate nn.Sequential(nn.AdaptiveAvgPool1d(1), nn.Flatten(), nn.Linear(in_c, len(dilations)), nn.Softmax(dim-1)) def forward(self, x): B, C, L x.shape w self.gate(x.mean(dim2, keepdimTrue).squeeze(2)).unsqueeze(-1) outs [] for i, conv in enumerate(self.convs): out F.swish(conv(x)) outs.append(out * w[:, i:i1]) return sum(outs) class DiscriminativeDictionary(nn.Module): def __init__(self, input_dim, dict_size64, sparsity3): super().__init__() self.dict nn.Parameter(torch.randn(dict_size, input_dim)) self.sparsity sparsity def forward(self, x): # x: [B, D] # 计算稀疏系数近似L0 sim F.linear(x, self.dict) # [B, dict_size] topk_vals, topk_idx torch.topk(sim, self.sparsity, dim-1) sparse_codes torch.zeros_like(sim) sparse_codes.scatter_(1, topk_idx, topk_vals) return sparse_codes def dictionary_coherence_loss(dict_matrix): # 减小冗余 gram torch.matmul(dict_matrix, dict_matrix.T) off_diag gram - torch.diag_embed(torch.diag(gram)) return torch.norm(off_diag, pfro) / dict_matrix.size(0) def maml_inner_loop(model, support_x, support_y, inner_lr0.01, steps1): fast_weights {name: param.clone() for name, param in model.named_parameters()} for _ in range(steps): logits model.functional_forward(support_x, fast_weights) loss F.cross_entropy(logits, support_y) grads torch.autograd.grad(loss, fast_weights.values(), create_graphTrue) for (name, param), grad in zip(fast_weights.items(), grads): fast_weights[name] param - inner_lr * grad return fast_weights def maml_outer_loss(model, query_x, query_y, fast_weights): logits model.functional_forward(query_x, fast_weights) return F.cross_entropy(logits, query_y)如有问题可以直接沟通