资源简介
以minstall数据库为例,介绍了详细应用例程。
代码片段和文件信息
% 遗传算法 特征选择 分类测试
clear all
% 加载数据
tic
load mnistAll
train_images = mnist.train_images;
train_labels = mnist.train_labels;
test_images = mnist.test_images;
test_labels = mnist.test_labels;
MN = 28*28;
N = 1000;
TN = 1000;
Train_labels = train_labels(1:N);
Train_images = train_images(::1:N);
Train_images = double(reshape(Train_imagesMNN));
Test_images = double(reshape(test_images(::1:TN)MNTN));
Test_labels = test_labels(1:TN);
class_label = [0:9];
[mn] = size(Train_images);
Len = length(Train_labels); %样本数目
% ga初始化
Iter = 200; %仿真代数
popnum = 80; % 群体规模
pm = 0.8;%变异概率
pc = 0.3; %交叉概率
pop = randi([0 1]mpopnum);%初始化粒子群,每列为一染色体
bestc = 0;
for ii = 1:Iter
%1 计算适应度 采用离散度准则J4 = tr(Sb)/tr(Sw)
pop1 = pop;
for i=1:popnum
temp_ind = find(pop(:i)~=0);
train_temp = Train_images(temp_ind:);
fiti(i) = zsl_J(train_tempTrain_labelsclass_label);
end
bestnow_ind = find(fiti==max(fiti));
bestnow(ii) = fiti(bestnow_ind(1));
if bestnow(ii) > bestc
bestc = bestnow(ii);
bestpop = pop(:bestnow_ind(1));
end
Bestev(ii) = bestc;
%选择复制
totalfiti = sum(fiti);
fitvalue = fiti/totalfiti;
fitvalue1 = cumsum(fitvalue);
[pxpy] = size(pop);
ms = sort(rand(py1));
% for i=1:popnum
% fitin = fi nd(fitvalue1>=ms(i));
% newpop(:i) = pop(:fitin(1));
% end
for i=1:popnum
tmp = find(rand<=fitvalue1);
newpop(:i) = pop(:tmp(1));
end
pop = newpop;
%交叉
[pxpy] = size(pop);
newpop = ones(size(pop));
for i=1:2:py-1
rand_temp = rand;
if (rand_temp cpoint = round(rand*px);
if cpoint==0
cpoint = 1;
elseif cpoint == px
cpoint = px-1;
end
newpop(:i) = [pop(1:cpointi);pop(cpoint+1:pxi+1)];
newpop(:i+1) = [pop(1:cpointi+1);pop(cpoint+1:pxi)];
else
newpop(:i) = pop(:i);
newpop(:i+1) = pop(:i+1);
end
end
newpop(:N) = bestpop;
pop = newpop;
%单点变异
[pxpy] = size(pop);
newpop = ones(size(pop));
for i=1:py
if(rand mpoint = round(rand*px);
if mpoint <=0
mpoint = 1;
end
newpop(:i) = pop(:i);
if any(newpop(mpointi))==0
newpop(mpointi)=1;
else
newpop(mpointi)=0;
end
else
newpop(:i) = pop(:i);
end
end
newpop(:N) = bestpop;
pop = newpop;
[ii]
end
%%
% 利用近邻法识别 SVM
% bestfeature_ind = find(pop(:10)~=0);
bestfeature_ind = find(bestpop==1);
train_images_select = Train_images(bestfeature_ind:);
test_images_select = Test_images(bestfeature_ind:);
acc1 = zsl_n
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3623 2012-05-04 21:54 ga1.m
----------- --------- ---------- ----- ----
3623 1
相关资源
- 基于Matlab的最大熵模糊图像复原算法
- KITTI雷达点云与图像数据融合matlab源码
- matlab 解码 NMEA0183格式GGA数据
- 一个有关飞机的模板匹配的跟踪的m
- 基于MATLAB的电弧模型仿真
- PRI信号分选
- Matlab论文:基于Matlab的二进制数字调
- 802.11协议吞吐量随节点数性能仿真
- matlab图片rgb转yuv,存.yuv文件 播放器
- Duda模式分类Pattern Classification MATLAB 代
- dijkstra算法的matlab实现31274
- 随机路径生成函数matlab
- matlab语音信号处理工具箱
- matlab2013激活文件
- matlab实现游程编码
- 暗通道先验+引导滤波MATLAB代码
- 边缘检测中的canny算法及其matlab实现
- 通过达曼光栅生成点阵的matlab程序.
- MATLAB核函数算法
- 求控制系统的性能指标MptrtsFAI,matl
- matlab 求DTFT
- 逆变器重复控制算法MATLAB仿真
- MATLAB R2014b 许可协议文件
- matlab读取comtrade格式的程序
- 基于Matlab的RC一阶电路仿真
- Las点云数据读取代码
- 雷达回波加天线方向图模拟程序
- MATLAB 2017b 安装文件及其破解文件百度
- Matlab实现音频降噪
- matlab实现导航卫星系统中计算多普勒
评论
共有 条评论