I there a way to call variables from my workspace into the genetic algorithm tool? (Without calling them from the fitness function)
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Jose Diaz
am 23 Okt. 2020
Bearbeitet: Stephen23
am 23 Okt. 2020
I have a fitness function which has coeficients that I am importing from a .csv file. The problem is that when I run the GA tool (from its GUI, not from code) it imports the data every iteration (which is very time consuming). I have tried removing the line where I read the table, since "data" is already in my workspace, however the tool doesn't recognize variables that in my workspace. Is it possible to have variables in my fitness function (data.Die and data.DiePD in my case) that are in my worspace without having to create those in my function?
function Sum_Sqr=GA_(x)
data=readtable('test.csv');
x1=x(1);x2=x(2);
dT = (x1*data.DieA.^x2).*data.DiePD
Sum_Sqr = sumsqr ( sum(dT,2) - data.t1);
0 Kommentare
Akzeptierte Antwort
Stephen23
am 23 Okt. 2020
Bearbeitet: Stephen23
am 23 Okt. 2020
"Is it possible to have variables in my fitness function (data.Die and data.DiePD in my case) that are in my worspace without having to create those in my function?"
Of course. You just need to parameterize your function, the MATLAB documentation explains how:
Basically you need to add those variables as inputs to the function, e.g.:
function Sum_Sqr=GA_(x,data)
and then in the workspace where the function is used you need something like this:
data = readtable('test.csv');
..
ga(@(x)GA_(x,data), .. )
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Genetic Algorithm finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!