【LSTM分类】基于卷积神经网络结合双向长短时记忆CNN-Bi-LSTM实现数据分类含Matlab源码

0 阅读1分钟

cover_image

【LSTM分类】基于卷积神经网络结合双向长短时记忆CNN-Bi-LSTM实现数据分类含Matlab源码

天天Matlab 天天Matlab 天天Matlab

2023年02月21日 00:00 福建 __

在小说阅读器中沉浸阅读

✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

🍎个人主页:Matlab科研工作室

🍊个人信条:格物致知。

更多Matlab仿真内容点击👇

智能优化算法 神经网络预测 雷达通信 无线传感器 电力系统

信号处理 图像处理 路径规划 元胞自动机 无人机

⛄ 内容介绍

一种基于长短时记忆网络和卷积神经网络的文本分类方法,首先,利用词向量将输入文本进行向量表示,通过三层CNN提取文本的局部特征,进而整合出全文语义,同时,使用LSTM存储文本序列中历史信息的特征,以获取文本的上下文依赖关系,其次,将输入向量分别与各层CNN的输出相融合,缓解深层神经网络中层与层之间特征传递时出现的特征丢失问题.本发明适用于文本分类,具有运行效率高,运行时间短的优点,解决了传统分类技术在处理复杂抽象和上下文的强相关性文本时的缺陷.

⛄ 部分代码

% Max_iter: Maximum iterations, N: Populatoin size, Convergence_curve: Convergence curve

rand('seed',sum(100 * clock)); % Random number seed

z = 0.03; % Adjustable parameter

% Initialize the position of slime mould

lb = ones(1,dim).*lb; % Lower boundary

ub = ones(1,dim).*ub; % Upper boundary

X = initialization(N,dim,ub,lb); % It can be downloaded from github.com/Shihong-Yin

bestPositions = zeros(1,dim); % Optimal food source location

Destination_fitness = inf; % Change this to -inf for maximization problems

weight = ones(N,dim); % Fitness weight of each slime mould

Convergence_curve = zeros(1,Max_iter);

% Main loop

for it = 1:Max_iter

% Check the boundary and calculate the fitness

FU = X>ub; FL = X<lb; X = (X.*(~(FU+FL)))+ub.*FU+lb.*FL;

PopFitness = cec21_bias_shift_rot_func(X',func_num)'; % github.com/Shihong-Yin

% Sort the fitness thus update the bF and wF

[SmellOrder,SmellIndex] = sort(PopFitness); % Eq.(2.6)

bestFitness = SmellOrder(1);

worstFitness = SmellOrder(N);

S = bestFitness-worstFitness+eps; % Plus eps to avoid denominator zero

% Calculate the fitness weight of each slime mould

for i = 1:N

if i <= N/2 % Eq.(2.5)

weight(SmellIndex(i),:) = 1+rand(1,dim)*log10((bestFitness- SmellOrder(i))/S+1);

else

weight(SmellIndex(i),:) = 1-rand(1,dim)*log10((bestFitness- SmellOrder(i))/S+1);

end

end

% Update the best position and destination fitness

if bestFitness < Destination_fitness

bestPositions = X(SmellIndex(1),:);

Destination_fitness = bestFitness;

end

a = atanh(-(it/Max_iter)+1); % Eq.(2.4)

vb = unifrnd(-a,a,N,dim); % Eq.(2.3)

b = 1-it/Max_iter;

vc = unifrnd(-b,b,N,dim);

p = tanh(abs(PopFitness-Destination_fitness)); % Eq.(2.2)

r = rand(N,dim);

A = randi([1,N],N,dim); % Two positions randomly selected from population

B = randi([1,N],N,dim);

% Update the Position of search agents

for i = 1:N

if rand < z % Eq.(2.7)

X(i,:) = (ub-lb).*rand(1,dim)+lb; % The original code is (ub-lb)*rand+lb;

else

for j = 1:dim

if r(i,j) < p(i) % Eq.(2.1)

X(i,j) = bestPositions(j)+vb(i,j)*(weight(i,j)*X(A(i,j),j)-X(B(i,j),j));

else

X(i,j) = vc(i,j)*X(i,j);

end

end

end

end

Convergence_curve(it) = Destination_fitness;

end

end

⛄ 运行结果

⛄ 参考文献

[1]尹梓诺, 马海龙, 胡涛. 基于联合注意力机制和一维卷积神经网络-双向长短期记忆网络模型的流量异常检测方法[J]. 电子与信息学报, 2022, 44:1-10.

[2]陈悦, 杨柳, 李帅,等. 基于Softmax函数增强卷积神经网络—双向长短期记忆网络框架的交通拥堵预测算法[J]. 科学技术与工程, 2022, 22(29):10.

⛳️ 完整代码

❤️部分理论引用网络文献,若有侵权联系博主删除
❤️ 关注我领取海量matlab电子书和数学建模资料

预览时标签不可点

继续滑动看下一个

轻触阅读原文

天天Matlab

向上滑动看下一个

知道了

微信扫一扫
使用小程序


取消 允许


取消 允许


取消 允许

× 分析

__

跳转二维码

作者头像

微信扫一扫可打开此内容,
使用完整服务

: , , , , , , , , , , , , 。 视频 小程序 赞 ,轻点两下取消赞 在看 ,轻点两下取消在看 分享 留言 收藏 听过