forked from saguo/Image_Classification_Randomforests
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathincrement.m
More file actions
34 lines (32 loc) · 1.32 KB
/
Copy pathincrement.m
File metadata and controls
34 lines (32 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
%%% Author: Zhaoming Zhang
function sroot = increment(sroot, data, Qx, clmax, depthmax, ratio, incre_func, train_func, test_func)
%% increment a given forest
% sroot: root of forest
% data: combined data of previously used data and increment data in ascending order
% Qx: index of increment data
% clmax: number of classes
% depthmax: maximum depth of tree
% ratio: maximum cut ratio, only used in RTST
% incre_fuc: specific function for tree increment
% train_func: specific function for spliting data in a node
% test_func: specific function for testing data in a node
datasize = length(Qx);
func_name = functions(incre_func);
for i = 1: length(sroot)
% randomly select 30% data
perm = randperm(datasize);
perm = perm(1: round(0.3*datasize));
Qxr = Qx(perm);
root = sroot{i};
root = subtree_size(root);
if strcmp(func_name.function, 'RTST')
root = uniform(root, 1 / root.nNode);
elseif strcmp(func_name.function, 'RTSTQ')
[root, quality_sum] = quality(root, 0);
root = normalize_cp(root, quality_sum);
end
root.Qx = [root.Qx, Qxr];
root.magnitude = length(root.Qx);
[root.PQ, root.entropy] = entropy(data, root.Qx, clmax); % compute the entropy of root
[sroot{i}, ~] = incre_func(root, data, Qxr, clmax, depthmax, ratio * root.nNode, train_func, test_func);
end