Function Repository Resource:

FindMinimumPlot

Source Notebook

Visualize the function evaluations done by FindMinimum

Contributed by: Wolfram Staff (with additional contributions by Jan Mangaldan)

ResourceFunction["FindMinimumPlot"][f,{x,xst}]

plots the steps and the points at which the function f and any of its derivatives are evaluated in FindMinimum[f,{x,xst}], superimposed on a plot of f versus x.

ResourceFunction["FindMinimumPlot"][f,{{x,xst},{y,yst}}]

plots the steps and the points at which the bivariate function f and any of its derivatives are evaluated, superimposed on a contour plot of f as a function of x and y.

ResourceFunction["FindMinimumPlot"][f,range,property]

returns the specified property.

Details

The argument property can be any of the following:
"Result"the result of FindMinimum
"Statistics"an association showing the number of steps and evaluations of the function and its derivatives
"Plot"the plot of the function and the evaluation points
Allassociation containing "Result", "Statistics" and "Plot"
ResourceFunction["FindMinimumPlot"] takes the same options as FindMinimum and Plot (in the one-dimensional case) or ContourPlot (in the two-dimensional case), with the following addition:
"EvaluationStyles"Automaticstyles used for the evaluation points
The "EvaluationStyles" option takes an association whose values correspond to the styles used for the evaluation points in the plot.
With the setting PlotLegendsAutomatic, ResourceFunction["FindMinimumPlot"] shows a legend for the evaluation points.

Examples

Basic Examples (2) 

Show the steps and function evaluations used in finding a local minimum of the function exp(x)+1/x:

In[1]:=
ResourceFunction["FindMinimumPlot"][Exp[x] + 1/x, {x, 1, 1.1}]
Out[1]=

Show the steps and function evaluations used in finding a local minimum of the function cos(x2-3y)+sin(x2+y2):

In[2]:=
ResourceFunction["FindMinimumPlot"][
 Cos[x^2 - 3 y] + Sin[x^2 + y^2], {{x, 1}, {y, 1}}]
Out[2]=

Scope (2) 

Use PlotLegends to display a legend for the evaluation points:

In[3]:=
ResourceFunction["FindMinimumPlot"][
 Cos[x^2 - 3 y] + Sin[x^2 + y^2], {{x, 1}, {y, 1}}, PlotLegends -> Automatic]
Out[3]=

Use a different minimization method from the default:

In[4]:=
ResourceFunction["FindMinimumPlot"][
 Cos[x^2 - 3 y] + Sin[x^2 + y^2], {{x, 1}, {y, 1}}, Method -> "ConjugateGradient", PlotLegends -> Automatic]
Out[4]=

Return the statistics of the evaluations done by FindMinimum:

In[5]:=
ResourceFunction["FindMinimumPlot"][
 Cos[x^2 - 3 y] + Sin[x^2 + y^2], {{x, 1}, {y, 1}}, "Statistics"]
Out[5]=

Return all properties:

In[6]:=
ResourceFunction["FindMinimumPlot"][
 Cos[x^2 - 3 y] + Sin[x^2 + y^2], {{x, 1}, {y, 1}}, All]
Out[6]=

Options (5) 

ColorFunction (1) 

Use a different ColorFunction setting:

In[7]:=
ResourceFunction[
 "FindMinimumPlot"][(x^2 - 3 y)^2 + Sin[x^2 + y^2]^2, {{x, 1}, {y, 1}}, ColorFunction -> "M10DefaultDensityGradient"]
Out[7]=

EvaluationStyles (2) 

Use "EvaluationStyles" to change the style used for the evaluation points:

In[8]:=
ResourceFunction["FindMinimumPlot"][
 Cos[x^2 - 3 y] + Sin[x^2 + y^2], {{x, 1}, {y, 1}}, "EvaluationStyles" -> <|{"Steps" -> Directive[Blue, Thin, PointSize[0.015]], "Function" -> Directive[Green, PointSize[0.02]], "Gradient" -> Directive[Red, PointSize[0.0325]], "Hessian" -> Directive[Cyan, PointSize[0.045]], "Solution" -> PointSize[0.055]}|>, Method -> "Newton", PlotLegends -> Automatic]
Out[8]=

Default styles are used if a particular style is left unspecified:

In[9]:=
ResourceFunction["FindMinimumPlot"][
 Cos[x^2 - 3 y] + Sin[x^2 + y^2], {{x, 1}, {y, 1}}, "EvaluationStyles" -> <|{"Steps" -> Directive[Blue, Thin, PointSize[0.015]], "Function" -> Directive[Green, PointSize[0.02]], "Solution" -> PointSize[0.055]}|>, Method -> "Newton", PlotLegends -> Automatic]
Out[9]=

Method (1) 

Compare different minimization methods:

In[10]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/5fa87129-24b2-4ec3-a597-0259753a504f"]
Out[10]=

PlotLegends (1) 

Show a legend for the evaluation points:

In[11]:=
ResourceFunction[
 "FindMinimumPlot"][(x^2 - 3 y)^2 + Sin[x^2 + y^2]^2, {{x, 1}, {y, 1}}, PlotLegends -> Automatic]
Out[11]=

Version History

  • 1.0.0 – 16 February 2021

Related Resources

License Information