?? convert_data_to_ranking_format.m
字號:
function [data]=convert_data_to_ranking_format(X,y,graph_type)% Converts the data to a format suitable for my ranking experiments.%%% Input%% * X ... d x N matrix, each column is one input.% * y ... 1 x N vector of the corresponding class which each input belongs to.% * graph_type ... can be either 'full' or 'chain'%%% Ouput%% * data ... structure containing the various information regarding the ranking task at hand.%% Basic information---%% * data.N ... number of data points% * data.d ... data dimensionality% * data.S ... number of classes% * data.m ... number of inputs in each class %% Actual data---%% * data.labels ... vector of class labels% * data.X ... cell array where each cell contains the data belonging to one class% * data.index ... index of the data belonging to one class% * data.X_raw ... d x N original data matrix% * data.y_raw ... 1 x N vector of the class labels%% Preference graph---% % * data.graph_type ... graph type% * data.C ... number of edges in the preference graph% * data.G ... data.C x 2 matrix encoding the preference relations. The class in the second column is preferred over that in the first column.% * data.num_of_pairs ... total number of pairwise preference realtions%%% Signature%% Author: Vikas Chandrakant Raykar% E-Mail: vikas@cs.umd.edu% Date: September 24, 2006%verbose=1;data.X_raw=X;data.y_raw=y;[data.d,data.N]=size(X);%Class labelsdata.class_labels=unique(y);%Number of classesdata.S=length(data.class_labels);%Graph typedata.graph_type=graph_type;data.X=cell(1,data.S);data.index=cell(1,data.S);%Split the data into differnt classesfor i=1:1:data.S ind=find(y==data.class_labels(i)); data.m(i)=length(ind); if data.m(i)==0 fprintf(1,'\nWarning: Class %d with label %d is empty',i,data.class_labels(i)); end data.X{i}=X(:,ind); data.index{i}=ind; clear ind;end% The order graph [Full graph]if strcmp(graph_type,'full')==1 k=1; data.num_of_pairs=0; for i=1:1:data.S-1 for j=i+1:data.S data.G(k,1)=i; data.G(k,2)=j; data.num_of_pairs=data.num_of_pairs+data.m(data.G(k,1))*data.m(data.G(k,2)); k=k+1; end end data.C=k-1;end% The order graph [Chain graph]if strcmp(graph_type,'chain')==1 k=1; data.num_of_pairs=0; for i=1:data.S-1 data.G(k,1)=i; data.G(k,2)=i+1; data.num_of_pairs=data.num_of_pairs+data.m(data.G(k,1))*data.m(data.G(k,2)); k=k+1; end data.C=k-1;endif verbose==1 disp(sprintf('%d classes N=%d inputs in d=%d dimensions Graph type=%s Total number of pairs=%d',data.S,data.N,data.d,data.graph_type,data.num_of_pairs));endreturn
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -