Genetic Algorithm in Matlab oop
显示 更早的评论
Hi,
Could anyone tell me the syntax of genetic algorithm in matlab oop?
I would like to have a small example with what should be involved in properties and methods, how to add packages etc.
For example
classdef GA
properties
clsystem % this is the folder where all myclasses and subclasses are included
end
methods (Static)
function
% Here goes my algorithm with fitness function
end
end
end
Could anyone give me a small example of the GA syntax using them.
Thank you
9 个评论
Walter Roberson
2020-9-3
I have not encountered a genetic algorithm classdef .
There is no special syntax for one. You define the class according to the interface you want it to have. What properties and operations do you want it to have?
Steven Lord
2020-9-3
Do you mean that you want to specify a method of an object as the objective function for a call to the ga function in Global Optimization Toolbox?
kanuri venkata mohana
2020-9-4
kanuri venkata mohana
2020-9-4
Walter Roberson
2020-9-4
They also have sub folders in them and then they contain classes
Do you mean "classes" in the object-oriented sense? Or do you mean "classes" in the sense of sets of readings that represent similar objects, such as one folder containing a number of pictures of kittens, and another folder containing a number of pictures of kangaroos ?
I want to include fit function in it and optimize.
Why use object oriented programming for that? Why not just call ga() ?
Do you mean that you want to specify a method of an object as the objective function for a call to the ga function
Caution: Methods of an object cannot typically be used directly as the objective function for a call to ga().
ga() calls the function handle it has been supplied, passing in the trial x vector, and expecting the "cost" associated with that vector to be returned. However, methods of an object require that the object itself be passed in as the first parameter, with two exceptions: (1) Object constructors; and (2) "static" methods of a class.
kanuri venkata mohana
2020-9-4
编辑:kanuri venkata mohana
2020-9-4
Walter Roberson
2020-9-4
The main() you post here does not call ga(). It calls gaoptimize(), which is not a Mathworks supplied function.
different folders together which are system, goset, path, pmd
gaoptimize() happens to be a function used in connection with Genetic Optimization System Engineering Tool (GOSET) from US Naval Academy. https://engineering.purdue.edu/~sudhoff/Software%20Distribution/GOSET%202.3%20manual.pdf
GOSET is not Mathworks supplied code.
Your code does not use any variable or field named IT, so I suspect that error is occuring within gaoptimize()
kanuri venkata mohana
2020-9-4
Walter Roberson
2020-9-4
Could you please tell me how to make the field lT to be used by gaoptimize()
No, I cannot.
You call clTransformer and assign the result to objT, but you never do anything with objT . In order to use the field lT of objT, gaoptimize() would have to evalin('caller') to deliberately look for objT in its calling environment, which would be a bad interface design that would be contrary to the principles of using object oriented design.
Perhaps you should be passing objT in some of the gaoptimize() calls, instead of passing objDS in all of them?
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!