wolffd@0: function [bnt_data, old_values] = transform_data_into_bnt_format(data,cnodes) wolffd@0: % TRANSFORM_DATA_TO_BNT_FORMAT Ensures discrete variables have values 1,2,..,k wolffd@0: % e.g., if the values of a discrete are [0 1 6], they must be mapped to [1 2 3] wolffd@0: % wolffd@0: % data(i,j) is the value for i-th node in j-th case. wolffd@0: % bnt_data(i,j) is the new value. wolffd@0: % old_values{i} are the original values for node i. wolffd@0: % cnodes is the list of all continous nodes, e.g. [3 5] means the 3rd and 5th node is continuous wolffd@0: % wolffd@0: % Author: yimin.zhang@intel.com wolffd@0: % Last updated: Jan. 22, 2002 by Kevin Murphy. wolffd@0: wolffd@0: num_nodes=size(data,1); wolffd@0: num_cases=size(data,2); wolffd@0: old_values=cell(1,num_nodes); wolffd@0: wolffd@0: for i=1:num_nodes wolffd@0: if (myismember(i,cnodes)==1) %cts nodes no need to be transformed wolffd@0: %just copy the data wolffd@0: bnt_data(i,:)=data(i,:); wolffd@0: continue; wolffd@0: end wolffd@0: values = data(i,:); wolffd@0: sort_v = sort(values); wolffd@0: %remove the duplicate values in sort_v wolffd@0: v_set = unique(sort_v); wolffd@0: wolffd@0: %transform the values wolffd@0: for j=1:size(values,2) wolffd@0: index = binary_search(v_set,values(j)); wolffd@0: if (index==-1) wolffd@0: fprintf('value not found in tranforming data to bnt format.\n'); wolffd@0: return; wolffd@0: end wolffd@0: bnt_data(i,j)=index; wolffd@0: end wolffd@0: old_values{i}=v_set; wolffd@0: end wolffd@0: wolffd@0: wolffd@0: %%%%%%%%%%%% wolffd@0: wolffd@0: function index=binary_search(vector, value) wolffd@0: % BI_SEARCH do binary search for value in the vector wolffd@0: % Author: yimin.zhang@intel.com wolffd@0: % Last updated: Jan. 19, 2002 wolffd@0: wolffd@0: begin_index=1; wolffd@0: end_index=size(vector,2); wolffd@0: index=-1; wolffd@0: while (begin_index<=end_index) wolffd@0: mid=floor((begin_index+end_index)/2); wolffd@0: if (isstr(vector(mid))) wolffd@0: % need to write a strcmp to return three result (< = >) wolffd@0: else wolffd@0: if (value==vector(mid)) wolffd@0: index=mid; wolffd@0: return; wolffd@0: elseif (value>vector(mid)) wolffd@0: begin_index=mid+1; wolffd@0: else wolffd@0: end_index=mid-1; wolffd@0: end wolffd@0: end wolffd@0: end wolffd@0: return;