MATLAB: Genetic algorithm

inital populationurgent

Dear all,
Please please someone help me urgently.
I want to use genetic algorithm on a weather dataset that has values for actual_observed weather variable and forecasts made by 4 different ways for that weather variable. Though the dataset contains thousands of rows but as a sample please provide me help for 10 rows of data.
This is stored in a matrix of 10rows X 5columns. Rows corresponds to temperature at 10 places forecasted by 4 different forecasting methods and last column is for the observed actual temperature at those 10 places.
Using ga, I need to know which one of these 4 forecasts are closest to the actual observed forecast. For this purpose, I am calculating error as(actual_observed – forecast)/ actual_observed. So, the result of this error, I am storing in another matrix of 10rows X 4 columns. The fitness function should search the column that has minimum error value. Please advise urgently, how to apply GA on such data.
Alternatively, I have tried calculate error and store in excel. Now I have written following fitness function. But I am getting error
??? In an assignment A(:) = B, the number of elements in A and B
must be the same.
Error in ==> ga at 188
state.Score(thisPopulation) = score;
function y = singlefitfun(xvector)
x1error=xvector(1:10);
x2error=xvector(11:20);
x3error=xvector(21:30);
x4error=xvector(31:40);
y=zeros(80,1);
for i = 1:10
y(i) = (x1error(i) + x2error(i) + x3error(i) + x4error(i))/4;
end

Best Answer

fitnessfcn accepts input x and returns a scalar function value evaluated at x.
However, your fitness function returns a vector of length 80.
Are the forecasting functions constant for a particular run, or is an unstated part of the question to improve the forecasting functions through GA? If the forecasting functions are constant, then your task is not suitable for GA and is instead better expressed as
[mindiffs, mincols] = min(abs(ForeCastData - MeasuredData),2);
and then mincols would indicate which of the forecasts was most accurate at each step. Determining which forecast was the overall most accurate would likewise be fairly simple:
msqe = sqrt(sum((ForeCastData - MeasuredData).^2));
[minerr, mincol] = min(msqe);
after which mincol would indicate which forecast had the best error rate.
Related Question