网页开发与网站开发做一个app软件大概需要多少钱
2026/6/20 1:51:42 网站建设 项目流程
网页开发与网站开发,做一个app软件大概需要多少钱,js网站效果,网站开发 报刊✅ 博主简介#xff1a;擅长数据搜集与处理、建模仿真、程序设计、仿真代码、论文写作与指导#xff0c;毕业论文、期刊论文经验交流。 ✅成品或者定制#xff0c;扫描文章底部微信二维码。 (1) 无监督时频对比预训练的特征表示学习框架 针对工业现场轴承故障标注样本稀缺而…✅博主简介擅长数据搜集与处理、建模仿真、程序设计、仿真代码、论文写作与指导毕业论文、期刊论文经验交流。✅成品或者定制扫描文章底部微信二维码。(1) 无监督时频对比预训练的特征表示学习框架针对工业现场轴承故障标注样本稀缺而无标签运行数据充足的现状,本研究构建基于对比学习的自监督预训练策略充分挖掘未标注数据的特征表达价值。时频对比学习通过构造正负样本对引导模型学习判别性特征表示,将原始振动时序信号同时转换为时域波形和频域频谱作为双视图输入,对同一信号源的时频表示视为正样本对,不同信号源的表示视为负样本对。编码器网络采用孪生结构分别处理时域和频域输入,通过共享权重的卷积层提取局部特征,全局平均池化层生成紧凑的嵌入向量。对比损失函数基于InfoNCE准则设计,最大化正样本对在特征空间的相似度同时推开负样本对,促使模型学习与故障模式相关的不变特征而忽略噪声和工况变化带来的干扰。为增强样本多样性,设计针对振动信号的数据增强策略,包括时域随机裁剪、幅值缩放、高斯噪声注入和频域随机掩码,通过对同一信号应用不同增强操作生成多个视图构成正样本对。预训练阶段在大规模无标签数据集上进行,编码器通过对比学习目标优化参数,学习到的特征表示能够捕获轴承运行状态的本质特征。微调阶段将预训练编码器作为特征提取器,仅在少量标注样本上训练轻量级分类头,通过迁移预训练知识快速适应特定故障诊断任务,显著降低对标注数据的依赖。(2) 时频信息深度融合的Transformer原型网络架构考虑到时域和频域信息分别反映轴承故障的不同侧面,本研究设计多模态融合网络实现时频特征的互补增强。时域分支采用倒置残差卷积结构处理原始振动信号,通过深度可分离卷积降低参数量,扩张卷积层增大感受野捕获长距离时序依赖,批归一化和ReLU激活函数增强非线性表达能力。频域分支对短时傅里叶变换得到的时频谱进行处理,利用二维卷积提取频率分布模式和时频局部纹理特征。提取的时频特征分别输入Transformer编码器进行全局上下文建模,通过多头自注意力机制捕获特征序列的长距离依赖关系,前馈网络进一步提升特征的抽象层次。为实现时频特征的深度交互,设计交叉注意力融合模块,将时域特征作为查询向量,频域特征作为键值向量进行注意力计算,使时域特征能够选择性地关注频域中的判别性成分,反之亦然。融合后的多模态特征进入原型分类网络,通过计算查询样本与各类别原型中心的距离进行分类。原型中心定义为支持集中同类样本嵌入向量的均值,分类决策基于欧氏距离或余弦相似度进行最近邻匹配。针对小样本场景下原型估计不稳定的问题,引入原型分布平衡正则化,通过最小化类间原型分布的KL散度促使各类别原型在特征空间均匀分布,避免某些类别的原型过度聚集导致分类偏差。训练采用episode采样策略,每个episode从训练集中随机抽取N个类别,每类K个支持样本和Q个查询样本,模拟真实小样本测试场景。(3) 跨工况泛化的元学习与领域适应联合优化针对轴承在不同转速和负载工况下振动特性差异导致的诊断性能下降问题,本研究结合元学习和领域适应技术提升模型的跨工况泛化能力。元学习通过在多个源工况任务上进行二阶优化,学习对新工况快速适应的初始化参数,使模型能够仅用少量目标工况样本实现高精度诊断。任务级训练将不同工况下的故障诊断视为不同任务,每个任务包含支持集和查询集,模型在支持集上进行内循环更新,在查询集上计算元损失进行外循环优化,通过任务间梯度聚合学习任务无关的通用表示。为进一步缩小源域和目标域的分布差异,引入领域适应模块对齐特征分布,采用最大均值差异准则度量两个分布的距离,通过最小化MMD损失促使特征提取器生成领域不变表示。设计自适应权重调整机制动态平衡分类损失和领域对齐损失,在训练初期侧重特征提取能力的提升,后期逐步增强领域对齐约束。import numpy as np import torch import torch.nn as nn import torch.nn.functional as F from scipy.fftpack import fft from sklearn.preprocessing import StandardScaler class TimeFrequencyEncoder(nn.Module): def __init__(self, signal_length1024, embedding_dim128): super(TimeFrequencyEncoder, self).__init__() self.time_encoder nn.Sequential( nn.Conv1d(1, 32, kernel_size64, stride8), nn.BatchNorm1d(32), nn.ReLU(), nn.Conv1d(32, 64, kernel_size16, stride4), nn.BatchNorm1d(64), nn.ReLU(), nn.AdaptiveAvgPool1d(1) ) self.freq_encoder nn.Sequential( nn.Conv1d(1, 32, kernel_size64, stride8), nn.BatchNorm1d(32), nn.ReLU(), nn.Conv1d(32, 64, kernel_size16, stride4), nn.BatchNorm1d(64), nn.ReLU(), nn.AdaptiveAvgPool1d(1) ) self.projection nn.Sequential( nn.Linear(128, embedding_dim), nn.ReLU(), nn.Linear(embedding_dim, embedding_dim) ) def forward(self, time_signal, freq_signal): time_feat self.time_encoder(time_signal).squeeze(-1) freq_feat self.freq_encoder(freq_signal).squeeze(-1) combined torch.cat([time_feat, freq_feat], dim1) embedding self.projection(combined) return F.normalize(embedding, dim1) class ContrastiveLoss(nn.Module): def __init__(self, temperature0.5): super(ContrastiveLoss, self).__init__() self.temperature temperature def forward(self, embeddings, labels): batch_size embeddings.size(0) similarity_matrix torch.matmul(embeddings, embeddings.T) / self.temperature mask torch.eye(batch_size, deviceembeddings.device).bool() similarity_matrix.masked_fill_(mask, -1e9) labels labels.unsqueeze(1) label_mask (labels labels.T).float() label_mask.masked_fill_(mask, 0) positives similarity_matrix * label_mask negatives similarity_matrix * (1 - label_mask) pos_exp torch.exp(positives).sum(dim1) all_exp torch.exp(similarity_matrix).sum(dim1) loss -torch.log(pos_exp / (all_exp 1e-8) 1e-8) return loss.mean() class InvertedResidualBlock(nn.Module): def __init__(self, in_channels, out_channels, expand_ratio6): super(InvertedResidualBlock, self).__init__() hidden_dim in_channels * expand_ratio self.use_residual in_channels out_channels self.conv nn.Sequential( nn.Conv1d(in_channels, hidden_dim, 1, biasFalse), nn.BatchNorm1d(hidden_dim), nn.ReLU6(inplaceTrue), nn.Conv1d(hidden_dim, hidden_dim, 3, padding1, groupshidden_dim, biasFalse), nn.BatchNorm1d(hidden_dim), nn.ReLU6(inplaceTrue), nn.Conv1d(hidden_dim, out_channels, 1, biasFalse), nn.BatchNorm1d(out_channels) ) def forward(self, x): if self.use_residual: return x self.conv(x) return self.conv(x) class CrossAttentionFusion(nn.Module): def __init__(self, dim, num_heads4): super(CrossAttentionFusion, self).__init__() self.num_heads num_heads self.scale (dim // num_heads) ** -0.5 self.q_proj nn.Linear(dim, dim) self.k_proj nn.Linear(dim, dim) self.v_proj nn.Linear(dim, dim) self.out_proj nn.Linear(dim, dim) def forward(self, x1, x2): batch_size, seq_len, dim x1.size() q self.q_proj(x1).view(batch_size, seq_len, self.num_heads, -1).transpose(1, 2) k self.k_proj(x2).view(batch_size, -1, self.num_heads, dim // self.num_heads).transpose(1, 2) v self.v_proj(x2).view(batch_size, -1, self.num_heads, dim // self.num_heads).transpose(1, 2) attn torch.matmul(q, k.transpose(-2, -1)) * self.scale attn F.softmax(attn, dim-1) out torch.matmul(attn, v) out out.transpose(1, 2).contiguous().view(batch_size, seq_len, dim) out self.out_proj(out) return out class PrototypicalNetwork(nn.Module): def __init__(self, input_dim128, hidden_dim256): super(PrototypicalNetwork, self).__init__() self.time_branch nn.Sequential( InvertedResidualBlock(1, 32), InvertedResidualBlock(32, 64), nn.AdaptiveAvgPool1d(16) ) encoder_layer nn.TransformerEncoderLayer(d_model64, nhead4, dim_feedforward256, batch_firstTrue) self.transformer nn.TransformerEncoder(encoder_layer, num_layers3) self.cross_attn CrossAttentionFusion(64, num_heads4) self.fc nn.Sequential( nn.Linear(64 * 16, hidden_dim), nn.ReLU(), nn.Dropout(0.3), nn.Linear(hidden_dim, input_dim) ) def forward(self, x): batch_size x.size(0) x self.time_branch(x) x x.transpose(1, 2) x self.transformer(x) x_fusion self.cross_attn(x, x) x (x x_fusion).view(batch_size, -1) x self.fc(x) return x def compute_prototypes(self, support_embeddings, support_labels, num_classes): prototypes [] for c in range(num_classes): mask support_labels c class_embeddings support_embeddings[mask] prototype class_embeddings.mean(dim0) prototypes.append(prototype) return torch.stack(prototypes) def classify(self, query_embeddings, prototypes): distances torch.cdist(query_embeddings, prototypes) return -distances def euclidean_distance(x, y): return torch.cdist(x, y) def prototype_regularization(prototypes): num_prototypes prototypes.size(0) pairwise_dist euclidean_distance(prototypes, prototypes) mask torch.eye(num_prototypes, deviceprototypes.device).bool() pairwise_dist.masked_fill_(mask, 1e9) min_dist pairwise_dist.min(dim1)[0] reg_loss -torch.log(min_dist 1e-8).mean() return reg_loss def generate_bearing_data(num_samples1000, signal_length1024): X_time [] X_freq [] y [] for i in range(num_samples): fault_type np.random.randint(0, 5) t np.linspace(0, 1, signal_length) if fault_type 0: signal np.sin(2 * np.pi * 50 * t) 0.2 * np.random.randn(signal_length) elif fault_type 1: signal np.sin(2 * np.pi * 80 * t) 0.5 * np.sin(2 * np.pi * 200 * t) impulse_locs np.random.randint(0, signal_length, 5) signal[impulse_locs] np.random.randn(5) * 2.0 elif fault_type 2: signal np.sin(2 * np.pi * 120 * t) 0.3 * np.sin(2 * np.pi * 300 * t) else: freq 50 fault_type * 30 signal np.sin(2 * np.pi * freq * t) 0.3 * np.random.randn(signal_length) freq_signal np.abs(fft(signal))[:signal_length//2] freq_signal np.pad(freq_signal, (0, signal_length - len(freq_signal))) X_time.append(signal) X_freq.append(freq_signal) y.append(fault_type) X_time np.array(X_time)[:, np.newaxis, :] X_freq np.array(X_freq)[:, np.newaxis, :] y np.array(y) return X_time.astype(np.float32), X_freq.astype(np.float32), y X_time, X_freq, y generate_bearing_data(800) encoder TimeFrequencyEncoder(signal_length1024, embedding_dim128) contrastive_loss ContrastiveLoss(temperature0.5) time_tensor torch.FloatTensor(X_time) freq_tensor torch.FloatTensor(X_freq) label_tensor torch.LongTensor(y) optimizer torch.optim.Adam(encoder.parameters(), lr0.001) encoder.train() for epoch in range(30): optimizer.zero_grad() embeddings encoder(time_tensor, freq_tensor) loss contrastive_loss(embeddings, label_tensor) loss.backward() optimizer.step() if (epoch 1) % 10 0: print(fEpoch {epoch1}: Contrastive Loss{loss.item():.4f}) proto_net PrototypicalNetwork(input_dim128, hidden_dim256) optimizer_proto torch.optim.Adam(proto_net.parameters(), lr0.0005) num_classes 5 num_support 5 num_query 10 proto_net.train() for episode in range(100): support_indices [] query_indices [] for c in range(num_classes): class_indices np.where(y c)[0] selected np.random.choice(class_indices, num_support num_query, replaceFalse) support_indices.extend(selected[:num_support]) query_indices.extend(selected[num_support:]) support_x time_tensor[support_indices] support_y label_tensor[support_indices] query_x time_tensor[query_indices] query_y label_tensor[query_indices] support_embeddings proto_net(support_x) query_embeddings proto_net(query_x) prototypes proto_net.compute_prototypes(support_embeddings, support_y, num_classes) logits proto_net.classify(query_embeddings, prototypes) classification_loss F.cross_entropy(logits, query_y) reg_loss prototype_regularization(prototypes) total_loss classification_loss 0.1 * reg_loss optimizer_proto.zero_grad() total_loss.backward() optimizer_proto.step() if (episode 1) % 20 0: print(fEpisode {episode1}: Loss{total_loss.item():.4f}) proto_net.eval() with torch.no_grad(): test_embeddings proto_net(time_tensor[:100]) test_labels label_tensor[:100] prototypes proto_net.compute_prototypes(test_embeddings, test_labels, num_classes) predictions proto_net.classify(test_embeddings, prototypes).argmax(dim1) accuracy (predictions test_labels).float().mean() print(fTest Accuracy: {accuracy.item() * 100:.2f}%)如有问题可以直接沟通

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询