%[2009]-"Text feature selection using ant colony optimization"
% (9/12/2020)
function ACO = jAntColonyOptimizationSVM(feat,label,opts)
% Parameters
tau = 1; % pheromone value
eta = 1; % heuristic desirability
alpha = 1; % control pheromone
beta = 0.1; % control heuristic
rho = 0.2; % pheromone trail decay coefficient
if isfield(opts,'N'), N = opts.N; end
if isfield(opts,'T'), max_Iter = opts.T; end
if isfield(opts,'tau'), tau = opts.tau; end
if isfield(opts,'alpha'), alpha = opts.alpha; end
if isfield(opts,'beta'), beta = opts.beta; end
if isfield(opts,'rho'), rho = opts.rho; end
if isfield(opts,'eta'), eta = opts.eta; end
% Objective function
fun = @jFitnessFunctionSVM;
% Number of dimensions
dim = size(feat,2);
% Initial Tau & Eta
tau = tau * ones(dim,dim);
eta = eta * ones(dim,dim);
% Pre
fitG = inf;
fit = zeros(1,N);
curve = inf;
t = 1;
% Iterations
while t <= max_Iter
% Reset ant
X = zeros(N,dim);
for i = 1:N
% Random number of features
num_feat = randi([1,dim]);
% Ant start with random position
X(i,1) = randi([1,dim]);
k = [];
if num_feat > 1
for d = 2:num_feat
% Start with previous tour
k = [k(1:end), X(i, d-1)];
% Edge/Probability Selection (2)
P = (tau(k(end),:) .^ alpha) .* (eta(k(end),:) .^ beta);
% Set selected position = 0 probability (2)
P(k) = 0;
% Convert probability (2)
prob = P ./ sum(P(:));
% Roulette Wheel selection
route = jRouletteWheelSelection(prob);
% Store selected position to be next tour
X(i,d) = route;
end
end
end
% Binary
X_bin = zeros(N,dim);
for i = 1:N
% Binary form
ind = X(i,:);
ind(ind == 0) = [];
X_bin(i,ind) = 1;
end
% Fitness
for i = 1:N
% Fitness
fit(i) = fun(feat,label,X_bin(i,:),opts);
% Global update
if fit(i) < fitG
Xgb = X(i,:);
fitG = fit(i);
end
end
%---// [Pheromone update rule on tauK] //
tauK = zeros(dim,dim);
for i = 1:N
% Update Phromones
tour = X(i,:);
tour(tour == 0) = [];
% Number of features
len_x = length(tour);
tour = [tour(1:end), tour(1)];
for d = 1:len_x
% Feature selected on graph
x = tour(d);
y = tour(d + 1);
% Update delta tau k on graph (3)
tauK(x,y) = tauK(x,y) + (1 / (1 + fit(i)));
end
end
%---// [Pheromone update rule on tauG] //
tauG = zeros(dim,dim);
tour = Xgb;
tour(tour == 0) = [];
% Number of features
len_g = length(tour);
tour = [tour(1:end), tour(1)];
for d = 1:len_g
% Feature selected on graph
x = tour(d);
y = tour(d + 1);
% Update delta tau G on graph
tauG(x,y) = 1 / (1 + fitG);
end
%---// Evaporate pheromone // (4)
tau = (1 - rho) * tau + tauK + tauG;
% Save
curve(t) = fitG;
fprintf('\nIteration %d Best (ACO)= %f',t,curve(t))
t = t + 1;
end
% Select features based on selected index
Sf = Xgb;
Sf(Sf == 0) = [];
sFeat = feat(:,Sf);
% Store results
ACO.sf = Sf;
ACO.ff = sFeat;
ACO.nf = length(Sf);
ACO.s = curve;
ACO.f = feat;
ACO.l = label;
end
%// Roulette Wheel Selection //
function Index = jRouletteWheelSelection(prob)
% Cummulative summation
C = cumsum(prob);
% Random one value, most probability value [0~1]
P = rand();
% Roulette wheel
for i = 1:length(C)
if C(i) > P
Index = i;
break;
end
end
end
机器不会学习CL
- 粉丝: 3867
- 资源: 71
最新资源
- 30T水井钻机sw19全套技术资料100%好用.zip
- 生产型企业设备备件溯源
- 文明6 兵贵神速mod 发布,作者luke(伊玛目的门徒),代码在博客里开源了
- docker-compose mongodb 副本集
- 光储直流微电网协调控制 直流电压分层优化控制 逆变器与储能变流器根据负载变化情况自动实现下垂模式和恒压模式的切 (附参考文献)
- 混合copula 二维数据拟合得到相关结构参数与系数 主要针对常用的Clayton Frank Gumbel三种copula函数的组合,进行混合copula构建 Matlab代码实现
- 自适应大领域搜索算法(ALNS)matlab解决tsp问题,与传统大规模领域搜索算法(LNS)相比收敛性强,运行时间短,很好的学习资料
- 2025年机器人专业毕业设计,双足机器人及其步态规划,包含三维图及二维图和论文说明书
- A星算法 A*算法 自己研究编写的Matlab路径规划算法 Astar算法走迷宫 可自行设置起始点,目标点,自由更地图 - 可以和人工势场法融合 动态障碍物
- win32汇编环境,对话框程序中显示文本
- C# winform-网上银行信息系统开发(源码+sql文件+设计报告)-2025-01-04
- 增材制造模拟,增材制造仿真 ansys workbench ,cmt, waam ,slm,电弧增材制造焊接,温度场应力场仿真模拟分析案例教程apdl命令流 单道单层,多道多层,搭接,增材仿真
- comsol锂离子电池组充放电循环强制液冷散热仿真 模型为SolidWorks导入,可以提供原模型 电池模型:一维电化学(p2d)模型耦合三维热模型
- 无感方波BLDC,手电钻源代码,全套方案
- 基于STM32的婴儿床温湿度监控系统20241228
- 无人船 无人艇路径跟踪控制 Matlab Simulink效果 基于Foseen船舶模型,LOS制导子系统+反步控制器制作 LOS+backstepping; 注:采用ESO实现漂角 侧滑角估计
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈