近期在研究生物地理學優化算法(Biogeography-based optimization ) 時發現 在計算物種數概率時,原文章給出的公式與作者給出的源碼形式不一樣,一度以爲是代碼出了問題,最後發現是因爲代碼中對種羣的排序是按照 從最好到最差 的順序排序。
原論文下載:https://download.csdn.net/download/sunshinefcx/11111947
源碼下載:https://download.csdn.net/download/sunshinefcx/11111950
代碼中的棲息地排序如下形式【population(i) 表示第 i 個棲息地】:
for j = 1 : length(Population) % 其中 j 代表的是棲息地
% Population(1) 是適宜度最高的棲息地,相對應的這個棲息地的物種數量最多
% 隨着 j 的增加,物種數量是減少的,棲息地的 適宜度 HSI 也是降低的
end
下面咱們來看,原論文及源碼中分別是怎麼實現的
原論文:
首先看原文我們可以知道,原文章中給出的 某棲息地在 (t+△t) 時刻有 S 種物種的概率 Ps 的計算公式如下:
在(t+△t)時刻此 棲息地 中有 S 種物種的情況主要有下面三種:
1、在 △t 時間內,此棲息地沒有 遷入 遷出
2、在 t 時刻此棲息地有S-1種物種,在 △t 時間內,遷入一種,以致於在 (t+△t) 時刻有 S 種
3、在 t 時刻此棲息地有S+1種物種,在 △t 時間內,遷出一種,以致於在 (t+△t) 時刻有 S 種
公式(1) 對 △t 求導之後,得到下面的式(2)
下面來看,源碼中是怎麼實現的
源代碼:
[lambda, mu] = GetLambdaMu(Population, I, E, P); % I表示最大遷入率 E最大遷出率 P最大物種數
if ProbFlag
% Compute the time derivative of Prob(i) for each habitat i.
for j = 1 : length(Population) % 開始遍歷棲息地 開始求導
% j 代表的是 棲息地
% Compute lambda for one less than the species count of habitat i.
lambdaMinus = I * (1 - (Population(j).SpeciesCount - 1) / P);
% Compute mu for one more than the species count of habitat i.
muPlus = E * (Population(j).SpeciesCount + 1) / P;
% Compute Prob for one less than and one more than the species count of habitat i.
% Note that species counts are arranged in an order opposite to that presented in
% MacArthur and Wilson's book - that is, the most fit
% habitat has index 1, which has the highest species count.
% 請注意,物種數量的排列順序與麥克阿瑟和威爾遜的書中的順序相反——
% 也就是說,最適合的棲息地的索引是 1,其物種數量最高。
% 所以說 對 第 j = 1 個種羣 ,物種數量是最多的,因此在 t 時刻 不能進行遷出操作
% 所以說 對 第 j = Smax 個種羣 ,物種數量是最少的,因此在 t 時刻 不能進行遷入操作
% j 從 1 -- Smax 物種數量是從最多到最少
if j < length(Population) % S < Smax
ProbMinus = Prob(j+1); % !!!因爲是相反的,所以 j + 1表示的是 物種數量 - 1
else % S == Smax
ProbMinus = 0;
end
if j > 1 % S > 1
ProbPlus = Prob(j-1); % !!! 因爲是相反的,所以 j - 1表示的是 物種數量 + 1
else % S = 1
ProbPlus = 0;
end
ProbDot(j) = -(lambda(j) + mu(j)) * Prob(j) + lambdaMinus * ProbMinus + muPlus * ProbPlus;
end
% Note that species counts are arranged in an order opposite to that presented in
% MacArthur and Wilson's book - that is, the most fit
% habitat has index 1, which has the highest species count.
% 請注意,物種數量的排列順序與麥克阿瑟和威爾遜的書中的順序相反——
% 也就是說,最適合的棲息地的索引是 1,其物種數量最高。
注意源碼中標註的這句,所以可以發現,正是在源碼中對棲息地的排序是從 最好 到 最差,所以相對應的 種羣數量也是從最多到最少,與上述(2)的也是相反的,詳細的理解可以參考我在代碼中的註釋