Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 奇怪的结果是用神经网络逼近函数_Matlab_Neural Network_Function Approximation - Fatal编程技术网

Matlab 奇怪的结果是用神经网络逼近函数

Matlab 奇怪的结果是用神经网络逼近函数,matlab,neural-network,function-approximation,Matlab,Neural Network,Function Approximation,我试图用RBF神经网络近似一个函数(微分方程的右侧),其形式为ddx=F(x,dx,u)(其中x,dx,u是标量,u是常数)。我将函数F作为一个黑匣子(我可以用初始x、dx和u输入它,并在我想要的时间跨度内取x和dx),在训练期间(使用sigma修改),我得到以下响应,绘制实际dx与近似dx 然后我保存NN的参数(高斯的中心和STD,以及最终权重),并使用与之前相同的初始x、dx和u执行模拟,当然,这次保持权重稳定。但我得到了下面的情节 这合乎逻辑吗?我错过什么了吗 培训代码如下: %load

我试图用RBF神经网络近似一个函数(微分方程的右侧),其形式为ddx=F(x,dx,u)(其中x,dx,u是标量,u是常数)。我将函数F作为一个黑匣子(我可以用初始x、dx和u输入它,并在我想要的时间跨度内取x和dx),在训练期间(使用sigma修改),我得到以下响应,绘制实际dx与近似dx

然后我保存NN的参数(高斯的中心和STD,以及最终权重),并使用与之前相同的初始x、dx和u执行模拟,当然,这次保持权重稳定。但我得到了下面的情节

这合乎逻辑吗?我错过什么了吗

培训代码如下:

%load the results I got from the real function
load sim_data t p pd dp %p is x,dp is dx and pd is u
real_states = [p,dp];

%down and upper limits of the variables
p_dl = 0;
p_ul = 2;
v_dl = -1;
v_ul = 4;
pd_dl = 0;%pd is constant each time,but the function should work for different pds
pd_ul = 2;

%number of gaussians
nc = 15;

x = p_dl:(p_ul-p_dl)/(nc-1):p_ul;

dx = v_dl:(v_ul-v_dl)/(nc-1):v_ul;

pdx = pd_dl:(pd_ul-pd_dl)/(nc-1):pd_ul;

%centers of gaussians
Cx = combvec(x,dx,pdx);

%stds of the gaussians
B = ones(1,3)./[2.5*(p_ul-p_dl)/(nc-1),2.5*(v_ul-v_dl)/(nc-1),2.5*(pd_ul-pd_dl)/(nc-1)];


nw = size(Cx,2);
wdx = zeros(nw,1);

state = real_states(1,[1,4]);%there are also y,dy,dz and z in real_states (ignored here)
states = zeros(length(t),2);
timestep = 0.005;

for step=1:length(t)
    states(step,:) = state;
    %compute the values of the sigmoids
    Sx = exp(-1/2 * sum(((([real_states(step,1);real_states(step,4);pd(1)]*ones(1,nw))'-Cx').*(ones(nw,1)*B)).^2,2));

    ddx = -530*state(2) + wdx'*Sx;
    edx = state(2) - real_states(step,4);
    dwdx = -1200*edx * Sx - 4 * wdx;
    wdx = wdx + dwdx*timestep;

    state = [state(1)+state(2)*timestep,state(2)+ddx*timestep];
end

save weights wdx Cx B

figure
plot(t,[dp(:,1),states(:,2)])
legend('x_d_o_t','x_d_o_t_h_a_t')
用于验证近似值的代码如下所示:

load sim_data t p pd dp
real_states = [p,dp];

load weights wdx Cx B
nw = size(Cx,2);
state = real_states(1,[1,4]);
states = zeros(length(t),2);
timestep = 0.005;

for step=1:length(t)
    states(step,:) = state;
    Sx = exp(-1/2 * sum(((([real_states(step,1);real_states(step,4);pd(1)]*ones(1,nw))'-Cx').*(ones(nw,1)*B)).^2,2));
    ddx = -530*state(2) + wdx'*Sx;
    state = [state(1)+state(2)*timestep,state(2)+ddx*timestep];
end

figure
plot(t,[dp(:,1),states(:,2)])
legend('x_d_o_t','x_d_o_t_h_a_t')

你遗漏了一些东西,你的代码!如果你不告诉我们你做了什么,谁能发现你的错误。对不起,我现在添加了代码,这是一条非常有用的评论:根据TeX的语法,你可以使用
legend('x_{dot}','x_{dothat}')
在图例中留出一堆下划线。另外:我不熟悉NNs,但是如果您将绘图的
ylim
截断为一个合理的小值,可能会有所帮助。错误曲线的形状可能会提供一些额外的信息:目前唯一清楚的是它正在发散。