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

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

🍊个人信条:格物致知。

⛄ 内容介绍

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

MATLAB实现CNN-BiLSTM卷积双向长短期记忆神经网络数据分类预测_卷积神经网络

MATLAB实现CNN-BiLSTM卷积双向长短期记忆神经网络数据分类预测_卷积神经网络_02

MATLAB实现CNN-BiLSTM卷积双向长短期记忆神经网络数据分类预测_卷积神经网络_03

MATLAB实现CNN-BiLSTM卷积双向长短期记忆神经网络数据分类预测_卷积神经网络_04

MATLAB实现CNN-BiLSTM卷积双向长短期记忆神经网络数据分类预测_卷积神经网络_05

MATLAB实现CNN-BiLSTM卷积双向长短期记忆神经网络数据分类预测_github_06

MATLAB实现CNN-BiLSTM卷积双向长短期记忆神经网络数据分类预测_github_07

⛄ 部分代码

% 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:///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:///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

⛄ 运行结果

MATLAB实现CNN-BiLSTM卷积双向长短期记忆神经网络数据分类预测_卷积神经网络_08

⛄ 参考文献

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

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

⛳️ 完整代码

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