Home > manopt > tools > surfprofile.m

# surfprofile

## PURPOSE

Plot the cost function as a surface over a 2-dimensional subspace.

## SYNOPSIS

function costs = surfprofile(problem, x, d1, d2, t1, t2)

## DESCRIPTION

``` Plot the cost function as a surface over a 2-dimensional subspace.

function surfprofile(problem, x, d1, d2, t1, t2)
function costs = surfprofile(problem, x, d1, d2, t1, t2)

Evaluates the cost function at points

gamma(t1, t2) = exponential_x(t1*d1 + t2*d2)

where the exponential map at x is specified by problem.M.exp (retr is
used instead if needed). d1 and d2 are two tangent vectors to problem.M
at the point x. The values assigned to t1 and t2 are as specified in the
two input vectors t1 and t2.

If the function is called with an output, the plot is not drawn and the
values of the cost are returned in a matrix of size
length(t1)*length(t2). To plot a surf, call surf(t1, t2, costs.') (notice
the transpose).

If x is omitted, a point is generated at random. If d1 is omitted, a
random tangent vector at x is generated. If d2 is omitted, a random
tangent vector at x is generated, orthogonally to d1. If t1, t2 are
omitted, they are generated with linspace's in [-1, 1].```

## CROSS-REFERENCE INFORMATION

This function calls:
• StoreDB
• canGetCost Checks whether the cost function can be computed for a problem structure.
• getCost Computes the cost function at x.
This function is called by:

## SOURCE CODE

```0001 function costs = surfprofile(problem, x, d1, d2, t1, t2)
0002 % Plot the cost function as a surface over a 2-dimensional subspace.
0003 %
0004 % function surfprofile(problem, x, d1, d2, t1, t2)
0005 % function costs = surfprofile(problem, x, d1, d2, t1, t2)
0006 %
0007 % Evaluates the cost function at points
0008 %
0009 %   gamma(t1, t2) = exponential_x(t1*d1 + t2*d2)
0010 %
0011 % where the exponential map at x is specified by problem.M.exp (retr is
0012 % used instead if needed). d1 and d2 are two tangent vectors to problem.M
0013 % at the point x. The values assigned to t1 and t2 are as specified in the
0014 % two input vectors t1 and t2.
0015 %
0016 % If the function is called with an output, the plot is not drawn and the
0017 % values of the cost are returned in a matrix of size
0018 % length(t1)*length(t2). To plot a surf, call surf(t1, t2, costs.') (notice
0019 % the transpose).
0020 %
0021 % If x is omitted, a point is generated at random. If d1 is omitted, a
0022 % random tangent vector at x is generated. If d2 is omitted, a random
0023 % tangent vector at x is generated, orthogonally to d1. If t1, t2 are
0024 % omitted, they are generated with linspace's in [-1, 1].
0025
0026 % This file is part of Manopt: www.manopt.org.
0027 % Original author: Nicolas Boumal, Sep. 1, 2014.
0028 % Contributors:
0029 % Change log:
0030 %
0031 %   April 3, 2015 (NB):
0032 %       Works with the new StoreDB class system.
0033 %
0034 %   Nov. 12, 2016 (NB):
0035 %       Most inputs are now optional.
0036
0037     % Verify that the problem description is sufficient.
0038     if ~canGetCost(problem)
0039         error('It seems no cost was provided.');
0040     end
0041
0042
0043     if ~exist('x', 'var') || isempty(x)
0044         x = problem.M.rand();
0045         if (exist('d1', 'var') && ~isempty(d1)) || ...
0046            (exist('d2', 'var') && ~isempty(d2))
0047             error('If x is omitted, d1, d2 should not be specified.');
0048         end
0049     end
0050     if ~exist('d1', 'var') || isempty(d1)
0051         d1 = problem.M.randvec(x);
0052     end
0053     if ~exist('d2', 'var') || isempty(d2)
0054         d2 = problem.M.randvec(x);
0055         % Make it orthogonal to d1
0056         coeff = problem.M.inner(x, d1, d2) / problem.M.inner(x, d1, d1);
0057         d2 = problem.M.lincomb(x, 1, d2, -coeff, d1);
0058     end
0059     if ~exist('t1', 'var') || isempty(t1)
0060         t1 = linspace(-1, 1, 51);
0061     end
0062     if ~exist('t2', 'var') || isempty(t2)
0063         t2 = linspace(-1, 1, 51);
0064     end
0065
0066
0067     if isfield(problem.M, 'exp')
0068         expo = problem.M.exp;
0069         str = 'Exp';
0070     else
0071         expo = problem.M.retr;
0072         str = 'Retr';
0073     end
0074
0075     storedb = StoreDB();
0076     linesearch_fun = @(ta, tb) getCost(problem, ...
0077                          expo(x, problem.M.lincomb(x, ta, d1, tb, d2)), ...
0078                          storedb);
0079
0080     costs = zeros(length(t1), length(t2));
0081     for i = 1 : length(t1)
0082         for j = 1 : length(t2)
0083             costs(i, j) = linesearch_fun(t1(i), t2(j));
0084         end
0085     end
0086
0087     if nargout == 0
0088         surf(t1, t2, costs.');
0089         xlabel('t1');
0090         ylabel('t2');
0091         zlabel(['f(' str '_x(t1*d1+t2*d2))']);
0092     end
0093
0094 end```

Generated on Fri 08-Sep-2017 12:43:19 by m2html © 2005