Code covered by the BSD License  

Highlights from
Table Breakpoint Optimization

image thumbnail

Table Breakpoint Optimization

by

 

04 Apr 2012 (Updated )

A set of tools for finding the best way to reduce the size of a table.

find_best_table_2de(...
function [x_f, y_f, z_f, mse_f, me_f] = find_best_table_2de(...
                                      x_0, y_0, z_0, ...
                                      mse_target, max_error, ...
                                      method)

%% find_best_table_2de
%
% This function finds the best way to reduce the size of a table to the
% so that the smaller table matches the original within specified error 
% bounds. That is, suppose you had a table of 100-by-100 points, but wanted
% to find the smallest table that had no more than 1.5 units of mean 
% squared error. This function would find how many points are necessary 
% along each axis to accomplish this and where those points go. "Goodness"
% will be measured by the difference between the original table and the new
% table sampled at the original data points. See find_best_table_demo.m for
% examples.
% 
% Inputs:
%   x_0        Array of values for the first independent variable
%   y_0        Array of values for the second indepdendent variable
%   z_0        Matrix of values for the dependent variable for all x_0 and
%              y_0 using meshgrid-style syntax (e.g., z_0(2, 3) corresponds
%              to x_0(3) and y_0(2)).
%   mse_target Target mean squared error
%   method     Interpolation method to use, e.g., 'linear' (help interp2)
% 
% Outputs:
%   x_f    Best division of first independent variable found
%   y_f    Best division of second independent variable found
%   z_f    Resulting fit of z_0 on x_f and y_f
%   mse_f  Mean square error of final table
%
% This builds off of work by Richard Willey, Stuart Kozola, Eric Johnson, 
% Sarah Zaranek, and Peter Maloney at The MathWorks, Inc.
%
% Requires the Optimization Toolbox (TM).
% Supports the Parallel Computing Toolbox (TM).
%
%  Tucker McClure @ The MathWorks
%  Copyright 2013 The MathWorks, Inc.
           
    % Default to linear interpolation.
    if nargin < 6, method = 'linear'; end;
    if nargin == 5 && ischar(max_error)
        method = max_error;
        max_error = inf;
    end
    if nargin == 4 || isempty(max_error), max_error = inf;  end;
    if isempty(mse_target),               mse_target = inf; end;

    % Just call the n-dimensional version. This file is here for backwards
    % compatibility.
    [x_fs, z_f, mse_f, me_f] = find_best_table_nde({x_0, y_0}, ...
                                                   z_0', ...
                                                   mse_target, ...
                                                   max_error, ...
                                                   method);
                                                       
    % n-D interpolation uses ndgrid format; 2d used meshgrid format at its
    % release, so we'll preserve that for compatibility.
	z_f = z_f';
    
    % Separate the x and y breakpoints.
    x_f = x_fs{1};
    y_f = x_fs{2};
    
end

Contact us