大数跨境
0
0

累了一天了,奖励自己一个新的改进点:趋势感知机制,附代码

累了一天了,奖励自己一个新的改进点:趋势感知机制,附代码 算法小狂人
2025-10-22
0
导读:1、简介在元启发式算法中,尽管历史搜索位置数据有可能揭示有价值的移动趋势和有希望的搜索方向,但它们往往未得到充

1、简介

在元启发式算法中,尽管历史搜索位置数据有可能揭示有价值的移动趋势和有希望的搜索方向,但它们往往未得到充分利用。为了解决这一限制,我们提出了趋势感知机制(TAM),该机制利用历史位置信息来增强位置更新过程。TAM通过从最近两次迭代中的总体位置得出趋势线来识别主要移动方向。它通过评估沿着这条趋势线的K个最近点的适应性来评估候选最佳位置。为了有效地平衡探索和利用,TAM采用自适应协方差机制来生成高维随机向量,动态调整更新策略。将TAM与四种著名的元启发式算法——PSO、SHADE、JaDE和CMA-ES——集成,并进行广泛的参数敏感性分析以确保鲁棒性。

2. 趋势感知机制

在本节中,我们介绍 TAM,一种旨在提高基于种群的优化算法的搜索效率和准确性的趋势感知更新策略。该机制利用历史搜索位置和适应度信息,将趋势感知融入搜索过程。TAM 通过分析种群在先前迭代中的搜索轨迹来优化个体位置更新。此外,一种自适应协方差机制生成结合了随机性和稳定性的高维趋势向量,促进了更智能的更新策略。

2.1. 机制概述

此更新机制依赖于两个历史矩阵:历史搜索位置矩阵 search_history 和适应度矩阵 fitness_historysearch_history 是一个大小为 (N, Max_iter, dim) 的三维矩阵,表示 N 个个体在 dim 维问题中跨越 Max_iter 次迭代的搜索位置。相比之下,fitness_history 是一个大小为 (N, Max_iter) 的二维矩阵,记录了相应个体在每次迭代中的适应度值。该更新机制包括以下步骤:

  1. 迭代约束:该机制仅在迭代次数 i > n 时激活,确保至少有 n 代历史数据可用于趋势估计。
  2. 趋势点计算:通过连接上一次迭代的搜索位置 search_history (j,i — 1,:) 与上上次迭代的搜索位置 search_history (j,i — 2,:) 来构建一条直线。从历史数据中识别出距离该直线最近的 K 个点,选择范围限制在最近的前 n 次搜索内,以最小化计算量。
  3. 向量生成:计算一个指向历史位置的向量 V,并使用自适应协方差机制生成一个随机向量 V'。
  4. 适应度比较与更新:将 K 个最近点的适应度值与当前位置和历史位置的适应度值进行比较,以确定算法更新的方向。

2.2. 距离计算

构建直线的参数方程,并通过计算距离来识别最近的点。设 P 表示搜索历史中的一个点,点 P 到直线的距离 d 可以使用以下方程计算(参见框 I 中的方程 (1)):

框 I

在这个方程中,  表示叉积,  表示向量的模。通过遍历所有搜索历史位置来计算每个点 P 到直线的距离,并选择距离最小的 K 个点。

2.3. 自适应协方差机制

在高维空间中,随机生成的偏移向量会显著影响搜索效率,因为此类空间的复杂性增加了平衡探索和开发的挑战。如果这些偏移的方向和大小不能自适应调整,算法可能会效率低下,原因可能是过度探索或过早收敛到局部最优。为了解决这个问题,所提出的机制采用了一种基于自适应协方差的方法,该方法根据当前种群分布调整偏移向量 V'。这种适应有助于提高搜索效率和准确性。该机制的工作原理和实施步骤如下:

首先,计算指向历史位置方向的向量 V,如下所示:

使用自适应协方差机制生成一个高维向量 V',其中   是一个零均值的高斯随机向量,  和   是控制历史趋势和随机探索之间平衡的权重参数。协方差矩阵   描述了多维数据(例如种群位置)中维度之间的相关性。在种群优化算法中,个体位置通常分布在不同维度上,并且这些维度可能表现出依赖性。根据种群位置计算协方差矩阵可以捕获这些相关性和波动,从而实现更集中的搜索。

协方差矩阵   基于种群的当前位置 X 计算:

其中   代表种群中心(所有维度上的平均位置),N 是种群中的个体数量。

一旦计算出协方差矩阵  ,就会生成一个随机向量  ,其方向和大小受种群分布的影响。使用 V 作为方向参考,引导随机向量 Z 沿着 V 的方向,从而得到偏移向量 V'。

这里,  和   是用于平衡历史趋势和随机探索的权重:

为确保 V' 的大小等于 V,将 V' 归一化如下:

2.4. 适应度比较与更新

K 个最近点中第 i 个点对应的适应度值为  ,将其与 search_history (j,i — 1,:) 和 search_history (j,i — 2,:) 的适应度值进行比较。比较执行如下:

  • 如果  ,则设 
  • 否则,如果   且  ,则设 
  • 否则,如果   且  ,则设 
  • 否则,如果  ,则设 

如果  ,这表明两点之间存在更好适应度值的可能性很高。在这种情况下,更新策略为:

其中

此调整将   向可能存在较低适应度值的方向偏移。否则,如果  ,表明两点之间存在较差的适应度值,则更新策略为:

这导致点   偏离当前趋势,确保个体的位置朝着更可能找到更好适应度值的方向移动。

如图 1(a) 所示,点 A (fitness_history (j,i — 2, :)) 和点 B (fitness_history (j,i — 1,:)) 用于趋势感知,而点 C、D、E 和 F 代表历史数据。设 K = 3,C、D 和 E 被识别为最近点,并计算邻近计数  。图 1(b) 是图 1(a) 的二维投影,其中每个点的位置保持一致。因此,图中代表主要感知方向的绿色向量与 AB 对齐。黄色向量表示基于协方差生成的随机向量,灰色向量表示 TAM 的最终输出。

(a) 3D 图 (b) 2D 等高线图

function Vec = TAM(search_history, fitness_history, Max_iter, i, j, K)
    % Inputs:
    % - search_history: historical search positions, 3D matrix (N, Max_iter, dim)
    % - fitness_history: historical fitness values, 2D matrix (N, Max_iter)
    % - Max_iter: maximum number of iterations
    % - i: current iteration index
    % - j: individual index in the population
    % - K: number of nearest points to consider
    
    % If i <= n, skip the trend-aware update mechanism
    n = 3;
    if i <= n 
        Vec = zeros(1size(search_history, 3));  % Return a zero row vector of size 1 x dim
        return;
    end

    % Dimensions of the problem
    [N, ~, dim] = size(search_history);

    % Current and previous positions
    pos_curr = squeeze(search_history(ji-1, :));  % Position at iteration (i-1)
    pos_prev = squeeze(search_history(ji-2, :));  % Position at iteration (i-2)
    
    % Compute trend vector V (Eq. (2))
    V = pos_prev - pos_curr;

    % Generate random vector V' using adaptive covariance mechanism (Eq. (3)-(7))
    X = squeeze(search_history(:, i-1, :));  % Positions of all individuals at iteration (i-1)
    mu = zeros(dim, 1);
    Sigma = cov(X);  % Covariance matrix
    Z = mvnrnd(mu, Sigma);  % Random vector Z ~ N(0, Σ)


    % Compute high-dimensional vector V'
    alpha = i / Max_iter;  % Weighting parameter alpha (Eq. (6))
    beta = 1 - alpha;  % Weighting parameter beta
    V_prime = alpha * V + beta * Z';  % Eq. (5)

    % Preallocate distances and index pairs
    dists = zeros(N * (i - 1), 1);  % Preallocate with maximum possible size
    index_pairs = zeros(N * (i - 1), 2);  % Preallocate with maximum possible size
    count = 0;  % Counter for valid distances

    % Vectorize distance calculations
    v_curr_prev = pos_prev - pos_curr;  % Vector from pos_curr to pos_prev
    norm_v_curr_prev = norm(v_curr_prev);  % Pre-calculate norm

    for p = 1:N
        for it = i-n:i-1  % Iterate through n past iterations up to (i-1)
            P = squeeze(search_history(p, it, :));  % Point at iteration 'it'
            % Vector from pos_curr to P
            v_curr_P = P - pos_curr;
            
            % Projection of v_curr_P onto v_curr_prev
            proj_factor = dot(v_curr_P, v_curr_prev) / norm_v_curr_prev^2;  % Normalize only once
            projection = proj_factor * v_curr_prev;  % Projected vector
            
            % Perpendicular distance (Euclidean distance) between P and the line
            d = norm(v_curr_P - projection);
            count = count + 1;  % Increment valid count
            dists(count) = d;  % Store distance
            index_pairs(count, :) = [p, it];  % Store the individual and iteration index
        end
    end

    % Trim preallocated arrays to the actual size used
    dists = dists(1:count);
    index_pairs = index_pairs(1:count, :);

    % Find the K points with the smallest distances
    [~, sorted_idx] = sort(dists);  % Sort distances in ascending order
    nearest_indices = sorted_idx(1:K);  % Select K nearest points
    K_nearest = index_pairs(nearest_indices, :);  % Get corresponding individual and iteration pairs

    % Perform fitness comparison and update strategy (Eq. (8)-(10))
    F = zeros(K, 1);
    for k = 1:K
        p_k = K_nearest(k, 1);  % Individual index of the K-th nearest point
        it_k = K_nearest(k, 2);  % Iteration index of the K-th nearest point
        f_k = fitness_history(p_k, it_k);  % Fitness value at nearest point

        f_prev1 = fitness_history(ji-1);  % Fitness at iteration (i-1)
        f_prev2 = fitness_history(ji-2);  % Fitness at iteration (i-2)

        if f_k > max(f_prev1, f_prev2)
            F(k) = 1;
        elseif f_prev1 < f_prev2 && f_k > min(f_prev1, f_prev2)
            F(k) = 0.4;
        elseif  f_k > min(f_prev1, f_prev2)
            F(k) = 0;
        else
            F(k) = -1;
        end
    end

    % Determine update direction based on sum of F (Eq. (9)-(10))
    if sum(F) < 0
        Vec = (V_prime * (1 - i / (rand() * Max_iter)) / 10)';  % Ensure Vec is a row vector of size 1 x dim
    else
        Vec = (-V_prime * (1 - i / (rand() * Max_iter)) / 10)';  % Ensure Vec is a row vector of size 1 x dim
    end
end

Ref: Lian J J, Ouyang K, Zhong R, et al. Trend-aware mechanism for metaheuristic algorithms[J]. Applied Soft Computing, 2025, 182: 113505.




完整资源免费获取

群智能算法小狂人

完整资源获取方式(200多种算法)

https://github.com/suthels/-/blob/main/README.md



---RECOMMEND---

·独家推荐~欢迎选购·



合作洽谈:群智能算法小狂人(ID:Suthel)


©算法改进与开发定制|数学建模|AVL cruise建模与仿真

戳“阅读原文”,下载完整代码

【声明】内容源于网络
0
0
算法小狂人
(群智能)算法开发与改进、算法类相关应用、机器学习、数学建模,命名实体识别,项目计划书撰写,AVL cruise建模仿真。
内容 228
粉丝 0
算法小狂人 (群智能)算法开发与改进、算法类相关应用、机器学习、数学建模,命名实体识别,项目计划书撰写,AVL cruise建模仿真。
总阅读87
粉丝0
内容228