Diego Sandoval
whoami
?“ Optimization is what you (want/try to) do with your salary at the end of the month.
Best possible [under constraints]
The main difference is that mathematical optimization gives you a guarantee.
What is the maximum area that can be bounded with a curve of fixed length $L$?
$$ A \le \frac{L^{2}}{4\pi} $$
$$ A = \frac{L^{2}}{4\pi}? $$
$$ \iff A_{\bullet} = \frac{L_{\circ} ^{2}}{4\pi} $$
Queen of Carthāgō
Let’s do some counterfactual reasoning:
What would have Dido do had the king impossed the constraint that the shape had to be rectangular?
Given a rectangle with perimeter $L$, what’s the relation between $\ell$ and $w$ that yields the maximum area?
$$ \begin{aligned} & \max_{\ell, w} & & \ell w \\ & \text{subject to} & & 2\ell + 2w = L \end{aligned} $$
Euclid (~300 BC) found that the relation that yields the maximum area is $w = \ell$, i.e., a square.
$$ \begin{aligned} & \max_{\ell, w} & & \ell w \\ & \text{s.t.} & & 2\ell + 2w = L \end{aligned} $$
$$ \ell = \frac{L}{2}- w $$
$$ \begin{aligned} & \max_{w} & & -w^2 + \frac{L}{2}w \\ \end{aligned} $$
Optimization
$f(w)=-w^2 + \frac{L}{2} w$
Optimization $\to$ calculus $\to$ derivatives
$f(w)=-w^2 + \frac{L}{2} w$
$$ \begin{aligned} & \max_{w} & & -w^2 + \frac{L}{2}w \\ \end{aligned} $$
$$ \frac{df}{dw} = -2w + \frac{L}{2} = 0 $$
$$ L = 4w $$
$$ 2w + 2\ell = L = 4w $$
$$ w = \ell \quad \blacksquare $$
$\mathbf{Q} = \mathbf{Q} - \frac{\mathbf{Q\gamma \gamma^{T} Q}}{\mathbf{\gamma^{T}Q\gamma}} + \frac{\mathbf{\delta \delta^{T}}}{ \mathbf{\delta^{T} \gamma}}$
Q = Q - (Q @ gamma @ gamma.T @ Q)/(gamma.T @ Q @ gamma)\
+ (delta @ delta.T)/(delta.T @ gamma)
Q = Q - Q*γ*γ'*Q / (γ'*Q*γ) + δδ' / (δ'γ)
function euclid(α, β)
return √(α^2 + β^2)
end
euclid(3, 4)
5
function 🦄(α, β)
return √(α^2 + β^2)
end
🦄(3, 4)
5
# A bit off-topic ...
[Mojo] hello.🔥
$$ \begin{aligned} & \max_{\ell, w} & & \ell w \\ & \text{subject to} & & 2w + 2\ell = L \end{aligned} $$
@variable(model, w >= 0)
@variable(model, ℓ >= 0)
@objective(model, Max, ℓ*w)
@constraint(model, 2w + 2ℓ == L)
Linear Regression $\to$ Least Squares [R1] [R2]
$$ \begin{align*} & \min_{\color{red}{\mathbf{\beta}}} & & \sum_{i=1} ^{n} \big(y_i - f(x_i, \mathbf{\beta})\big)^2 \end{align*} $$
$$ \begin{align*} & \min_{\color{red}{\mathbf{\beta}}} & & \sum_{i=1} ^{n} \big(y_i - f(x_i, \mathbf{\beta})\big)^2 \end{align*} $$
$$ \begin{align*} \color{red}{\mathbf{\beta}} &= (\mathbf{X}^{\top} \mathbf{X})^{-1} \mathbf{X}^{\top}\mathbf{y} \end{align*} $$
$$ \begin{align*} \color{red}{\beta_0} &= 113.88 \\ \color{red}{\beta_1} &= 0.9 \\ \end{align*} $$
$$ \text{Posterior} = \frac{\text{Probability of the data} \times \text{Prior}}{\text{Average probability of the data}} $$
$$ \begin{align*} \beta_0 & \sim \text{Normal}(178, 20)\\ \beta_1 & \sim \text{Log-Normal}(0,1)\\ \sigma & \sim \text{Uniform}(0, 50)\\ \end{align*} $$
$$ \begin{align*} \mu_i & = \beta_0 + \beta_1 (x_i - \bar{x})\\ \text{height} & \sim \text{Normal} (\mu_i, \sigma)\\ \end{align*} $$
Distribution of $\color{red}{\beta_1}$
def model(weight, height):
b0 = numpyro.sample("b0", dist.Normal(178, 20))
b1 = numpyro.sample("b1", dist.LogNormal(0, 1))
sigma = numpyro.sample("sigma", dist.Uniform(0, 50))
mu = b0 + b1 * (weight - jnp.mean(weight))
numpyro.sample("height", dist.Normal(mu, sigma), obs=height)
Critical points, multiple minima
Constrained optimization $\to$ $\chi \in [a,b]$
$ \max \quad f(x) \equiv \min \quad -f(x)$