Amortized optimization, also called learning to optimize, trains a machine-learning model to predict optimal or near-optimal solutions for repeated optimization problems. It shifts computation from repeatedly solving each instance toward training and fast inference. section 11.6
A supervised-learning workflow can:
- Represent each optimization problem through its parameters. section 11.6
- Train a model to map those parameters to a candidate solution. section 11.6
Optimizing a function on a sphere
For functions defined over the earth or another spherical space, the model predicts a point on the unit 2-sphere. Celestial-to-Euclidean conversion represents right ascension and declination as three-dimensional coordinates; the trained model then produces candidate extreme points. section 11.6
Listing 11.3 Solving a function optimization problem using supervised learning
import torch
from torch import nn
import numpy as np
from tqdm import tqdm
import matplotlib.pyplot as plt
def celestial_to_euclidean(ra, dec): #1
x = np.cos(dec)*np.cos(ra)
y = np.cos(dec)*np.sin(ra)
z = np.sin(dec)
return x, y, z
def euclidean_to_celestial(x, y, z): #2
sindec = z
cosdec = (x*x + y*y).sqrt()
sinra = y / cosdec
cosra = x / cosdec
ra = torch.atan2(sinra, cosra)
dec = torch.atan2(sindec, cosdec)
return ra, dec
def sphere_dist(x,y): #3
if x.ndim == 1:
x = x.unsqueeze(0)
if y.ndim == 1:
y = y.unsqueeze(0)
assert x.ndim == y.ndim == 2
inner = (x*y).sum(-1)
return torch.arccos(inner)
Inspect the conversion functions and spherical-distance calculation used to represent and compare candidate solutions. section 11.6
