1 %> @brief Base Block 
class 
    3     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
    4     %%% Potentially re-set when inheriting a 
block 
    5     properties(SetAccess=
protected)
 
    6         %> =
'irdata'. (High-Level setting) Class or classes (can be 
string or cell of strings) that the 
block can deal with.
 
    7         %> Allows 
for @c 
objtool and @c datatool to know (when appropriate) which blocks are applicable to the selected object(s).
 
    9         %> =0. (High-Level setting and 
internal function) Whether or not the 
block is bootable.
 
   11         %> =0. (High-Level + 
internal function). Whether or not the 
block can be trained, or completely non-data-based.
 
   14         %> =0. (
internal function). Whether or not the 
block accepts incremental training. The meaning is:
 
   15         %> @arg If YES, it means that the 
block can adapt/evolve everytime its train() method is called
 
   16         %> @arg If NO, the 
block can be trained only once, and calling its train() method many times can lead to unpredictable results
 
   20         %> =1. (internal function) If true, dataset number of features will be checked upon training and using. Ignored if o.flag_trainable is 0.
 
   22         %> =0. (internal function) If true, dataset number of observations will be checked upon training and using. Ignored if o.flag_trainable is 0.
 
   25         %> =0. (High-Level setting (@ref 
gencode)) Whether 
block allows/expects multiple objects 
as input.
 
   27         %> =1. (High-Level setting (@ref 
gencode)) Whether the 
block generates any output at all (counterexample: @ref 
vis blocks)
 
   30         %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
   31         %%% How to deal with the question of inliers/outliers!
 
   33         %> If true, train() will pass on to do_train() a dataset with inliers only.
 
   34         %> If this flag is true, @ref flag_train_require_inliers will be ignored, because @ref flag_train_inliers_only being true is one way to solve the "inliers requirement".
 
   35         flag_train_inliers_only = 0;
 
   37         %> =1. If true, train() will give an error if the dataset has outliers. This is true by default, because the developer should
 
   38         %> be aware of outliers being inputted into a training algorithm.
 
   39         flag_train_require_inliers = 1;
 
   43     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
   44     %%% Internal operation
 
   45     properties(SetAccess=protected)
 
   46         %> =-1. Number of features. Cleared at boot(), assigned or reinforced at train().
 
   48         %> =-1. Number of observations.
 
   50         %> =0. Set to 1 by train() if training is successful; set back to 0 after booting.
 
   52         %> =0. Set to 1 by boot() after booting the 
block 
   61     methods(Access=private)
 
   63         %block_assert_trained: Makes sure that the 
block is trained [before used]
 
   64         function o = assert_trained(o)
 
   65             if o.flag_trainable > 0 && ~o.flag_trained
 
   66                 irerror(sprintf('Tried to use 
block of class ´%s´ before training', class(o)));
 
   70         %block_assert_nf: Makes sure that the number of features is compatible with the 
block 
   71         function o = assert_nonf(o, data)
 
   72             if o.flag_trainable > 0
 
   74                     for i = 1:length(data)
 
   76                             irerror(sprintf('Incorrect number of features: %d (should be %d)', data(i).nf, o.nf));
 
   81                     for i = 1:length(data)
 
   83                             irerror(sprintf('Incorrect number of observations: %d (should be %d)', data(i).no, o.no));
 
   93     methods(Access=protected)
 
   94         % "do" method is for pure implementation of the related functionality, opposed to its public counterpart 
 
   95         % which deals with bureaucracy
 
   96         function o = do_train(o, data) %
#ok<INUSD> 
   99         % 
"do" method is 
for pure implementation of the related functionality, opposed to its 
public counterpart 
 
  100         % which deals with bureaucracy
 
  101         function data = do_use(o, data)
 
  105         %> @brief Boots the 
block 
  107         %> Abstract. Booting accounts for clearing any recordings; model structure; stored data etc from the 
object so that it can
 
  109         function o = do_boot(o)
 
  117             o.classtitle = 'Block';
 
  125         %> Abstract. Method to get the per-feature grades. BMTool stuff.
 
  126         function z = get_grades(o, params)
 
  127             irerror('Block does not calculate per-feature grades!');
 
  130         %> Abstract. Method to get 
block title based on passed parameters. BMTool stuff.
 
  131         function z = get_gradeslegend(o, params)
 
  139         %> @brief Applies 
block to data.
 
  140         function varargout = use(o, data)
 
  141             % BTW there is no point in the "o =" i.e. the assignment, because the 
block won't output itself anyway
 
  147             out = o.do_use(data);
 
  149                 % Default time recording
 
  155                 varargout = {o, out};
 
  160         %> @brief Trains 
block.
 
  161         function o = train(o, data, varargin)
 
  162             if o.flag_bootable && ~o.flag_booted
 
  163                 irerror('Block needs to be booted first!');
 
  166             if o.flag_trainable > 0
 
  167                 if o.flag_trained && o.flag_incrtrain
 
  171                 if (o.flag_train_inliers_only || o.flag_train_require_inliers) && any(data.classes < 0)
 
  172                     if o.flag_train_inliers_only
 
  175                         irerror(sprintf('Dataset contains rows with class < 0, but 
block of class "%s" requires dataset with inliers only (select inliers first)!', class(o)));
 
  179                 o.no = data(1).no; % Please note that if do_train() gives an error, this won't  have effect
 
  184                 o = o.do_train(data, varargin{:});
 
  186                     % Default time recording
 
  187                     o.time_train = toc(t);
 
  193         %> @brief Configures the structure to deal with 
new type of data
 
  195         %> Booting accounts 
for clearing any recordings; model structure; stored data etc from the 
object so that it can
 
Visualization base class. 
 
function data_select_inliers(in data)
 
Analysis Session (AS) base class. 
 
MATLAB code generation to create, boot, train and use blocks.