Home > atmlab > retrieval > spareice > RetrievalDatabaseProduct.m

RetrievalDatabaseProduct

PURPOSE ^

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

DOWNLOAD ^

RetrievalDatabaseProduct.m

SOURCE CODE ^

0001 classdef RetrievalDatabaseProduct < HomemadeDataset
0002     % base class for any product based on some atmospheric DB
0003     %
0004     % Subclasses may be NN-based, MCI-based, etc.
0005     %
0006     % See also: NNTrainedProduct, IceMusicNNIWP, InstrumentVisualiser
0007     
0008     properties
0009         
0010         % data means different things for different implementations.
0011         % e.g. for ANN, it's training data
0012         % for MCI, it's the database used in retrievals; even if these
0013         % classes don't retrieve, it's still of interest for reference
0014         data
0015         ice_axis;
0016         localcols
0017         selection
0018         
0019 %        chans
0020         
0021         chanstr
0022         freqstr
0023     end
0024     
0025     
0026     properties (Abstract, Constant)
0027         chans
0028         freqs
0029     end
0030     
0031     methods (Abstract)
0032         % set self.data, self.localcols
0033         
0034         [x, y] = evaluate_test_data(self, noise_level)
0035         
0036         getdata(self, varargin)
0037     end
0038     
0039     methods
0040         function self = RetrievalDatabaseProduct(varargin)
0041             self = self@HomemadeDataset(varargin{:});
0042             
0043             self.freqstr = sprintf('%s ', self.freqs{self.chans});
0044             self.chanstr = sprintf('%d', self.chans);
0045             
0046         end
0047          
0048         function limit_data(self)
0049             % sets self.selection to list of indices
0050             lims = struct();
0051             for fnc = fieldnames(self.targets)
0052                 fn = fnc{1};
0053                 if isfield(self.targets.(fn), 'lims')
0054                     lims.(fn) = self.targets.(fn).lims;
0055                 end
0056             end
0057             
0058             idx = collocation_restrain(self.data, limstruct2limmat(lims, self.localcols));
0059             
0060             % convert from logical to list-of-indices so I can more easily
0061             % sub-sample it
0062             %
0063             % 2013-06-12: stop this, just set trainInd directly instead
0064             
0065             idx = find(idx);
0066 %
0067 %             if length(idx) > self.maxsize
0068 %                 logtext(atmlab('OUT'), 'Reducing %d -> %d points\n', length(idx), self.maxsize);
0069 %                 self.selection = idx(unique(round(linspace(1, length(idx), self.maxsize))));
0070 %             else
0071                 self.selection = idx;
0072 %             end
0073         end            
0074         
0075         function [h_ax, h_cb] = plot_scatter_perf(self, x, y)
0076             
0077             %            freqstr = sprintf('%s ', self.freqs{self.chans});
0078             %            chanstr = sprintf('%d', self.chans);
0079             
0080             %           filt = (x>0) & (y>0) & isfinite(x) & isfinite(y);
0081             % build options-structure for scatter_density_plot
0082             op = self.opts;
0083             op.scatprops = []; % no scatter
0084             [h_ax, h_cb] = scatter_density_plot(x, y, op);
0085             
0086         end
0087         
0088     end
0089     
0090     methods (Static)
0091         function perf = binned_median_fractional_error(x, y, bins)
0092             % median fractional error
0093             perf = cellfun(@median, bin(log10(x), abs(y-x)./x, bins));
0094         end
0095         
0096         function perf = binned_mad(x, y, bins)
0097             % binned median absolute distance
0098             % see also: mad
0099             perf = cellfun(@(xx) mad(xx, 1), bin(log10(x), y, bins));
0100         end
0101     end
0102     
0103     
0104     methods (Static, Access = protected)
0105                 
0106         function [y, newcols] = select_and_prepare_data(dat, cols, S, homog)
0107             % select and transform fields
0108             %
0109             % IN
0110             %
0111             %   dat     matrix, typically single or double
0112             %   cols    structure describing columns of matrix
0113             %   S       structure with fields to be selected, each field
0114             %           must have a 'transform' member that is a function
0115             %           to be applied, or a 'process' member with
0116             %           {function, input_structures}
0117             %   homog   homogenise input, yes or no
0118             %
0119             % OUT
0120             %
0121             %   y       new data
0122             %   newcols correspondings cols
0123             
0124             fields = fieldnames(S);
0125             newcols = struct();
0126             %y = zeros(sum(cellfun(@(X) length(cols.(X)), fields)), size(dat, 1), class(dat));
0127             y = zeros(0, size(dat, 1), class(dat));
0128             i = 1;
0129             for k = 1:length(fields)
0130                 fn = fields{k};
0131                 %colrange = i:((i+length(cols.(fn)))-1);
0132                 % the user may want to input something to the neural
0133                 % network that is actually a combination of other fields,
0134                 % such as the difference between two fields.  To do so,
0135                 % they create 'process' which contains {processor(x, y),
0136                 % {struct_for_x, struct_for_y}} as a value.
0137                 if isfield(S.(fn), 'process') 
0138                     proc_input_names = fieldnames(S.(fn).process{2});
0139                     proc_inputs = cell(size(proc_input_names));
0140                     for n=1:length(proc_input_names)
0141                         name = proc_input_names{n};
0142                         srccols = cols.(name);
0143                         if isfield(S.(fn).process{2}.(name), 'chans')
0144                             srccols = srccols(S.(fn).process{2}.(name).chans);
0145                         end
0146                         proc_inputs{n} = S.(fn).process{2}.(name).transform(dat(:, srccols));
0147                     end
0148                     field_data = S.(fn).process{1}(proc_inputs{:});
0149                     if isfield(S.(fn), 'transform')
0150                         field_data = S.(fn).transform(field_data);
0151                     end
0152                     colrange = i:(i+min(size(field_data))-1);
0153                     y(colrange, :) = field_data.';
0154                     i = i + length(colrange);    
0155                     newcols.(fn) = colrange;
0156                 else
0157                     srccols = cols.(fn);
0158                     if isfield(S.(fn), 'chans') && length(S.(fn).chans) < length(srccols)
0159                         %colrange = colrange(S.(fn).chans);
0160                         srccols = srccols(S.(fn).chans);
0161                     end
0162                     colrange = i:(i+length(srccols)-1);
0163                     newcols.(fn) = colrange;
0164                     y(colrange, :) = S.(fn).transform(dat(:, srccols)).';
0165                     i = i + length(colrange);
0166                 end
0167             end
0168         end
0169                 
0170     end
0171 end

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005