Code covered by the BSD License  

Highlights from
Statistical Learning Toolbox

from Statistical Learning Toolbox by Dahua Lin
Functions for statistical learning, pattern recognition and computer vision, covering many topics.

Description of edl_batchexp
Home > sltoolbox > ExpDL > edl_batchexp.m

edl_batchexp

PURPOSE ^

EDL_BATCHEXP Performs Batch experiments according to scheme

SYNOPSIS ^

function edl_batchexp(expfun, scrpath, env, logger, filter, runopt)

DESCRIPTION ^

EDL_BATCHEXP Performs Batch experiments according to scheme

 $ Syntax $
   - edl_batchexp(expfun, scrpath, env, logger)
   - edl_batchexp(expfun, scrpath, env, logger, filter, runopt)

 $ Arguments $
   - expfun:   the experiment function
   - scrpath:  the absolute script path
   - env:      the environment configuration
   - logger:   the logger to log experiment information
               (if not specified, it will create a default one)
   - filter:   the filtering function (default = [])
               it can also be a integer array specifying which 
               experiments to run.
   - runopt:   the running option
               'restart':  run all specified experiments 
                           (default follows edl_batchexp)
               'resume':   run the experiments that not succeeded

 $ Description $
   - edl_batchexp(expfun, scrpath, env) performs a batch of experiments 
     according to the properties list in sch and the environment variables. 

   - edl_batchexp(expfun, scrpath, env, filter) additionaly uses a filter 
     function to select a subset of experiments from sch to run. The filter
     function should receive one argument as the property struct, and
     outputs true or false.

 $ History $
   - Created by Dahua Lin, on Aug 10th, 2006
   - Modified by Dahua Lin, on Aug 13rd, 2006
       - Based on new EDL specification

CROSS-REFERENCE INFORMATION ^

This function calls:
  • edl_readctrlfile EDL_READCTRLFILE Reads in a control file
  • edl_readscript EDL_READSCRIPT Reads in a EDL script
  • edl_updatectrlfile EDL_UPDATECTRLFILE Updates the status in a control file
  • incindent INCINDENT Increases the indent by a specified amount
  • sllog SLLOG Constructs a logger
  • write WRITE Writes message to a logger
  • writeblank WRITEBLANK Writes a blank line to log
  • writeinfo WRITEINFO Writes information to logger without time-stamp
  • slfilepart SLFILEPARTS Extracts a specified part of a file path string
  • raise_lackinput RAISE_LACKINPUT Raises an error indicating lack of input argument
  • sladdpath SLADDPATH Adds dirpath to precede the filenames
This function is called by:
  • edl_go EDL_GO The Top interface for doing experiments in EDL

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function edl_batchexp(expfun, scrpath, env, logger, filter, runopt)
0002 %EDL_BATCHEXP Performs Batch experiments according to scheme
0003 %
0004 % $ Syntax $
0005 %   - edl_batchexp(expfun, scrpath, env, logger)
0006 %   - edl_batchexp(expfun, scrpath, env, logger, filter, runopt)
0007 %
0008 % $ Arguments $
0009 %   - expfun:   the experiment function
0010 %   - scrpath:  the absolute script path
0011 %   - env:      the environment configuration
0012 %   - logger:   the logger to log experiment information
0013 %               (if not specified, it will create a default one)
0014 %   - filter:   the filtering function (default = [])
0015 %               it can also be a integer array specifying which
0016 %               experiments to run.
0017 %   - runopt:   the running option
0018 %               'restart':  run all specified experiments
0019 %                           (default follows edl_batchexp)
0020 %               'resume':   run the experiments that not succeeded
0021 %
0022 % $ Description $
0023 %   - edl_batchexp(expfun, scrpath, env) performs a batch of experiments
0024 %     according to the properties list in sch and the environment variables.
0025 %
0026 %   - edl_batchexp(expfun, scrpath, env, filter) additionaly uses a filter
0027 %     function to select a subset of experiments from sch to run. The filter
0028 %     function should receive one argument as the property struct, and
0029 %     outputs true or false.
0030 %
0031 % $ History $
0032 %   - Created by Dahua Lin, on Aug 10th, 2006
0033 %   - Modified by Dahua Lin, on Aug 13rd, 2006
0034 %       - Based on new EDL specification
0035 %
0036 
0037 %% Parse and verify input arguments
0038 
0039 if nargin < 3
0040     raise_lackinput('edl_batchexp', 3);
0041 end
0042 
0043 if nargin < 4 || isempty(logger)
0044     logger = sllog();
0045 end
0046 
0047 if nargin < 5
0048     filter = [];
0049 end
0050 
0051 if nargin < 6 || isempty(runopt)
0052     runopt = 'restart';
0053 end
0054 
0055      
0056 
0057 %% Main Skeleton
0058 
0059 % prepare configuration
0060 [copts, sch] = prepare_configuration(scrpath, logger, filter, runopt);
0061 
0062 % do experiments
0063 do_experiments(expfun, copts, sch, env, logger);
0064 
0065 % finalize
0066 write(logger, 'Experiments completed.');
0067 
0068 
0069 %% Core routines
0070 
0071 function [copts, sch] = prepare_configuration(scrpath, logger, filter, runopt)
0072 
0073 switch runopt
0074     case 'restart'
0075         is_resume = false;
0076     case 'resume'
0077         is_resume = true;
0078     otherwise
0079         error('edl:interperror', ...
0080             'Invalid running option %s', runopt);
0081 end
0082 
0083 
0084 write(logger, 'Prepare experiment configurations');
0085 
0086 script = edl_readscript(scrpath);
0087 scrparent = slfilepart(scrpath, 'parent');
0088 
0089 copts.guid = script.attribs.guid;
0090 copts.workdir = script.attribs.workdir;
0091 copts.ctrlpath = sladdpath(script.attribs.ctrlpath, scrparent);
0092 
0093 logger = incindent(logger, 1);
0094 writeinfo(logger, 'GUID = %s', copts.guid);
0095 writeinfo(logger, 'workdir root = %s', copts.workdir);
0096 writeinfo(logger, 'control path = %s', copts.ctrlpath);
0097 
0098 sch = script.entries;
0099 
0100 if ~isempty(filter)
0101     writeinfo(logger, 'filtered scheme = true');
0102     sch = filter_sch(sch, filter);
0103 end
0104 
0105 writeinfo(logger, 'running mode = %s', runopt);
0106 if is_resume
0107     sch = filter_sch_runopt(sch, copts.ctrlpath);
0108 end
0109 
0110 writeinfo(logger, 'number of experiments: %d', length(sch));
0111 writeblank(logger);
0112 
0113 
0114 function sch = filter_sch(sch, filter)
0115 
0116 n = length(sch);
0117 
0118 is_selected = false(n, 1);
0119 
0120 if isnumeric(filter)
0121     is_selected(filter) = true;
0122 else
0123     for i = 1 : n
0124         is_selected(i) = feval(filter, sch(i));
0125     end
0126 end
0127 
0128 if ~all(is_selected)
0129     sch = sch(is_selected);
0130 end
0131 
0132 function sch = filter_sch_runopt(sch, ctrlpath)
0133 
0134 n = length(sch);
0135 
0136 if n > 0
0137     C = edl_readctrlfile(ctrlpath);
0138     is_disabled = false(n, 1);
0139     
0140     for i = 1 : n
0141         idx = sch(i).internal_index;
0142         if strcmpi(C.status{idx}, 'succeed')
0143             is_disabled(i) = true;
0144         end        
0145     end
0146 end
0147 
0148 
0149 if any(is_disabled)
0150     sch = sch(~is_disabled);
0151 end
0152 
0153 
0154 
0155 function do_experiments(expfun, copts, sch, env, logger)
0156 
0157 n = length(sch);
0158 
0159 for i = 1 : n
0160     
0161     cursch = sch(i);
0162     internal_index = cursch.internal_index;
0163     
0164     write(logger, 'Enter experiment %d / %d (internal index = %d)', i, n, internal_index);
0165     
0166     try
0167         feval(expfun, ...
0168             cursch, ...
0169             env, ...
0170             incindent(logger, 1));
0171         
0172         edl_updatectrlfile(copts.guid, copts.ctrlpath, internal_index, 'succeed');
0173         write(logger, 'experiment succeeded');
0174         writeblank(logger);
0175         
0176     catch        
0177         write(logger, 'experiment failed');                
0178         writeblank(logger);
0179         edl_updatectrlfile(copts.guid, copts.ctrlpath, internal_index, 'failed');
0180         
0181         rethrow(lasterror);
0182     end
0183             
0184 end
0185 
0186

Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003

Contact us at files@mathworks.com