?? demo_rbf_rt_1.m
字號:
function [mydemo, cleanup] = demo_rbf_rt_1%% Demo of hybrid RBF and regression tree method.%% Version 1 (special order to selections).%% Initialise number of chunks in mydemo.n = 0;n = n + 1;mydemo(n) = struct( ... 'comments', {{ 'This is the demo for the rbf_rt_1 method.', ... '-----------------------------------------', ... '', ... 'rbf_rt_1 is an algorithm for regression and classification', ... 'which combines RBF networks, regression trees and a special', ... 'kind of subset selection.'}}, ... 'commands', '', ... 'question', '', ... 'optional', '');n = n + 1;mydemo(n) = struct( ... 'comments', 'First, let''s try the method on a relatively easy 1D problem.', ... 'commands', '', ... 'question', 'Please choose either ''sine1'' or ''hermite''.', ... 'optional', {{'sine1', 'hermite'}});n = n + 1;mydemo(n) = struct( ... 'comments', {{ ... 'Okay, you chose ''answer''. We''ll next get an instance of', ... 'a training set for that problem and take a look at it.'}}, ... 'commands', {{ ... '[x, y, dconf] = get_data(''answer'');', ... 'fig = get_fig(''rbf_rt_1 demo'');', ... 'hold off', ... 'plot(x, y, ''r*'')', ... '%set(gca, ''XLim'', [dconf.x1 dconf.x2])', ... '%set(gca, ''YLim'', [floor(min(y)) ceil(max(y))])', ... '%set(gca, ''XTick'', dconf.x1:dconf.x2)', ... '%set(gca, ''YTick'', floor(min(y)):ceil(max(y)))', ... '%xlabel(''x'', ''FontSize'', 16)', ... '%ylabel(''y'', ''FontSize'', 16, ''Rotation'', 0)'}}, ... 'question', '', ... 'optional', '');n = n + 1;mydemo(n) = struct( ... 'comments', {{ ... 'We''ll also get an uncorrupted (zero noise), ordered test set', ... 'of 400 samples which we can use to judge the accuracy of', ... 'rbf_rt_1 when we apply it to the training set.'}}, ... 'commands', {{ ... 'dconf.std = 0;', ... 'dconf.ord = 1;', ... 'dconf.p = 400;', ... '[xt, yt] = get_data(dconf);', ... 'hold on', ... 'plot(xt, yt, ''b-'', ''LineWidth'', 2)'}}, ... 'question', '', ... 'optional', '');n = n + 1;mydemo(n) = struct( ... 'comments', {{ ... 'Now we''ll run the method on the training set (x,y). rbf_rt_1', ... 'will return the centres (c), radii (r) and weights (w) of an', ... 'RBF network, together with some auxiliary information in info', ... 'and it''s control parameters in conf. For now, we''ll let', ... 'rbf_rt_1 choose default values for all its control parameters.', ... '', ... 'This may take a few seconds.'}}, ... 'commands', '[c, r, w, info, conf] = rbf_rt_1(x, y);', ... 'question', '', ... 'optional', '');n = n + 1;mydemo(n) = struct( ... 'comments', {{ ... 'So what does the model built by rbf_rt_1 predict as the outputs', ... 'over the test set inputs (xt)? We can use rbf_dm to get the', ... 'design matrix of the test set and then it''s just a matter of', ... 'multiplying this by the weights.'}}, ... 'commands', {{ ... 'Ht = rbf_dm(xt, c, r);', ... 'ft = Ht * w;', ... 'plot(xt, ft, ''m-'', ''LineWidth'', 2)'}}, ... 'question', '', ... 'optional', '');n = n + 1;mydemo(n) = struct( ... 'comments', {{ ... 'The algorithm which rbf_rt_1 uses involves a regression tree.', ... 'The tree itself is only used as an intermediate data structure', ... 'on the way to producing an RBF network and is not likely to be', ... 'an accurate predictor. Nevertheless, it can be illuminating to', ... 'see the tree''s predictions and to this end rbf_rt_1 returns a', ... 'tree in the info structure and the routine pred_tree is available', ... 'to make predictions from inputs such as the xt of our test set.', ... 'Each horizontal line in the plot corresponds to one leaf node', ... 'in the tree.'}}, ... 'commands', {{ ... 'tt = pred_tree(info.tree, xt);', ... 'hold off', ... 'plot(x, y, ''r*'')', ... '%set(gca, ''XLim'', [dconf.x1 dconf.x2])', ... '%set(gca, ''YLim'', [floor(min(y)) ceil(max(y))])', ... '%set(gca, ''XTick'', dconf.x1:dconf.x2)', ... '%set(gca, ''YTick'', floor(min(y)):ceil(max(y)))', ... '%xlabel(''x'', ''FontSize'', 16)', ... '%ylabel(''y'', ''FontSize'', 16, ''Rotation'', 0)', ... 'hold on', ... 'plot(xt, tt, ''m-'', ''LineWidth'', 2)'}}, ... 'question', '', ... 'optional', '');n = n + 1;mydemo(n) = struct( ... 'comments', {{ ... 'Some of the tree nodes, including non-leaf nodes, are turned', ... 'into radial basis functions in the final network. The centres', ... 'of the functions correspond to the centres of the tree nodes', ... 'and the function widths correspond to the node widths except', ... 'that they are also scaled by the parameter info.scale. This', ... 'value was choosen as the best alternative from the list in', ... 'in conf.scales.', ... '', ... 'You can see the RBFs are a mixture of wide and narrow, relecting', ... 'the different node sizes at different levels of the tree.'}}, ... 'commands', {{ ... 'disp(conf.scales)', ... 'disp(info.scale)', ... 'hold off', ... 'plot(xt, Ht, ''r-'')', ... '%set(gca, ''XLim'', [dconf.x1 dconf.x2])', ... '%set(gca, ''YLim'', [0 1])', ... '%set(gca, ''XTick'', dconf.x1:dconf.x2)', ... '%set(gca, ''YTick'', [0 1])', ... '%xlabel(''x'', ''FontSize'', 16)', ... '%ylabel(''h_j(x)'', ''FontSize'', 16)'}}, ... 'question', '', ... 'optional', '');n = n + 1;mydemo(n) = struct( ... 'comments', {{ ... 'We can alo plot the basis functions after they''ve been', ... 'multiplied by the weights and show how they combine to', ... 'form the model of the function. If any of the weights are', ... 'large the vertical scale in the plot will be increased and', ... 'it might not be so easy to see the function anymore.'}}, ... 'commands', {{ ... 'Bt = Ht .* w(:,ones(size(Ht,1),1))'';', ... '%y1 = min([min(min(Bt)) min(y)]);', ... '%y2 = max([max(max(Bt)) max(y)]);', ... '%dy = 10^floor(log10(y2 - y1));', ... '%y1 = dy * floor(y1 / dy);', ... '%y2 = dy * ceil(y2 / dy);', ... 'hold off', ... 'plot(x, y, ''r*'')', ... '%set(gca, ''XLim'', [dconf.x1 dconf.x2])', ... '%set(gca, ''YLim'', [y1 y2])', ... '%set(gca, ''XTick'', dconf.x1:dconf.x2)', ... '%set(gca, ''YTick'', y1:dy:y2)', ... '%xlabel(''x'', ''FontSize'', 16)', ... '%ylabel(''y'', ''FontSize'', 16, ''Rotation'', 0)', ... 'hold on', ... 'plot(xt, Bt, ''r-'')', ... 'plot(xt, ft, ''m-'', ''LineWidth'', 2)'}}, ... 'question', '', ...
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -