Simulink中神经网络的初始化金宝app

3 views (last 30 days)
erfan hassani
erfan hassani 2021年6月15日
Edited: erfan hassani2021年6月15日
你好,
我正在尝试在Simulink建立神经网络以控制电动机。金宝app我使用MATLAB代码构建此系统,并且可以正常工作,但是当我想在Simulink中进行操作时,我不知道与其他人之间的分离是如何分开的。金宝app
我的意思是,在MATLAB代码中,I Wirte初始化代码,然后在“ for Loop”中开发了系统,因此该系统可与k样品一起使用。
But in simulink how should I seperate initialization from the rest of the code?
In below, there is a sample of my matlab function which I have problem with.
function[Uc,S] = fcn(Ec, Xc,Xc1,Xc2,Xc3,Ec1,S1, Ue)
d = Ue;
%err = ec;
k = r;
x = Xc;
b = 0.005;%这是网络培训率
% %神经网络初始化
n = 4;隐藏神经元数量的%
dim=4;输入神经元数量的%
wij = 0.05*rand(n,dim);%输入隐藏重量
W1j =0.05*rand(1,N);%hidden to output weights
%% neural network
为了j = 1:4
s(j)= tanh(wij(j,1)*xc + wij(j,2)*xc1 + wij(j,3)*xc2 + wij(j,4)*xc3);
结尾
% input layer
net1 = [Xc;Xc1;Xc2;Xc3];
O1 = Net1;
%隐藏室
net2 = Wij*O1;
O2 = [S(1),S(2),S(3),S(4)];
%output layer
net3 = w1j。*o2;
U = Net3(1,1)+ Net3(1,2)+ Net3(1,3)+ Net3(1,4);
%% updating weights
%更新W1J
sigma = sqrt(B)*Ec1 + d;
为了j = 1 :4
w1j_new(j)= sigma /(4*s1(j));
结尾
%Updating Wij
如果i == 1
为了j = 1:4
wij_new(j,1)= 1/(4*xc)*tanh(sigma/(4*w1j(1,j)));
结尾
Elseifi == 2
为了j = 1:4
Wij_new(j,2) = 1/(4*Xc1)*tanh(sigma/(4*W1j(1,j)));
结尾
Elseifi == 3
为了j = 1:4
Wij_new(j,3) = 1/(4*Xc2)*tanh(sigma/(4*W1j(1,j)));
结尾
Elseifi == 4
为了j = 1:4
wij_new(j,4)= 1/(4*xc3)*tanh(sigma/(4*w1j(1,j)));
结尾
结尾
wij = wij_new;
w1j = w1j_new(4,:,1);
uc = u;

答案(1)

大卫·威灵汉(David Willingham)
你好,
您是否想直接从Simulink培训NN模型?金宝app还是在simulink中运行预估计的模型?金宝app
我们看到的一个典型的工作流程是使用MATLAB首先训练您的神经网络。训练神经网络后,您可以使用来自神经网络工具箱的GenSim命令来导出网络以模拟和模拟它。金宝app有关GENSIM函数的更多信息,请参见以下URL:
1条评论
erfan hassani
erfan hassani 2021年6月15日
Thank you for answering me. I do not want to use NN Toolbox.
我将尝试更多地解释我的问题。
I'm using neural netwrok to tune PID parameters to do real time control. here is my simulink picture:
每个NNP,NNI和NND都是神经障碍:
As I said before, when I'm using matlab coding, I initialize my network and after that I use a for loop ( k= 1:length(t)) to tune my PID and use it for my PLANT.
但是我不知道何时使用Simulink,因为我没有循环,并且我想进行实时控制。金宝app
在诸如NNC或NNE之类的MATLAB函数中,我应该启动网络,然后每次信号出现时,都应更新WAIGHT和PID参数。
我的NNC代码在下面,我认为我应该使用“标志”第一次进行初始化(情况0),而不是每个信号。
function[Uc,S] = fcn(Ec, Xc,Xc1,Xc2,Xc3,Ec1,S1, Ue)
d = Ue;
%err = ec;
k = r;
x = Xc;
b = 0.005;%这是网络培训率
% %神经网络初始化
n = 4;隐藏神经元数量的%
dim=4;输入神经元数量的%
wij = 0.05*rand(n,dim);%输入隐藏重量
W1j =0.05*rand(1,N);%hidden to output weights
%% neural network
为了j = 1:4
s(j)= tanh(wij(j,1)*xc + wij(j,2)*xc1 + wij(j,3)*xc2 + wij(j,4)*xc3);
结尾
% input layer
net1 = [Xc;Xc1;Xc2;Xc3];
O1 = Net1;
%隐藏室
net2 = Wij*O1;
O2 = [S(1),S(2),S(3),S(4)];
%output layer
net3 = w1j。*o2;
U = Net3(1,1)+ Net3(1,2)+ Net3(1,3)+ Net3(1,4);
%% updating weights
%更新W1J
sigma = sqrt(B)*Ec1 + d;
为了j = 1 :4
w1j_new(j)= sigma /(4*s1(j));
结尾
%Updating Wij
如果i == 1
为了j = 1:4
wij_new(j,1)= 1/(4*xc)*atanh(sigma/(4*w1j(1,j)));
结尾
Elseifi == 2
为了j = 1:4
wij_new(j,2)= 1/(4*xc1)*atanh(sigma/(4*w1j(1,j)));
结尾
Elseifi == 3
为了j = 1:4
Wij_new(j,3) = 1/(4*Xc2)*atanh(sigma/(4*W1j(1,j)));
结尾
Elseifi == 4
为了j = 1:4
wij_new(j,4)= 1/(4*xc3)*atanh(sigma/(4*w1j(1,j)));
结尾
结尾
wij = wij_new;
w1j = w1j_new(4,:,1);
uc = u;

登录发表评论。

下载188bet金宝搏


Release

R2019b

社区寻宝

在Matlab Central中找到宝藏,发现社区如何为您提供帮助!

Start Hunting!