Over next month, start thinking about how your interests relate with something we have covered or are going to cover
Least Squares, Convex Optimization, or Deep Learning/non-convex optimization
Ask me if you want suggestions
Target complexity is homework assignment
Addendum on Cones
Not all cones are convex!
When is a cone convex?
Convex iff closed under addition
When is a cone convex?
Convex iff closed under addition
When is a cone convex?
Convex iff closed under addition
How to show a set is convex?
Suppose you have a problem and some constraints
Brute force math:
Try to prove that for every \(\mathbf{x}_1\) and \(\mathbf{x}_2\) in set, \(\theta\mathbf{x}_1+(1-\theta)\mathbf{x}_2\) is in the set, if \(0\leq\theta\leq1\)
Only for simplest sets
How to show a set is convex
Using convex functions (next weeks)
Graph of a convex function
Technically how CVX works
How to show a set is convex
Show how to build your set from simpler convex sets
Intersection
Transformations: Linear/Affine, Perspective, Linear Fractional Mapping
How to show a set is (not) convex
If you are stuck, brute force numerics
Generate random points in set
Check random convex combinations
Wait a long time
Intersection
Intersection is shared points
\[ C_3 = C_1 \cap C_2 \]
Intersections of Convex are Convex
Even an infinite intersection
Infinite Constraints Example
Suppose we can several locations where we are allowed to build some quantity of renewable energy plants.
Infinite Constraints Example
\(p_i(t)\) power function for each plant over a typical day
Infinite Constraints Example
\(p_i(t)\) power function for each plant over a typical day
Infinite Constraints Example
Let \(w_i\) stand for the size of renewable plant we build at location \(i\).
Infinite Constraints Example
The total power generated at time \(t\): \[
p_{tot}(t) = \mathbf{p}(t)^T\mathbf{w}
\]
Infinite Constraints
Guarantee that the level of power above demand level:
\[
\mathbf{p}(t)^T\mathbf{w} \geq d_{min}(t)
\]
Infinite Constraints
For each individual time point \(t\), this inequality describes a convex set
Because \(\mathbf{p}(t)^T\mathbf{w} \geq d_{min}(t)\) linear in \(\mathbf{w}\)
Take intersection over \(t\)\[
C = \bigcap_t \{\mathbf{w}\,|\, \mathbf{p}(t)^T\mathbf{w} \geq d_{min}(t) \}
\]
\(C\) is a convex set
Mapping a Set
Can apply a function \(f\) to an entire set to generate a new set
Doesn’t have to be in the same space: \(f:\, \mathbb{R}^m \mapsto \mathbb{R}^n\)
Mapping a Set
Image of \(C\) under \(f\):
\[f(C) = \{x\, |\, x = f(y)\, \mathrm{for}\, y \in C\}\]
Mapping a Set
Other Direction: Preimage of \(C\) under \(f\):
\[ f^{-1}(C) = \{x\, |\, f(x) \in C\} \]
Linear/Affine Transformations
If \(C\) is convex, and \(f\) is affine \(f(\mathbf{x}) = A\mathbf{x} + \mathbf{b}\)
\(f(C)\) and \(f^{-1}(C)\) both convex if \(C\) is convex
Example: Conditional Probability
Consider discrete probability distribution over two variables: \[p(i,j) = \mathrm{prob(x=i,y=j)}\]
Conditional probability \(p(i|j) = \frac{p(i,j)}{\sum_{i'}p(i',j)}\)
Linear fractional function of joint probabilities
A convex set of joint probabilities becomes a convex set of conditional probabilities
Intro to CVX
CVX is software that solves convex optimization problems
Based on disciplined convex programming or DCP
Has library of functions with known curvature
CVX verifies convexity of objectives and constraints
Intro to CVX
Build expressions out of variables and constants
import cvxpy as cvx# 6 dimensional vector of unknownsx = cvx.Variable(6)# 12x6 dimensional matrix of unknownsA = cvx.Variable((12,6))# Scalar variabley = cvx.Variable()# Constants are numpy ndarraysx_mean = np.random.randn(6)
Intro to CVX
atomic functions define objective and constraints
margin =0.2problem = cvx.Problem( cvx.Minimize(cvx.norm(x)), # Objective (this one is least squares) [x - x_mean >=-margin , # These are the constraints x - x_mean <= margin])# Check convexity?obj = cvx.Minimize(cvx.norm(x))print(obj.is_dcp())
True
Intro to CVX
Use atomic functions to define objective and constraints
margin =0.2problem = cvx.Problem( cvx.Minimize(cvx.norm(x)), # Objective (this one is least squares) [x - x_mean >=-margin , # These are the constraints x - x_mean <= margin])# Check convexity of constraints?print((x - x_mean >=- margin).is_dcp())print((x - x_mean <= margin).is_dcp())
True
True
Intro to CVX
Use atomic functions to define objective and constraints
margin =0.2problem = cvx.Problem( cvx.Minimize(cvx.norm(x)), # Objective (this one is least squares) [x - x_mean >=-margin , # These are the constraints x - x_mean <= margin])# Check everything at once?print(problem.is_dcp())
True
Intro to CVX
Use atomic functions to define objective and constraints
margin =0.2problem = cvx.Problem( cvx.Minimize(cvx.norm(x)), # Objective (this one is least squares) [x - x_mean >=-margin , # These are the constraints x - x_mean <= margin])# Check everything at once?print(problem.is_dcp())
True
Intro to CVX
Solve using problem.solve()
margin =0.2problem = cvx.Problem( cvx.Minimize(cvx.norm(x)), # Objective (this one is least squares) [x - x_mean >=-margin , # These are the constraints x - x_mean <= margin])# Solve the problemsol = problem.solve()print(sol) # objectivex.value # optimum
margin =0.2w = np.sqrt(np.random.random(6))problem = cvx.Problem( cvx.Minimize(cvx.norm(np.diag(w) @ x)), # Objective (this one is least squares) [x - x_mean >=-margin , # These are the constraints x - x_mean <= margin])