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

✅作者简介:热爱科研的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 https://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)'; % https://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电子书和数学建模资料

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研助手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值