0

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

然后我保存 NN 的参数(高斯的中心和标准差,以及最终权重)并使用与之前相同的初始 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')
4

0 回答 0