specfem::optimization

namespace optimization

This namespace contains optimization algorithms and related types.

The main interface is the optimize() function, which is overloaded for different algorithms and supports both numerical and user-provided gradients.

For implementing a new algorithm simply define a new tag struct (e.g., MyAlgorithm) and provide specializations of optimize() for that tag. This design allows for a clean separation of algorithms and a consistent user interface.

template<int N>
struct OptimizationResult

Result structure returned by optimization algorithms.

Template Parameters:

N – Number of optimization variables

template<typename AlgorithmTag, int N, typename Func, typename Options>
OptimizationResult<N> specfem::optimization::optimize(AlgorithmTag tag, Func &&objective, Options options)

Generic optimization interface for derivative-free optimization algorithms.

Provides optimization methods for unconstrained minimization problems. All algorithms operate on Kokkos::View arrays for device compatibility.

Example:

auto objective = [](auto x) { return x(0)*x(0) + x(1)*x(1); };
NelderMeadOptions<2> opts; opts.x0 = initial_guess; auto result =
optimize(NelderMeadSimplex{}, objective, opts);
Usage pattern:

  1. Select an algorithm tag (e.g., NelderMeadSimplex)

  2. Configure options (initial point, tolerances)

  3. Call optimize() with objective function

Note

Specializations for each algorithm tag are in separate headers.

Template Parameters:
  • AlgorithmTag – Algorithm selector (e.g., NelderMeadSimplex)

  • N – Dimension of optimization problem

  • Func – Objective function type: type_real(View<type_real[N]>)

  • Options – Algorithm-specific options structure

Parameters:
  • tag – Algorithm tag selecting the optimization method

  • objective – Function to minimize

  • options – Algorithm configuration and initial point

Returns:

OptimizationResult containing solution and diagnostics

template<typename AlgorithmTag, int N, typename Func, typename GradFunc, typename Options>
OptimizationResult<N> specfem::optimization::optimize(AlgorithmTag tag, Func &&objective, GradFunc &&gradient, Options options)

Generic optimization interface with user-provided gradient.

Provides optimization methods for unconstrained minimization problems. All algorithms operate on Kokkos::View arrays for device compatibility.

Example:

auto objective = [](auto x) { return x(0)*x(0) + x(1)*x(1); };
SteepestDescentOptions<2> opts; opts.x0 = initial_guess; auto result =
optimize(SteepestDescent{}, objective, gradient, opts);
Usage pattern:

  1. Select an algorithm tag (e.g., SteepestDescent)

  2. Configure options (initial point, tolerances)

  3. Call optimize() with objective function and gradient function

Note

Only supported by gradient-based algorithms (e.g., SteepestDescent).

Template Parameters:
  • AlgorithmTag – Algorithm selector (e.g., SteepestDescent)

  • N – Dimension of optimization problem

  • Func – Objective function type: type_real(View<type_real[N]>)

  • GradFunc – Gradient function type: void(View<type_real[N]> x, View<type_real[N]> grad_out)

  • Options – Algorithm-specific options structure

Parameters:
  • tag – Algorithm tag selecting the optimization method

  • objective – Function to minimize

  • gradient – Function computing gradient at a point

  • options – Algorithm configuration and initial point

Returns:

OptimizationResult containing solution and diagnostics

Algorithms

struct NelderMeadSimplex

Tag for Nelder-Mead simplex algorithm.

Derivative-free method suitable for non-smooth objective functions. Converges slowly but robustly for problems with few variables (N < 10).

See also

optimize(NelderMeadSimplex, Func &&objective, NelderMeadOptions<N> options)

struct SteepestDescent

Tag for steepest descent (gradient descent) algorithm.

First-order gradient-based method using backtracking line search. Computes gradient numerically via central finite differences. Faster than Nelder-Mead for smooth functions but requires differentiability.

See also

optimize(SteepestDescent, Func &&objective, SteepestDescentOptions<N> options)

See also

optimize(SteepestDescent, Func &&objective, GradFunc &&gradient, SteepestDescentOptions<N> options)

Note

This is mainly intended for educational purposes, just to show how to implement interfaces with and without gradients.