This is an example showing how to use Mateda 2.0 for finding the maximum probability of a multivariate normal distribution model. The multivariate normal distribution function in matlab is used to serve as an objective function, in which the following parameters are used.
Number of variables: 2
means: [0 0]
Variance, co-variance matrix (Sigma): [.25 .3; .3 1]
For definition of the multivariate normal distribution function, see here.
As a result, the fitness function to be maximized is written as a matlab function as follows:
function [Z] = MVNPDF_( vector )
%MVNPDF_ Summary of this function goes here
% Detailed explanation goes here
global mu %means
global Sigma %variance-co-variance matrix
Z=mvnpdf(vector, mu, Sigma); %Get the probability given vector of x and y
return
Above function is saved in a file called _MVNPDF.m.
Next, the following is matlab code for finding the maximum value of the above function using EDA.
% Finding maximum of a multivariate normal distribution
PopSize = 100; %if too small say 10, it may not return good results
n = 2; %Number of variables, x and y only
Card(1,:) = -3*ones(1,n); %this is starting range (-3) of the variables
Card(2,:) = 3*ones(1,n); %this is ending range (3) of the variables.
cache = [1,1,1,1,1]; %Turn on all the result logging
% Use Multivariate Gaussian Learning model rather than
% Univariate Gaussian Learning model (LearnGaussianUnivModel)
edaparams{1}={'learning_method','LearnGaussianFullModel',{}};
% Of course, have to use the same class of sampling method
edaparams{2} = {'sampling_method','SampleGaussianFullModel',{PopSize,1}};
% Typical elitism replacement method
edaparams{3}={'replacement_method','elitism',{1,'fitness_ordering'}};
% Select promising solutions based on proportion of fitness
edaparams{4}={'selection_method','prop_selection',{}};
%Define mu and Sigma for setting up the fitness function F
global mu;
mu = [0 0]; % define means for F
global Sigma;
Sigma = [.25 .3; .3 1]; % define sigma for F
F = 'MVNPDF_'; % Set F to the file name of the fitness function.
[AllStat,Cache]=RunEDA(PopSize,n,F,Card,cache,edaparams)
The following is the results:
PopSize: 100
Number of variables: 2
Function: MVNPDF_
seeding_pop_method: RandomInit
Params:
sampling_method: SampleGaussianFullModel
'Params: ' [100] [1]
repairing_method: none
Params:
local_opt_method: none
Params:
replacement_method: elitism
'Params: ' [1] 'fitness_ordering'
selection_method: prop_selection
'Params: '
learning_method: LearnGaussianFullModel
'Params: '
statistics_method: simple_pop_statistics
'Params: ' 'fitness_ordering'
verbose_method: simple_verbose
Params:
stop_cond_method: max_gen
'Params: ' [50]
....
There were 50 generations and the following are the best individuals for each of the 50 generations.
[-0.105761617623641,0.0457401246596891]
[-0.105761617623641,0.0457401246596891]
[-0.105761617623641,0.0457401246596891]
[-0.0218213711430172,-0.0568160229471882]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[0.00104128400186346,-0.00379801083192315]
[-0.000545786613022278,0.000430316063058732]
[-0.000545786613022278,0.000430316063058732]
[-0.000545786613022278,0.000430316063058732]
[-0.000545786613022278,0.000430316063058732]
[-0.000545786613022278,0.000430316063058732]
[-0.000545786613022278,0.000430316063058732]
[-0.000545786613022278,0.000430316063058732]
[-0.000545786613022278,0.000430316063058732]
The optimal values are [-0.000545786613022278,0.000430316063058732]. Put it back to mvnpdf, e.g.mvnpdf([0 0],mu,Sigma), it returns the optimal value of Z.
Although it can find the optimal value, it is interesting to see the model it learnt. To check the learnt model, check Cache{3,:} and this returns 50 [1x2 double] [2x2 double]. Just check the last one and the following vectors/matrix can be identified.
mu'
[0.0351083399147978,-0.0201286199194872]
Sigma'
[0.00247712813037407,-0.000591245499891970;
-0.000591245499891970,0.00391133037686946]
The mu' is closed to the mu [0 0]. However, values in Sigma [.25 .3;
.3 1] are very different than that in Sigma'.
The reason is that this problem is to find the optimal value led by the fitness function. Sigma' and Sigma are referring to different notions. Sigma' provides how accurate the mu' is, see sigma is closed to zero. Instead, Sigma is used to define the distribution model for fitness function only.
ENDS
BC IT Outsourcing 2023/24
-
OK, it has been a while since the last time I published this data, but I have
a valid excuse.
The most striking feature of the 2024 chart is the zero’ing...
1 年前
