function [kernel_c1,kernel_c2,weight_c2,weight_full_1,weight_full_2,weight_arr2num]=CNN_upweight(Error,train_data,state_c1,state_s1,state_c2,state_s2_temp1,state_s2_temp2,state_s2,...
state_f1,state_f2,kernel_c1,kernel_c2,weight_c2,weight_full_1,weight_full_2,weight_arr2num,yita,state_c2_temp1)
%%% 完成参数更新,权值和卷积核
%% 结点数目
layer_f2_num=size(state_f2,2);
layer_f1_num=size(state_f1,2);
layer_c2_num=size(state_c2,3);
layer_c1_num=size(state_c1,3);
[c2_row,c2_col,~]=size(state_c2);
[c1_row,c1_col,~]=size(state_c1);
[s2_row,s2_col,~]=size(state_s2_temp1);
[kernel_row,kernel_col]=size(kernel_c1(:,:,1));
%% 保存网络权值
weight_full_2_temp=weight_full_2;
weight_full_1_temp=weight_full_1;
weight_arr2num_temp=weight_arr2num;
kernel_c2_temp=kernel_c2;
kernel_c1_temp=kernel_c1;
weight_c2_temp=weight_c2;
%% 更新weight_full_2
for n=1:layer_f2_num
delta_weight_full_2_temp(:,n)=2*Error(1,n)*state_f1';
end
size(delta_weight_full_2_temp);
weight_full_2_temp=weight_full_2_temp-yita*delta_weight_full_2_temp;
%% 更新weight_full_1
for n=1:layer_f2_num
for m=1:layer_f1_num
delta_weight_full_1_temp(:,m)=2*Error(1,n)*weight_full_2(m,n)*state_s2';
end
weight_full_1_temp=weight_full_1_temp-yita*delta_weight_full_1_temp;
end
%% 更新weight_arr2num
for m=1:layer_c2_num
for n=1:layer_f2_num
count_delta_weight_arr2num_temp=zeros(s2_row,s2_col);
for k=1:layer_f1_num
delta_weight_arr2num_temp(:,:,m)=2*Error(1,n)*weight_full_1(m,k)*weight_full_2(k,n)*exp(-state_s2_temp2(1,m))/(1+exp(-state_s2_temp2(1,m))).^2*state_s2_temp1(:,:,m);
count_delta_weight_arr2num_temp=count_delta_weight_arr2num_temp+delta_weight_arr2num_temp(:,:,m);
end
weight_arr2num_temp(:,:,m)=weight_arr2num_temp(:,:,m)-yita*count_delta_weight_arr2num_temp;
end
end
%% 更新kernel_c2
for m=1:layer_c2_num
for n=1:layer_f2_num
count_delta_state_s2_temp1=zeros(s2_row,s2_col);
for k=1:layer_f1_num
delta_state_s2_temp1(:,:,m)=2*Error(1,n)*weight_full_1(m,k)*weight_full_2(k,n)*exp(-state_s2_temp2(1,m))/(1+exp(-state_s2_temp2(1,m))).^2*weight_arr2num(:,:,m);
count_delta_state_s2_temp1=count_delta_state_s2_temp1+delta_state_s2_temp1(:,:,m);
end
delta_state_c2=kron(count_delta_state_s2_temp1,ones(2,2)/4);
count=zeros(kernel_row,kernel_col);
for k_row=1:c2_row
for k_col=1:c2_col
count=count+state_c2_temp1(k_row:k_row+kernel_row-1,k_col:k_col+kernel_col-1)*delta_state_c2(k_row,k_col);
end
end
kernel_c2_temp(:,:,m)=kernel_c2_temp(:,:,m)-yita*count;
end
end
%% 更新 weight_c2
for n=1:layer_f2_num
for m=1:layer_c2_num
count_delta_state_s2_temp1=zeros(s2_row,s2_col);
for kk=1:layer_f1_num
delta_state_s2_temp1(:,:,m)=2*Error(1,n)*weight_full_1(m,kk)*weight_full_2(kk,n)*exp(-state_s2_temp2(1,m))/(1+exp(-state_s2_temp2(1,m))).^2*weight_arr2num(:,:,m);
count_delta_state_s2_temp1=count_delta_state_s2_temp1+delta_state_s2_temp1(:,:,m);
end
delta_state_c2=kron(count_delta_state_s2_temp1,ones(2,2)/4);
delta_state_c2_temp1(:,:,m)=conv2(delta_state_c2,kernel_c2(:,:,m),'full');
for k=1:layer_c1_num
delta_weight_c2_temp(k,m)=sum(sum(delta_state_c2_temp1(:,:,m).*state_s1(:,:,k)));
end
end
weight_c2_temp=weight_c2_temp-yita*delta_weight_c2_temp;
end
%% 更新 kernel_c1
for n=1:layer_f2_num
for m=1:layer_c2_num
count_delta_state_s2_temp1=zeros(s2_row,s2_col);
for kk=1:layer_f1_num
delta_state_s2_temp1(:,:,m)=2*Error(1,n)*weight_full_1(m,kk)*weight_full_2(kk,n)*exp(-state_s2_temp2(1,m))/(1+exp(-state_s2_temp2(1,m))).^2*weight_arr2num(:,:,m);
count_delta_state_s2_temp1=count_delta_state_s2_temp1+delta_state_s2_temp1(:,:,m);
end
delta_state_c2=kron(count_delta_state_s2_temp1,ones(2,2)/4);
delta_state_c2_temp1(:,:,m)=conv2(delta_state_c2,kernel_c2(:,:,m),'full');
end
for k=1:layer_c1_num
[x,y,~]=size(state_c2_temp1);
count1=zeros(x,y);
for m=1:layer_c2_num
count_temp=weight_c2(k,m)*delta_state_c2_temp1(:,:,m);
count1=count1+count_temp;
end
delta_state_s1(:,:,k)=count1;
delta_state_c1(:,:,k)=kron(delta_state_s1(:,:,k),ones(2,2)/4);
%
count2=zeros(kernel_row,kernel_col);
for k_row=1:c1_row
for k_col=1:c1_col
count=count+train_data(k_row:k_row+kernel_row-1,k_col:k_col+kernel_col-1)*delta_state_c1(k_row,k_col,k);
end
end
kernel_c1_temp(:,:,k)=kernel_c1_temp(:,:,k)-yita*count;
end
end
%% 权值更新
weight_c2=weight_c2_temp;
kernel_c1=kernel_c1_temp;
kernel_c2=kernel_c2_temp;
weight_arr2num=weight_arr2num_temp;
weight_full_2=weight_full_2_temp;
weight_full_1=weight_full_1_temp;
end

依邻依伴
- 粉丝: 3073
- 资源: 249
最新资源
- 管家婆辉煌食品版TOP+12.71.zip
- 基于COMSOL的电弧磁流体多场耦合仿真模型:电弧放电与MHD模拟分离过程研究,COMSOL电弧磁流体动网格仿真模型:电弧放电与多场耦合模拟分离过程研究,COMSOL电弧磁流体仿真模型,电弧放电仿真
- struts2ognl说明
- 企业FPGA AHB verilog全套IP源代码:ic设计验证与soc开发的学习宝库,企业FPGA AHB verilog全套源代码解析与应用级实现,学习IC设计与SOC开发的宝藏资源,企业大厂应用
- 自适应动态协议驱动的线性多智能体系统分布式一致性优化策略,线性多智能体系统的自适应动态协议分布式一致性技术研究,具有自适应动态协议的线性多智能体系统分布式一致性 ,核心关键词:自适应动态协议;线性多智
- Screenshot_2025-02-19-13-41-21-257_net.csdn.csdnplus.jpg
- 管家婆辉煌食品版TOP+12.81.zip
- 管家婆辉煌食品版TOP+12.91.zip
- 管家婆辉煌食品版TOP+13.1.zip
- 基于MATLAB的路径规划算法改进:人工势场法解决目标不可达问题详解,内含对比展示图集,改进人工势场法解决Matlab路径规划中的目标不可达问题:从斥力到引力势场的改进展示,matlab路径规划算法
- 双馈电机模型下的高效预测控制技术,双馈电机模型精准预测控制技术:策略、方法与实现,双馈电机模型预测控制 ,双馈电机; 模型预测控制; 控制系统设计; 电机控制技术,双馈电机模型预测控制技术
- 批量将视频ts格式转换为mp4格式的软件
- 最小领导者数分配问题在非线性多智能体有向网络一致性中的重要性探究,非线性多智能体有向网络一致性领导者数分配策略优化研究,非线性多智能体有向网络一致性的最小领导者数分配 ,最小领导者数分配;非线性多智能
- gradle-8.12-bin.zip
- 管家婆辉煌食品版TOP+13.22.zip
- 永磁直驱式风力发电系统Simulink仿真模型:直驱风机与光伏并网综合研究,直驱风机Simulink仿真模型与永磁直驱风力发电系统整体Matlab/Simulink分析-含2018-2021不同版本
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


