samplemodel.m

来自「This matlab code on reed solomon and BCH」· M 代码 · 共 47 行

M
47
字号
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 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 + =
减小字号Ctrl + -
显示快捷键?