adding more to codes for sim

This commit is contained in:
mhjensen
2018-11-06 11:02:04 +01:00
parent 0fce698a63
commit cb232e1001
31 changed files with 425 additions and 121 deletions
+36
View File
@@ -583,6 +583,27 @@ from which we also find $b$.
!split
===== Mercer's theorem =====
!split
===== Mathematical optimization of convex functions =====
A mathematical optimization problem, or just optimization problem, has the form
!bt
\[
\mathrm{minimize}\hspace{0.1cm} f(x),
\]
!et
subject to some constraints $g(\lambda_i) \leq b_i$ for say a selected set $i=1,2,\dots, n$.
In our case we are optimizing with respect to the Lagrangian multipliers $\lambda_i$, and the
vector $\bm{\lambda}=[\lambda_1, \lambda_2,\dots, \lambda_n]$ is the optimization variable we are dealing with.
and $f(x)$ is our objective function while $g(\lambda_i) \leq b_i$ represents our constraint function.
In our case we are particularly interested in a class of optimization problems called convex optmization problems.
In our disussion on gradient descent methods we discussed at length the definition of a convex function.
Convex optimization problems play a central role in applied mathematics and we recommend strongly "Boyd and Vandenberghe's text on the topics":"http://web.stanford.edu/~boyd/cvxbook/".
!split
===== How do we solve these problems =====
@@ -625,8 +646,23 @@ object; all arguments given to its solvers must be in this matrix type. There ar
to do this. The first is to define the matrix directly with (potentially nested) lists:
from cvxopt import matrix
!bc pycod
# Import the necessary packages
import numpy
from cvxopt import matrix
from cvxopt import solvers
# Define QP parameters (directly)
P = matrix([[1.0,0.0],[0.0,0.0]])
q = matrix([3.0,4.0])
G = matrix([[-1.0,0.0,-1.0,2.0,3.0],[0.0,-1.0,-3.0,5.0,4.0]])
h = matrix([0.0,0.0,-15.0,100.0,80.0])
# Define QP parameters (with NumPy)
P = matrix(numpy.diag([1,0]), tc=d)
q = matrix(numpy.array([3,4]), tc=d)
G = matrix(numpy.array([[-1,0],[0,-1],[-1,-3],[2,5],[3,4]]), tc=d)
h = matrix(numpy.array([0,0,-15,100,80]), tc=d)
# Construct the QP, invoke solver
sol = solvers.qp(P,q,G,h)
# Extract optimal value and solution
sol[x] # [7.13e-07, 5.00e+00]
sol[primal objective]
!ec