关于多重数组结构的显示
<P>我要建一棵树,产生的多重数组结构,请问用什么语句才能把这个多重数组结构显示出来?</P> <BR>假设想实现这样的显示:<BR> a(1,1)=1<BR> a(1,2)=2<BR> a(1,3)=3<BR> <BR> a(2,1)=1<BR> a(2,2)=3......<BR>不知道有没有什么语句可以实现?<BR><BR>先谢谢! <P>有没有人知道啊?</P> 帮个忙可以吗?回复:(2-31)关于多重数组结构的显示
<P>没懂</P> <P>就是一个树形结构<BR>-A----B-----C<BR>| | <BR>| -----G<BR> ---D-----E<BR> |<BR> -----F<BR>有什么语句可以将这个结构的每层的值都显示出来?<BR>a=tree.child()类似这样?</P> 这个程序出来结果是: split_dim:1<BR>child<BR>我想让它显示:<BR>split_dim:1<BR>child(1) split_dim:1<BR><BR>child(1,1)=2<BR>child(1,2)=1<BR>child(2) split_dim:2<BR><BR>child(2,1)=1<BR>child(2,2)=2<BR>child(3) split_dim:0<BR>child(3)=1<BR>不知道该加个什么语句才能实现? 先谢谢大家!<br>
<P>function tree=build_tree(features,targets,3)<BR>%建树:<BR>=size(features); <BR>Uc=unique(targets);<BR>U=length(unique(targets)); <BR>%结束条件:<BR>if (length(unique(targets))==1)<BR>tree.split_dim=0;<BR>tree.child=targets(U); %???<BR>return<BR>end<BR>if (L == 1),<BR>for a = 1:Nbins,<BR>tree.split_dim = 0;<BR>indices = find(features == a);<BR>if ~isempty(indices),<BR>if (length(unique(targets(indices))) == 1),<BR>tree.child(a) = targets(indices(1));<BR>else<BR>H = hist(targets(indices), Uc);<BR> = max(H);<BR>tree.child(a) = Uc(T);<BR>end<BR>else<BR>tree.child(a) = inf;<BR>end<BR>end<BR>return<BR>end<BR>for a=1:U,<BR>Pnode(a)=length(find(targets==a))/Ni; <BR>end<BR>Inode=-sum(Pnode.*log(Pnode)/log(2)); <BR>delta_Ib=zeros(1,L); <BR>P=zeros(1,U); <BR>for a=1:L, <BR>for k=1:Nbins, <BR>f=find(features(:,a)==k);<BR>V(k)=length(f);<BR>Y(k)=V(k)/Ni;<BR>if (V(k)~=0), <BR>for b=1:U, <BR>s=length(find(targets(f)==b)); <BR>P(b)=s/V(k); %P(s/v)<BR>end<BR>end<BR>Q=sum(-P.*log(eps+P)/log(2)); <BR>E(k)=Y(k).*Q; <BR>end <BR>info=sum(E); <BR>delta_Ib(a)=Inode-info; <BR>end<BR>=max(delta_Ib); <BR>tree.split_dim=dim;<BR>dims=find(~ismember(1:L,dim)); <BR>for a=1:Nbins,<BR>indices=find(features(:,dim) ==a); %把在Ak处取值相同的例子归于同一子集,取几个值就得几个子集<BR>if (~isempty(indices)),<BR>tree.child(a)=build_tree(features(indices,dims),targets(indices),Nbins); %对既含正例又含反例的子集,递归调用建树算法<BR>end<BR>end</P>
<P>features数据:<BR>1 1 1 1<BR>1 1 1 2<BR>2 1 1 1<BR>3 2 1 1<BR>3 3 2 1<BR>3 3 2 2<BR>2 3 2 2<BR>1 2 1 1<BR>1 3 2 1<BR>3 2 2 1<BR>1 2 2 2<BR>2 2 1 2<BR>2 1 2 1<BR>3 2 1 2<BR>targets 数据:<BR>1<BR>1<BR>2<BR>2<BR>2<BR>1<BR>2<BR>1<BR>2<BR>2<BR>2<BR>2<BR>2<BR>1</P>
页:
[1]