Originally Posted by
notPrime Thanks a lot. I have another question (Sorry, I literally started using Matlab last week). I have two m files fitness and DoIt. In DoIt, I have:
...Some code
fitness(gene2,gene3,gene4,gene5,gene6,actualYValue s,measureOfFit1)
In fitness, I have:
%This function measures the fitness of our chromosome by comparing the predict values to the
%actual values. The measure of fit is the square of the pearson correlation coefficient.
function[measure] = fitness(x1, x2, x3, x4, x5,yValues,fitnessValue)
%Here we form the matrix and carry out the linear regression calculations
firstColumn=ones(29,1);
theMatrix = [firstColumn, x1, x2, x3, x4, x5];
c=inv(transpose(theMatrix)*theMatrix)*transpose(th eMatrix);
%Now we will multiply the transpose of the c matrix by the the transpose of theMatrix to
%calculate our predicted y values. Using linear regression.
finalMatrix = transpose(transpose(c)*transpose(theMatrix));
predictedYValues = finalMatrix*yValues;
measure = linreg(predictedYValues, yValues);
fitnessValue=measure;
I'm trying to get the fitness function to reflect the changes in the fitnessValue done in the fitness function back to the DoIt function. How would I do this? Is there anything like the ampersand in C?
Try calling code:
Code:
fitnessvalue=fitness( ..... )
where the fitness function returns measure rather than modifies fitnessvalue:
Code:
function [measure] = fitness(x1, x2, x3, x4, x5,yValues,fitnessValue)
%Here we form the matrix and carry out the linear regression calculations
firstColumn=ones(29,1);
theMatrix = [firstColumn, x1, x2, x3, x4, x5];
c=inv(transpose(theMatrix)*theMatrix)*transpose(theMatrix);
%Now we will multiply the transpose of the c matrix by the the
%transpose of theMatrix to
%calculate our predicted y values. Using linear regression.
finalMatrix = transpose(transpose(c)*transpose(theMatrix));
predictedYValues = finalMatrix*yValues;
measure = linreg(predictedYValues, yValues);
CB