Examples

This page demonstrates Globtim features with inline examples and visual results.

Runnable demo scripts

Self-contained scripts ship in the examples/ directory. Run any of them from a project that has Globtim installed (e.g. julia examples/custom_function_demo.jl):

ScriptWhat it shows
custom_function_demo.jlDefine a custom 2D objective, build the polynomial approximation, find critical points
quick_subdivision_demo.jlAdaptive subdivision on sphere / Rosenbrock / Rastrigin / anisotropic
domain_sweep_demo.jlSweep over domain sizes for a fixed objective
high_dimensional_demo.jl3D / 4D scaling behaviour
scalar_function_demo.jl1D scalar functions
sparsification_demo.jlPolynomial coefficient sparsification
anisotropic_grid_demo.jlAnisotropic Chebyshev / Legendre grids
basis_comparison.jlChebyshev vs Legendre nodes / convergence on the 1D Runge function

For an end-to-end tour across all three packages (find → refine → plot), see the Ecosystem Walkthrough.


Visual examples of Globtim finding critical points on standard benchmark functions.

Deuflhard

Deuflhard Function

Holder Table

Holder Table Function

Beale

Beale Function

Branin

Branin Function


Basic 2D Workflow

Core API sequence:

StepAPI Call
1. Define problemTestInput(f, dim=2, center=[0.0,0.0], sample_range=1.2)
2. Build polynomialConstructor(TR, degree)
3. Find critical ptssolve_polynomial_system(x, pol)
4. Process solutionsprocess_crit_pts(solutions, f, TR)
5. Analyze & classifyanalyze_critical_points(f, df, TR, enable_hessian=true)

Custom Objective Functions

Define any function accepting a vector x and returning a scalar:

my_function(x) = (x[1]^2 - 1)^2 + (x[2]^2 - 1)^2 + 0.1*sin(10*x[1]*x[2])

Statistical Analysis with Tables

The enhanced statistics and table rendering/export live in the GlobtimPostProcessing package, which consumes the df_enhanced DataFrame produced by analyze_critical_points:

using GlobtimPostProcessing
# render statistical tables and export to CSV / Markdown / LaTeX
export_analysis_tables(tables, "critical_point_analysis", output_dir; formats=[:csv, :markdown, :latex])

High-Dimensional Problems (3D/4D)

Tips:

  • Use AdaptivePrecision for accuracy/performance balance
  • Reduce polynomial degree as dimension increases (4D → degree 4-6)
  • Disable Hessian analysis for faster results: enable_hessian=false

Domain Exploration

Test different domain sizes to find all critical points:

TR = TestInput(f, dim=2, center=[0.0, 0.0], sample_range=r)      # uniform
TR = TestInput(f, dim=2, center=[0.0, 0.0], sample_range=[2.0, 1.0])  # rectangular

Visualization

For plotting the polynomial level set with critical points overlaid, use the GlobtimPlots package. Load a Makie backend (CairoMakie for static files, GLMakie for interactive windows) before calling any plot function:

using GlobtimPlots
using CairoMakie

apol = adapt_polynomial_data(pol)   # adapt globtim objects for plotting
ainp = adapt_problem_input(TR)
fig = cairo_plot_polyapprox_levelset(apol, ainp, df_enhanced, df_min)
CairoMakie.save("levelset.png", fig)

See the GlobtimPlots documentation for the full set of plot types (Morse spectra, subdivision partitions, convergence sweeps).

For post-experiment analysis (refinement, parameter recovery, campaign comparison), use GlobtimPostProcessing.


Polynomial Degree Comparison

Compare Chebyshev vs Legendre bases and analyze how polynomial degree affects approximation quality and critical point discovery. See the Polynomial Approximation page for theoretical background.


1D Functions with Scalar Input

Works with functions like sin, cos that expect scalar input:

f = x -> sin(3x) + 0.1*x^2
TR = TestInput(f, dim=1, center=[0.0], sample_range=π)

Basin Analysis

Analyze convergence basins for critical points. The df_min DataFrame includes:

  • basin_points - Number of points converging to this minimum
  • average_convergence_steps - Mean BFGS iterations
  • region_coverage_count - Spatial coverage metric

Next Steps