資源簡介
是ISODATA的實現,題目比較簡單,有很大的一致性,代碼280余行
代碼片段和文件信息
function?ISODATA()
clc;
format?long;
K?=?2;thetaN?=?2;thetas?=?1;thetad?=?4;L?=?1;I?=?4;Nc?=?1;N?=?8;
point?=?[00;11;22;43;53;44;54;65];??????????%所有點
cate?=?zeros(5N);??????????????????????????????????%用來存儲每一分類中點的序號
mymean?=?zeros(52);????????????????????????????????%用來存儲每一分類的中心
for?n?=?1:8?????????????????????????????????????????%初始分類
????cate(1n)?=?n;
end
c?=?1;??????????????????????????????????????????????%類的數目
deltaj?=?zeros(51);????????????????????????????????%每一類樣本與其中心的平均距離
delta?=?0;??????????????????????????????????????????%總平均距離
for?n?=?1:I?????????????????????????????????????????%I次迭代?????
????for?m?=?1:5?????????????????????????????????????%計算各分類的中心
????????temp?=?[];
????????for?l?=?1:8
????????????if?cate(ml)?~=?0
????????????????temp?=?[temppoint(cate(ml):)‘];
????????????end
????????end
????????if?~isempty(temp)
????????????mymean(m:)?=?mean(temp2)‘;
????????end
????end
????temp?=?0;
????for?m?=?1:c?????????????????????????????????????%去掉樣本數過少的類
????????if?NumCate(catem)?????????????for?l?=?1:NumCate(catem)
????????????????idx?=?NearestCate(mymeanpointcate(ml)cm);
????????????????cate(idxNumCate(cateidx)+1)?=?cate(ml);
????????????end
????????????cate(m:)?=?zeros(1N);
????????????temp?=?temp?+?1;
????????end
????end
????for?m?=?1:5?????????????????????????????????????%重新計算各分類的中心
????????temp?=?[];
????????for?l?=?1:8
????????????if?cate(ml)?~=?0
????????????????temp?=?[temppoint(cate(ml):)‘];
????????????end
????????end
????????if?~isempty(temp)
????????????mymean(m:)?=?mean(temp2)‘;
????????end
????end
????for?l?=?1:c?????????????????????????????????????%計算每一類樣本與其中心的平均距離
????????temp?=?0;
????????for?k?=?1:NumCate(catel)
????????????temp?=?temp?+?(point(cate(lk)1)?-?mymean(l1))^2?+?(point(cate(lk)2)?-?mymean(l2))^2;
????????end
????????deltaj(l1)?=?temp?/?NumCate(catel);
????end
????delta?=?0;??????????????????????????????????????%計算總平均距離
????for?l?=?1:c
????????delta?=?delta?+?NumCate(catel)?*?deltaj(l1);
????end
????delta?=?delta?/?N;
????sigma?=?Sigma(catecpointmymean);?????????????%計算每個類的各維標準偏差
????sigma_max?=?max(sigma[]2);
????[sigma_max_maxidx]?=?max(sigma_max);
????if?c?<=?K/2?|?(sigma_max_max?>?thetas?&?deltaj(idx)?>?delta?&?NumCate(catec)?>?2?*?(thetaN?+?1))???????%分裂
????????c?=?c?+?1;
????????center1?=?mymean(idx:)?+?0.5?*?sigma;
????????center2?=?mymean(idx:)?-?0.5?*?sigma;
????????temp?=?zeros(2NumCate(cateidx));
????????n1?=?0;n2?=?0;
????????for?m?=?1:NumCate(cateidx)
????????????if?(point(cate(idxm)1)?-?center1(11))^2?+?(point(cate(idxm)2)?-?center1(
- 上一篇:ISE生成coe文件工具
- 下一篇:三相逆變器并聯仿真
評論
共有 條評論