MATLAB Answers

How can I introduce an non-genetic case optimization in Matlab Genetic Algorithm?

1 view (last 30 days)
rfigueiredo on 7 Apr 2015
My problem is easier to understand with the code that someone help me to accomplished using fminsearch.
function optimization
h = randi(24,8760,1);
nd = randi(365,8760,1);
veic = randi(333,8760,1);
max_veic = max(veic);
veicN = veic./max_veic;
Gh= randi(500,8760,1);
Dh= randi(500,8760,1);
A = randi([300800],27,1);
lat =70;
HRA =15.*(h-12);
decl =23.27*sind(360*(284+nd)/365);
% precompute
cHRA = cosd(HRA);
sHRA = sind(HRA);
sdecl = sind(decl);
cdecl = cosd(decl);
slat = sind(lat);
clat = cosd(lat);
pares_opt = fminsearch(@fun, randi([0,90],27,2))
function RMSE = fun(pares)
if any(pares( : )<0)|| any(pares( : ) >90)
RMSE = inf;
% precompute
cinclin = cosd(pares(:,1))';
sinclin = sind(pares(:,1))';
cazim = cosd(pares(:,2))';
sazim = sind(pares(:,2))';
Ii= bsxfun(@times,Ih,...
sdecl *(slat * cinclin - clat * sinclin .* cazim)...
+(cdecl .* cHRA)*(clat * cinclin + slat * sinclin .* cazim)...
+(cdecl .* sHRA)*(sinclin .* sazim));
Di=0.5*Dh*(1+ cinclin);
Gi=(Ii+Di)* diag(A);
Gparque= sum(Gi,2);
max_Gparque = max(Gparque);
RMSE = sqrt(mean((GparqueN-veicN).^2));
My main goal is to achieve the best 'RMSE' possible, to do so I have to create a matrix ('pares') where each line contains a pair of values (one value from each column).These values have to be within a certain range(0-90). With each of this 27 pairs I have to calculate 'Ii'/'Gi'/'Di', giving me a matrix with a size like 8760*27.
Then I make a sum of 'Gi' to have 'Gparque'(vector 8760*1) and finally I calculate 'RMSE'. When I have RMSE calculated, I have to modify the matrix 'pares' to other values that can result in a better RMSE. Once there are many combinations of 27 values that can be within the 0-90 range, I have to get a solution that can optimize this search for the minimum RMSE. So, I need to use something that changes the values of 'pares' but with some optimization criteria that can approximate the minimum of RMSE.
I've searched and found that Genetic Algorithm tools in Matlab can be a good match for this problem. But now I don't know how I can introduce my data in this algorithm. I think that my matrix 'pares' is the individual that I want to optimize, and maybe it is easier to make this matrix a single vector because if I do so, each row of the matrix's used on GA could be an individual. But I am not sure of this!
Thank you so much!

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!