function pred = apply_tree_final( forest, NaNNbre, xtest_rk, xtrain_rk, xtest_rk_normalized, xtrain_rk_normalized_sorted ) % APPLY_TREE calculates a single tree's contribution to the prediction % % pred = apply_tree( tree, xtrain, NaNNbre) calculates the contributions % from tree on data in xtrain. NaNNbre is the number of non-NaN % entries in each column of xtrain. % % pred = apply_tree( tree, xtrain, NaNNbre, xtrain_normalized) allows the % user to input xtrain_normalized, which is the value of xtrain if it % were used to generate a normal variable with zero mean and unit % standard deviation. This will speed up the function. % % tree is a vector has the following parameters % - 1-3: Variables indices for first three nodes % - 4-5: Threshods for nodes 1 and 2 % - 6: slope % - 7-9 : missing value param for nodes 1 to 3 % - 10 : architechture type (1,2,3,4), i.e. location of the final node in the tree % - 11: intercept % $LastChangedBy: alistair $ % $LastChangedDate: 2012-05-16 13:48:37 +0100 (Wed, 16 May 2012) $ % $Revision: 10 $ % Originally written on GLNXA64 by Alistair Johnson, 09-May-2012 16:26:13 % Contact: alistairewj@gmail.com % treeidx = 1; % tree = forest(1,:,treeidx); Ntrees = size(forest,2); if Ntrees > 1 Ntrees = Ntrees-1; % do not include intercept in forest calcs end %% APPLY TREE N = size(xtest_rk,1); %% First Node % first split value [0,1] * number of non-nan values i1 = forest(1,1:Ntrees); i4 = forest(4,1:Ntrees); i7 = forest(7,1:Ntrees); i1_NaN = NaNNbre(i1); obs1 = bsxfun(@gt,xtest_rk(:,i1),i4.*i1_NaN); % get observations in 1st split % obs1 = xtrain(:,tree(1)) > tree(4)*NaNNbre(tree(1)); % rank greater than... % if number of NaNs * missingness for that param < number of values in the split % if(NaNNbre(tree(1))*tree(7)tree(5)*NaNNbre(tree(2)); obs2 = bsxfun(@gt,xtest_rk(:,i2),i5.*i2_NaN); % if(NaNNbre(tree(2))*tree(8)