How to modify this function with a different objective function

조회 수: 9 (최근 30일)
gary_feesher
gary_feesher 2016년 12월 4일
편집: gary_feesher 2016년 12월 4일
From this tutorial on Multiobjective Optimization using Particle Swarm Optimization, there is a function that creates the two objective functions (below). My question is: I have two objective functions that I would like to replace f1 and f2 with, but I am unsure where to even begin. For example, my objective functions are the Sharpe Ratio and Percent Profit functions. Both of these functions require a couple different inputs and I am not sure where these should be initialized.
Any support on where to go next is appreciated!
function z=ZDT(x)
n=numel(x);
f1=x(1);
g=1+9/(n-1)*sum(x(2:end));
h=1-sqrt(f1/g);
f2=g*h;
z=[f1
f2];
end

채택된 답변

Walter Roberson
Walter Roberson 2016년 12월 4일
That is, create two anonymous functions
extra_parameters_for_sharpe = ....
extra_parameters_for_percent_profit = ....
F_sh = @(x) sharpe_ratio(x, extra_parameters_for_sharpe);
F_pp = @(x) percent_profit(x, extra_parameters_for_percent_profit);
After which,
obj = @(x) [F_sh(x); F_pp(x)];
best_x = particleswarm(obj, .......)
  댓글 수: 1
gary_feesher
gary_feesher 2016년 12월 4일
편집: gary_feesher 2016년 12월 4일
Makes sense, thanks Walter! Another question... Would x and the extra parameters be the weights for the objective functions that are returned when the swarm is finished optimizing? And is there a way to turn this Sharpe Matlab function into an objective function for my optimization code? ( Sharpe Ratio)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Particle Swarm에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by