带时滞的神经网络代码%% 具有模糊逻辑和惯性项的复值神经网络固定时间同步 (一范数控制器)
% 基于论文: Novel Results on Fixed-Time Complex Projective Lag Synchronization for Fuzzy Complex-Valued Neural Networks With Inertial Item
% 作者: YU YAO, JING HAN, GUODONG ZHANG, JUNHAO HU
%% 参数初始化
clear all; clc;
close all;
% ========== 系统参数 ==========
n = 2; % 神经元数量
dt = 0.001; % 时间步长
tau = 1; % 时滞 (τ)
gamma = 2; % 滞后常数 (γ)
t_start = -max(tau, gamma); % 起始时间 (考虑时滞和滞后)
t_end = 20; % 结束时间
t_vec = t_start:dt:t_end;
num_steps = length(t_vec);
% 系统参数 (来自论文Page 9)
alpha = [1.4; 2]; % α_i
epsilon = [2; 1.4]; % ε_i
xi = epsilon - 1; % ξ_i = ε_i - 1
h_param = alpha - xi; % h_i = α_i - ξ_i
% 连接权重矩阵 (Table 1)
partial = [1.5+2.6i, -2.0+1.7i; % ∂_{iρ}
1.2+0.6i, 1.0-1.5i];
hbar = [ 2.5+1.5i, 1.0-1.2i; % hbar_{iρ}
-1.7-2.7i, -2.4-1.6i];
s = [0.4-1.0i, -2.0-0.3i; % s_{iρ} (模糊AND模板)
1.5-1.6i, 1.1-1.6i];
wbar = [0.2-2.5i, 2.0-1.4i; % ϖ_{iρ} (模糊OR模板)
0.5-1.6i, 2.8+0.6i];
r = ones(2,2); % r_{iρ} (模糊MIN模板, 论文设为1)
delta = ones(2,2); % δ_{iρ} (模糊MAX模板, 论文设为1)
d = zeros(2,2); % d_{iρ} (论文设为0)
H_input = [1; 1]; % H_ρ(t) 外部输入
% 激活函数 (论文Page 9)
activation = @(u) tanh(real(u)) + 1i*tanh(imag(u));
% ========== 控制器参数 (论文Page 10) ==========
m = 3 + 1i; % 投影因子
beta_val = 1.6; % 指数参数 (Φ)
zeta1 = [25.6; 29.1]; % ζ_{1i}
zeta2 = [15.0; 0.7]; % ζ_{2i}
zeta3 = [0.05; 0.05]; % ζ_{3i}
phi = [65.0, 80.0; % φ_{iρ} (满足条件 φ_iρ > (|h̄_iρ| + |s_iρ| + |ϖ_iρ|)M_ρ)
64.4, 80.5];
T1f = 6.35; % 理论同步时间
% ========== 初始化状态变量 ==========
% 驱动系统 (λ, v)
lambda = zeros(n, num_steps); % λ_i(t)
v_drive = zeros(n, num_steps); % v_i(t) = dλ_i/dt + λ_i
% 响应系统 (κ, w)
kappa = zeros(n, num_steps); % κ_i(t)
w_resp = zeros(n, num_steps); % w_i(t) = dκ_i/dt + κ_i
% 误差系统
Sigma = zeros(n, num_steps); % Σ_i(t) = κ_i(t) - m*λ_i(t-γ)
Theta = zeros(n, num_steps); % Θ_i(t) = w_i(t) - m*v_i(t-γ)
% ========== 设置初始条件 (修正版) ==========
% 找到历史区间索引 (t ≤ 0)
idx_hist = find(t_vec <= 0);
% 驱动系统初始化 (整个历史区间)
lambda(1, idx_hist) = 5.8 + 1.7i; % φ_1(t)
lambda(2, idx_hist) = -2.5 - 1.4i; % φ_2(t)
v_drive(1, idx_hist) = 7.9 + 0.3i; % ψ_1(t)
v_drive(2, idx_hist) = -4.3 - 0.4i; % ψ_2(t)
% 响应系统初始化
kappa(1, idx_hist) = 3.3 + 1.1i;
kappa(2, idx_hist) = -8.0 - 1.2i;
w_resp(1, idx_hist) = 6.0 - 1.8i;
w_resp(2, idx_hist) = -1.0 + 1.3i;
% 初始化误差系统 (整个历史区间)
for k = idx_hist
% 计算 t - γ 时刻的索引
t_gamma = t_vec(k) - gamma;
[~, idx_g] = min(abs(t_vec - t_gamma));
% 计算误差
Sigma(1, k) = kappa(1, k) - m * lambda(1, idx_g);
Sigma(2, k) = kappa(2, k) - m * lambda(2, idx_g);
Theta(1, k) = w_resp(1, k) - m * v_drive(1, idx_g);
Theta(2, k) = w_resp(2, k) - m * v_drive(2, idx_g);
end
% ========== 辅助函数 ==========
% 复值符号函数 (Lemma 4)
complex_sign = @(z) sign(real(z)) + 1i*sign(imag(z));
% 复值一范数 (Table 1)
complex_norm1 = @(z) abs(real(z)) + abs(imag(z));
% 模糊AND (取最小值)
fuzzy_and = @(vals) min(real(vals)) + 1i*min(imag(vals));
% 模糊OR (取最大值)
fuzzy_or = @(vals) max(real(vals)) + 1i*max(imag(vals));
% ========== 主仿真循环 ==========
for k = 1:num_steps-1
t = t_vec(k);
% 精确查找滞后时间点索引
t_tau = t - tau;
[~, idx_tau] = min(abs(t_vec - t_tau));
t_gamma = t - gamma;
[~, idx_gamma] = min(abs(t_vec - t_gamma));
t_tau_gamma = t - tau - gamma;
[~, idx_tau_gamma] = min(abs(t_vec - t_tau_gamma));
% --- 更新驱动系统 ---
for i = 1:n
% 方程(33): dλ_i/dt = -λ_i(t) + v_i(t)
dlambda_dt = -lambda(i,k) + v_drive(i,k);
% 方程(33): dv_i/dt 计算
term1 = -xi(i)*v_drive(i,k) - h_param(i)*lambda(i,k);
% 求和项: Σ ∂_{iρ} f_ρ(λ_ρ(t))
term2 = 0;
for rho = 1:n
term2 = term2 + partial(i,rho) * activation(lambda(rho,k));
end
% 求和项: Σ hbar_{iρ} g_ρ(λ_ρ(t-τ))
term3 = 0;
for rho = 1:n
term3 = term3 + hbar(i,rho) * activation(lambda(rho,idx_tau));
end
% 模糊项: AND r_{iρ} H_ρ(t)
and_vals = r(i,:) .* H_input.';
term4 = fuzzy_and(and_vals);
% 模糊项: OR δ_{iρ} H_ρ(t)
or_vals = delta(i,:) .* H_input.';
term5 = fuzzy_or(or_vals);
% 模糊项: AND s_{iρ} g_ρ(λ_ρ(t-τ))
and_vals2 = zeros(1,n);
for rho = 1:n
and_vals2(rho) = s(i,rho) * activation(lambda(rho,idx_tau));
end
term6 = fuzzy_and(and_vals2);
% 模糊项: OR ϖ_{iρ} g_ρ(λ_ρ(t-τ))
or_vals2 = zeros(1,n);
for rho = 1:n
or_vals2(rho) = wbar(i,rho) * activation(lambda(rho,idx_tau));
end
term7 = fuzzy_or(or_vals2);
% 组合所有项
dv_drive_dt = term1 + term2 + term3 + term4 + term5 + term6 + term7;
% 欧拉法更新
lambda(i,k+1) = lambda(i,k) + dt * dlambda_dt;
v_drive(i,k+1) = v_drive(i,k) + dt * dv_drive_dt;
end
% --- 更新响应系统 ---
for i = 1:n
% 方程(35): dκ_i/dt = -κ_i(t) + w_i(t)
dkappa_dt = -kappa(i,k) + w_resp(i,k);
% 方程(35): dw_i/dt 计算 (包含控制器)
term1 = -xi(i)*w_resp(i,k) - h_param(i)*kappa(i,k);
% 求和项: Σ ∂_{iρ} f_ρ(κ_ρ(t))
term2 = 0;
for rho = 1:n
term2 = term2 + partial(i,rho) * activation(kappa(rho,k));
end
% 求和项: Σ hbar_{iρ} g_ρ(κ_ρ(t-τ))
term3 = 0;
for rho = 1:n
term3 = term3 + hbar(i,rho) * activation(kappa(rho,idx_tau));
end
% 模糊项: AND r_{iρ} H_ρ(t)
and_vals = r(i,:) .* H_input.';
term4 = fuzzy_and(and_vals);
% 模糊项: OR δ_{iρ} H_ρ(t)
or_vals = delta(i,:) .* H_input.';
term5 = fuzzy_or(or_vals);
% 模糊项: AND s_{iρ} g_ρ(κ_ρ(t-τ))
and_vals2 = zeros(1,n);
for rho = 1:n
and_vals2(rho) = s(i,rho) * activation(kappa(rho,idx_tau));
end
term6 = fuzzy_and(and_vals2);
% 模糊项: OR ϖ_{iρ} g_ρ(κ_ρ(t-τ))
or_vals2 = zeros(1,n);
for rho = 1:n
or_vals2(rho) = wbar(i,rho) * activation(kappa(rho,idx_tau));
end
term7 = fuzzy_or(or_vals2);
% --- 控制器计算 (方程5) ---
% 计算误差 (使用精确索引)
Sigma(i,k) = kappa(i,k) - m * lambda(i,idx_gamma);
Theta(i,k) = w_resp(i,k) - m * v_drive(i,idx_gamma);
% 计算v_i^*(t) - 修正项
v_star = 0;
for rho = 1:n
% 第一项: m∂_{iρ}f_ρ(λ_ρ(t-γ)) - ∂_{iρ}f_ρ(mλ_ρ(t-γ))
arg1 = lambda(rho,idx_gamma);
termA = m * partial(i,rho) * activation(arg1) - ...
partial(i,rho) * activation(m * arg1);
% 第二项: mhbar_{iρ}f_ρ(λ_ρ(t-τ-γ)) - hbar_{iρ}f_ρ(mλ_ρ(t-τ-γ))
arg2 = lambda(rho,idx_tau_gamma);
termB = m * hbar(i,rho) * activation(arg2) - ...
hbar(i,rho) * activation(m * arg2);
v_star = v_star + termA + termB;
end
% 模糊项: AND s_{iρ}部分
and_vals3 = zeros(1,n);
and_vals4 = zeros(1,n);
for rho = 1:n
arg = lambda(rho,idx_tau_gamma);
and_vals3(rho) = m * s(i,rho) * activation(arg);
and_vals4(rho) = s(i,rho) * activation(m * arg);
end
termC = fuzzy_and(and_vals3) - fuzzy_and(and_vals4);
% 模糊项: OR ϖ_{iρ}部分
or_vals3 = zeros(1,n);
or_vals4 = zeros(1,n);
for rho = 1:n
arg = lambda(rho,idx_tau_gamma);
or_vals3(rho) = m * wbar(i,rho) * activation(arg);
or_vals4(rho) = wbar(i,rho) * activation(m * arg);
end
termD = fuzzy_or(or_vals3) - fuzzy_or(or_vals4);
v_star = v_star + termC + termD;
% 计算v_{1i}(t) - 控制器反馈项
norm_Sigma_i = complex_norm1(Sigma(i,k));
norm_Theta_i = complex_norm1(Theta(i,k));
% 时滞误差项 - 修正为使用Σ_ρ(t-τ)
sum_phi = 0;
for rho = 1:n
% 计算 t - τ 时刻的误差索引
t_tau_rho = t - tau;
[~, idx_tau_rho] = min(abs(t_vec - t_tau_rho));
sum_phi = sum_phi + phi(i,rho) * complex_norm1(Sigma(rho,idx_tau_rho));
end
% 计算v1_i (关键修正: 使用复值符号函数)
v1_i = -complex_sign(Theta(i,k)) * (...
zeta1(i)*norm_Sigma_i + ...
zeta2(i)*norm_Theta_i + ...
norm_Sigma_i^beta_val + ...
norm_Theta_i^beta_val + ...
zeta3(i) + sum_phi);
% 完整控制器 (方程5)
controller = v_star + v1_i;
% 组合所有项 (包含控制器)
dw_resp_dt = term1 + term2 + term3 + term4 + term5 + term6 + term7 + controller;
% 欧拉法更新
kappa(i,k+1) = kappa(i,k) + dt * dkappa_dt;
w_resp(i,k+1) = w_resp(i,k) + dt * dw_resp_dt;
end
% --- 更新下一步的误差 (使用精确索引) ---
for i = 1:n
% 计算 t+1 时刻的 t+1 - γ 索引
t_next_gamma = t_vec(k+1) - gamma;
[~, next_idx_gamma] = min(abs(t_vec - t_next_gamma));
Sigma(i,k+1) = kappa(i,k+1) - m * lambda(i,next_idx_gamma);
Theta(i,k+1) = w_resp(i,k+1) - m * v_drive(i,next_idx_gamma);
end
end
% ========== 可视化结果 ==========
% 提取绘图时间段 (t >= 0)
plot_start_idx = find(t_vec >= 0, 1);
plot_t = t_vec(plot_start_idx:end);
% 创建状态分量图
figure('Position', [100, 100, 1200, 900], 'Name', 'State Components');
% 神经元1状态 (实部)
subplot(2,2,1);
hold on;
plot(plot_t, real(lambda(1,plot_start_idx:end)), 'r-', 'LineWidth', 1.5);
plot(plot_t, real(kappa(1,plot_start_idx:end)), 'b--', 'LineWidth', 1.5);
xlabel('Time (s)', 'FontSize', 12);
ylabel('State Value', 'FontSize', 12);
title('Neuron 1: Real Part', 'FontSize', 14);
legend('Drive \lambda_1', 'Response \kappa_1', 'Location', 'best');
grid on;
xline(T1f, 'r--', 'T_{1f}=6.35', 'LineWidth', 1.5);
hold off;
% 神经元1状态 (虚部)
subplot(2,2,2);
hold on;
plot(plot_t, imag(lambda(1,plot_start_idx:end)), 'r-', 'LineWidth', 1.5);
plot(plot_t, imag(kappa(1,plot_start_idx:end)), 'b--', 'LineWidth', 1.5);
xlabel('Time (s)', 'FontSize', 12);
ylabel('State Value', 'FontSize', 12);
title('Neuron 1: Imaginary Part', 'FontSize', 14);
legend('Drive \lambda_1', 'Response \kappa_1', 'Location', 'best');
grid on;
xline(T1f, 'r--', 'T_{1f}=6.35', 'LineWidth', 1.5);
hold off;
% 神经元2状态 (实部)
subplot(2,2,3);
hold on;
plot(plot_t, real(lambda(2,plot_start_idx:end)), 'r-', 'LineWidth', 1.5);
plot(plot_t, real(kappa(2,plot_start_idx:end)), 'b--', 'LineWidth', 1.5);
xlabel('Time (s)', 'FontSize', 12);
ylabel('State Value', 'FontSize', 12);
title('Neuron 2: Real Part', 'FontSize', 14);
legend('Drive \lambda_2', 'Response \kappa_2', 'Location', 'best');
grid on;
xline(T1f, 'r--', 'T_{1f}=6.35', 'LineWidth', 1.5);
hold off;
% 神经元2状态 (虚部)
subplot(2,2,4);
hold on;
plot(plot_t, imag(lambda(2,plot_start_idx:end)), 'r-', 'LineWidth', 1.5);
plot(plot_t, imag(kappa(2,plot_start_idx:end)), 'b--', 'LineWidth', 1.5);
xlabel('Time (s)', 'FontSize', 12);
ylabel('State Value', 'FontSize', 12);
title('Neuron 2: Imaginary Part', 'FontSize', 14);
legend('Drive \lambda_2', 'Response \kappa_2', 'Location', 'best');
grid on;
xline(T1f, 'r--', 'T_{1f}=6.35', 'LineWidth', 1.5);
hold off;
% 创建同步误差分量图
figure('Position', [100, 100, 1200, 600], 'Name', 'Synchronization Error Components');
% 神经元1同步误差 (实部)
subplot(2,2,1);
plot(plot_t, real(Sigma(1,plot_start_idx:end)), 'b', 'LineWidth', 1.5);
xlabel('Time (s)', 'FontSize', 12);
ylabel('Error', 'FontSize', 12);
title('Neuron 1: Real Part of \Sigma', 'FontSize', 14);
grid on;
hold on;
xline(T1f, 'r--', 'T_{1f}=6.35', 'LineWidth', 1.5);
hold off;
% 神经元1同步误差 (虚部)
subplot(2,2,2);
plot(plot_t, imag(Sigma(1,plot_start_idx:end)), 'b', 'LineWidth', 1.5);
xlabel('Time (s)', 'FontSize', 12);
ylabel('Error', 'FontSize', 12);
title('Neuron 1: Imaginary Part of \Sigma', 'FontSize', 14);
grid on;
hold on;
xline(T1f, 'r--', 'T_{1f}=6.35', 'LineWidth', 1.5);
hold off;
% 神经元2同步误差 (实部)
subplot(2,2,3);
plot(plot_t, real(Sigma(2,plot_start_idx:end)), 'b', 'LineWidth', 1.5);
xlabel('Time (s)', 'FontSize', 12);
ylabel('Error', 'FontSize', 12);
title('Neuron 2: Real Part of \Sigma', 'FontSize', 14);
grid on;
hold on;
xline(T1f, 'r--', 'T_{1f}=6.35', 'LineWidth', 1.5);
hold off;
% 神经元2同步误差 (虚部)
subplot(2,2,4);
plot(plot_t, imag(Sigma(2,plot_start_idx:end)), 'b', 'LineWidth', 1.5);
xlabel('Time (s)', 'FontSize', 12);
ylabel('Error', 'FontSize', 12);
title('Neuron 2: Imaginary Part of \Sigma', 'FontSize', 14);
grid on;
hold on;
xline(T1f, 'r--', 'T_{1f}=6.35', 'LineWidth', 1.5);
hold off;
% ========== 按图六风格绘制同步误差 ==========
figure('Position', [100, 100, 1000, 600], 'Name', 'Synchronization Error (Figure 6 Style)');
hold on;
% 神经元1误差 - 实部 (红色实线)
plot(plot_t, real(Sigma(1,plot_start_idx:end)), 'r-', 'LineWidth', 1.5);
% 神经元1误差 - 虚部 (红色虚线)
plot(plot_t, imag(Sigma(1,plot_start_idx:end)), 'r--', 'LineWidth', 1.5);
% 神经元2误差 - 实部 (蓝色实线)
plot(plot_t, real(Sigma(2,plot_start_idx:end)), 'b-', 'LineWidth', 1.5);
% 神经元2误差 - 虚部 (蓝色虚线)
plot(plot_t, imag(Sigma(2,plot_start_idx:end)), 'b--', 'LineWidth', 2);
% 添加理论同步时间线
xline(T1f, 'k--', 'LineWidth', 2, 'DisplayName', ['T_f = ', num2str(T1f)]);
% 标注参数信息
text(0.5, max(ylim)*0.9, ['m = ', num2str(real(m)), '+', num2str(imag(m)), 'i, \gamma = ', num2str(gamma)], ...
'FontSize', 12, 'BackgroundColor', 'white');
% 设置图形属性
xlabel('Time (s)', 'FontSize', 12);
ylabel('Error Value', 'FontSize', 12);
title('Complex Projective Lag Synchronization Errors', 'FontSize', 14);
legend('Re(\Xi_1)', 'Im(\Xi_1)', 'Re(\Xi_2)', 'Im(\Xi_2)', 'T_f=6.35', 'Location', 'best');
grid on;
box on;
hold off;
% 设置坐标轴范围使曲线清晰
xlim([0, min(t_end, T1f*1.5)]);
ylim([min([real(Sigma(:)); imag(Sigma(:))])*1.1, max([real(Sigma(:)); imag(Sigma(:))])*1.1]);
% ========== 性能分析 ==========
% 计算同步误差范数用于分析
error_norm = zeros(1, num_steps);
for k = 1:num_steps
total_error = 0;
for i = 1:n
total_error = total_error + complex_norm1(Sigma(i,k));
end
error_norm(k) = total_error;
end
plot_error = error_norm(plot_start_idx:end);
% 检查同步时间
error_threshold = 1e-4;
sync_index = find(plot_error < error_threshold, 1);
if ~isempty(sync_index)
sync_time = plot_t(sync_index);
fprintf('系统在 %.4f 秒达到同步 (阈值 = %.0e)\n', sync_time, error_threshold);
else
fprintf('系统在仿真时间内未达到同步 (最小误差 = %.4e)\n', min(plot_error));
end
fprintf('理论同步时间 T_{1f} = %.4f 秒\n', T1f);
% 绘制总误差范数
figure;
semilogy(plot_t, plot_error, 'LineWidth', 2);
xlabel('Time (s)');
ylabel('Total Error Norm');
title('Total Synchronization Error Norm');
grid on;
hold on;
xline(T1f, 'r--', 'T_{1f}=6.35', 'LineWidth', 1.5);
hold off;
这是我给的初值
% 驱动系统初始化 (整个历史区间)
lambda(1, idx_hist) = 5.8 + 1.7i; % φ_1(t)
lambda(2, idx_hist) = -2.5 - 1.4i; % φ_2(t)
v_drive(1, idx_hist) = 7.9 + 0.3i; % ψ_1(t)
v_drive(2, idx_hist) = -4.3 - 0.4i; % ψ_2(t)
% 响应系统初始化
kappa(1, idx_hist) = 3.3 + 1.1i;
kappa(2, idx_hist) = -8.0 - 1.2i;
w_resp(1, idx_hist) = 6.0 - 1.8i;
w_resp(2, idx_hist) = -1.0 + 1.3i;
初值哦和0时刻图像不对应,代码有无,给出改正后的完整代码
最新发布