📄 samplemodel.m
字号:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% File: sampleModel.m
%
% Description: Sample the new population based on the given marginal
% product model (structure and the probability distribution)
%
% @param mpm is a cell array with the local-best marginal product model,
% the subsolutions across all partitions present in the population, the
% associated frequencies of the the different subsolutions, and the MDL
% score.
%
% @param n is the number of new individuals that need to be
% sampled/created.
%
% @return population is the new sampled population of candidate solutions
%
% Author: Kumara Sastry
%
% Date: March 2007
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function population = sampleModel(mpm, n)
% Get the model, subsolutions, and frequencies from the mpm
model = mpm.SubStructures;
subSolutions = mpm.SubSolutions;
frequency = mpm.Probabilities;
% Get the total number of substructures
numSubStructures = size(model,2);
% Sample subsolutions for each of the substructure
for i = 1:numSubStructures,
%For each substructure
subStructure = model{i};
% Get the list of subsolutions, and the frequencies
subSolution = subSolutions{i};
subSolutionFrequency = frequency{i};
% Sample the subsolutions from the given discrete probability
% distribution
sampledSubSolutionID = randsample(1:size(subSolution,1), n, true, subSolutionFrequency);
population(:,subStructure) = subSolution(sampledSubSolutionID,:);
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -