⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mygaini.m

📁 本源码用于解决金融领域的指数复制的问题
💻 M
字号:
function [pop,weights,y0] = mygaini(num,bounds,NVAR,evalFN,P,I,evalOps,options)
% initializeoga(populationSize, variableBounds,evalFN,evalOps,options)
%    initializeoga creates a matrix of random permutations with 
%    a number of rows equal to the populationSize and a number
%    columns equal to the size of the permutation plus 1 for 
%    the f(x) value which is found by applying the evalFN.
%    This initization function is used with an order-based
%    representation.
%
% pop    - the initial, evaluated, random population 
% num    - the size of the population, i.e. the number to create
% bounds - the number of permutations in an individual (e.g., number
%          of cities in a tsp
% evalFN - the evaluation fn, usually the name of the .m file for evaluation
% evalOps- any options to be passed to the eval function defaults []
% options- options to the initialize function, ie. [eps float/binary prec] 
%           where eps is the epsilon value and the second option is 1 for
%          orderOps, prec is the precision of the variables defaults [1e-6 1]

if nargin<5
  options=[1e-6 1];
end
if nargin<4
  evalOps=[];
end


numVars     = bounds; 		%Number of variables

xZomeLength = numVars+1; 		%Length of string is numVar + fit
pop         = zeros(num,xZomeLength); 	%Allocate the new population
for i=1:num
  pop(i,:)=[randperm(numVars) 0];
end

Q=P(2:end,pop(1,1:NVAR));
R=P(1:end-1,pop(1,1:NVAR));
S=P(end,pop(1,1:NVAR));
options = optimset('Display','off','LargeScale','off');  
y0=ones(NVAR,1);

weights=[];
for i=1:num
    Q=P(2:end,pop(i,1:NVAR));
    R=P(1:end-1,pop(i,1:NVAR));
    S=P(end,pop(i,1:NVAR));
    [weights(i,:) pop(i,end)]=fmincon(@(y) myfun(y,pop(i,1:NVAR),Q,R,I(2:end)+1),y0,[],[],S,10000,ones(NVAR,1),10000.*ones(NVAR,1),[],options);
    pop(i,end)=-pop(i,end);
end


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -