restrictedtournamentreplacement.m
来自「This matlab code on reed solomon and BCH」· M 代码 · 共 57 行
M
57 行
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% File: restrictedTournamentReplacement.m
%
% Description: Perform restricted tournament replacement. For every
% offspring select the closest parent from among w randomly chosen parents.
% If the offspring is better than the closest parent then it replaces the
% parent.
%
% @param population is the parent population
%
% @param fitness is the fitness of parent individuals
%
% @param newPopulation is the offspring population
%
% @param newFitness is the fitness of offspring individuals
%
% @param windowSize is the fitness of offspring individuals
%
% @return bestPopulation is the top n individuals from the combined
% population of parent and offspring individuals.
%
% @return bestFitness is the fitness of the top n individuals from the
% combined population of parent and offspring individuals.
%
% Author: Kumara Sastry
%
% Date: March 2007
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [population, fitness] = restrictedTournamentReplacement(population, fitness, newPopulation, newFitness, windowSize)
% Get the number of offspring individuals
n = size(newPopulation,1);
% For each offspring individual
for i = 1:n,
% Randomly select windowSize individuals from the parent population
shuffleArray = randperm(n);
chosenParentsIndex = shuffleArray(1:windowSize);
%Compute the hamming distance of the offspring with the randomly
%selected parents
hammingDistance = sum(abs(population(chosenParentsIndex,:)-repmat(newPopulation(i,:),windowSize,1)),2);
% Find the closest parent
[closestDistance, closestDistanceIndex] = min(hammingDistance);
closestParent = chosenParentsIndex(closestDistanceIndex);
% If the offspring is better than the closest parent than replace the
% parent with the offspring.
if(newFitness(i) > fitness(closestParent))
population(closestParent,:) = newPopulation(i,:);
fitness(closestParent) = newFitness(i);
end
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?