[sdpb] 132/233: Commented SDP.cpp

Tobias Hansen thansen at moszumanska.debian.org
Thu Mar 9 04:06:29 UTC 2017


This is an automated email from the git hooks/post-receive script.

thansen pushed a commit to branch master
in repository sdpb.

commit fa4d96a9648222f72131fb0a1fbb43b0252f2508
Author: David Simmons-Duffin <dsd at minerva.sns.ias.edu>
Date:   Sat Jan 10 15:44:23 2015 -0500

    Commented SDP.cpp
---
 src/SDP.cpp | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 77 insertions(+), 7 deletions(-)

diff --git a/src/SDP.cpp b/src/SDP.cpp
index 54dd7d4..07d8a5c 100644
--- a/src/SDP.cpp
+++ b/src/SDP.cpp
@@ -9,6 +9,24 @@
 #include <vector>
 #include "SDP.h"
 
+// Given a vector of polynomials {q_0(x), q_1(x), ..., q_n(x)} of
+// degree deg q_m(x) = m, a list of numSamples points x_k and scaling
+// factors s_k, form the (maxDegree+1) x numSamples Matrix
+//
+//   {{ \sqrt(s_0) q_0(x_0), ..., \sqrt(s_K) q_0(x_K) },
+//    { \sqrt(s_0) q_1(x_0), ..., \sqrt(s_K) q_1(x_K) },
+//    ...
+//    { \sqrt(s_0) q_M(x_0), ..., \sqrt(s_K) q_M(x_K) }}
+//
+// where maxDegree = M and numSamples = K+1.
+//
+// Input: 
+// - maxDegree: the maximal degree of q_m(x) to include
+// - numSamples: number of sample points x_k
+// - bilinearBasis: the vector {q_0(x), q_1(x), ..., q_n(x)}
+// - samplePoints: the points {x_0, x_1, ... }
+// - sampleScalings: the scale factors {s_0, s_1, ... }
+//
 Matrix sampleBilinearBasis(const int maxDegree,
                            const int numSamples,
                            const vector<Polynomial> &bilinearBasis,
@@ -24,6 +42,18 @@ Matrix sampleBilinearBasis(const int maxDegree,
   return b;
 }
 
+// Convert a PolynomialVectorMatrix to a DualConstraint group by
+// sampling the matrix at the appropriate number of points, as
+// described in SDP.h:
+//
+//   (1,y) . M(x) is positive semidefinite
+//
+// is equivalent to
+//
+//   Tr(A_p Y) + (B y)_p = c_p
+//
+// for tuples p = (r,s,k).
+//
 DualConstraintGroup
 dualConstraintGroupFromPolVecMat(const PolynomialVectorMatrix &m) {
   DualConstraintGroup g;
@@ -36,12 +66,15 @@ dualConstraintGroupFromPolVecMat(const PolynomialVectorMatrix &m) {
   int numConstraints = numSamples * g.dim * (g.dim + 1)/2;
   int vectorDim      = m.elt(0, 0).size();
 
+  // Form the constraintMatrix B and constraintConstants c from the
+  // polynomials (1,y) . \vec P^{rs}(x)
 
-  // The first element of each vector multiplies the constant 1
+  // The first element of each vector \vec P^{rs}(x) multiplies the constant 1
   g.constraintConstants = Vector(numConstraints);
-  // The rest multiply decision variables
+  // The rest multiply decision variables y
   g.constraintMatrix    = Matrix(numConstraints, vectorDim - 1);
 
+  // Populate B and c by sampling the matrix polynomial
   int p = 0;
   for (int c = 0; c < g.dim; c++) {
     for (int r = c; r < g.dim; r++) {
@@ -58,13 +91,23 @@ dualConstraintGroupFromPolVecMat(const PolynomialVectorMatrix &m) {
     }
   }
 
+  // The matrix Y has two blocks Y_1, Y_2.  The bilinearBases for the
+  // constraint matrices A_p are given by sampling the following
+  // vectors for each block:
+  //
+  //   Y_1: {q_0(x), ..., q_delta1(x)}
+  //   Y_2: {\sqrt(x) q_0(x), ..., \sqrt(x) q_delta2(x)
+  //
   int delta1 = g.degree/2;
   g.bilinearBases.push_back(sampleBilinearBasis(delta1, numSamples,
                                                 m.bilinearBasis,
                                                 m.samplePoints,
                                                 m.sampleScalings));
   int delta2 = (g.degree - 1)/2;
+  // a degree-0 PolynomialVectorMatrix only needs one block
   if (delta2 >= 0)
+    // The \sqrt(x) factors can be accounted for by replacing the
+    // scale factors s_k with x_k s_k.
     g.bilinearBases
       .push_back(sampleBilinearBasis(delta2, numSamples,
                                      m.bilinearBasis,
@@ -75,11 +118,13 @@ dualConstraintGroupFromPolVecMat(const PolynomialVectorMatrix &m) {
   return g;
 }
 
-SDP sdpFromDualConstraintGroups(const Vector &objective,
+// Collect a bunch of DualConstraintGroup's and a dual objective
+// function into an SDP.
+SDP sdpFromDualConstraintGroups(const Vector &dualObjective,
                                 const Real &objectiveConst,
                                 const vector<DualConstraintGroup> &dualConstraintGroups) {
   SDP sdp;
-  sdp.dualObjective  = objective;
+  sdp.dualObjective  = dualObjective;
   sdp.objectiveConst = objectiveConst;
 
   for (vector<DualConstraintGroup>::const_iterator g = dualConstraintGroups.begin();
@@ -87,6 +132,9 @@ SDP sdpFromDualConstraintGroups(const Vector &objective,
        g++) {
     sdp.dimensions.push_back(g->dim);
     sdp.degrees.push_back(g->degree);
+
+    // sdp.primalObjective is the concatenation of the
+    // g.constraintConstants
     sdp.primalObjective.insert(sdp.primalObjective.end(),
                                g->constraintConstants.begin(),
                                g->constraintConstants.end());
@@ -94,19 +142,30 @@ SDP sdpFromDualConstraintGroups(const Vector &objective,
   sdp.FreeVarMatrix = Matrix(sdp.primalObjective.size(), sdp.dualObjective.size());
 
   int p = 0;
+  // Each g corresponds to an index 0 <= j < J (not used explicitly here)
   for (vector<DualConstraintGroup>::const_iterator g = dualConstraintGroups.begin();
        g != dualConstraintGroups.end();
        g++) {
+    // sdp.bilinearBases is the concatenation of the g.bilinearBases.
+    // The matrix Y is a BlockDiagonalMatrix built from the
+    // concatenation of the blocks for each individual
+    // DualConstraintGroup.  sdp.blocks[j] = {b1, b2, ... } contains
+    // the indices for the blocks of Y corresponding to the j-th
+    // group.
     vector<int> blocks;
     for (vector<Matrix>::const_iterator b = g->bilinearBases.begin();
          b != g->bilinearBases.end();
          b++) {
+      // Ensure that each bilinearBasis is sampled the correct number
+      // of times
       assert(b->cols == g->degree + 1);
       blocks.push_back(sdp.bilinearBases.size());
       sdp.bilinearBases.push_back(*b);
     }
     sdp.blocks.push_back(blocks);
 
+    // sdp.FreeVarMatrix is the block-wise concatenation of the
+    // g.constraintMatrix's
     for (int k = 0; k < g->constraintMatrix.rows; k++, p++)
       for (int n = 0; n < g->constraintMatrix.cols; n++)
         sdp.FreeVarMatrix.elt(p, n) = g->constraintMatrix.elt(k, n);
@@ -117,17 +176,28 @@ SDP sdpFromDualConstraintGroups(const Vector &objective,
   return sdp;
 }
 
+// Form an SDP from an affineObjective and a list of
+// PolynomialVectorMatrices.  affineObjective is a vector of the form
+// (f, b), where the objective function will be
+//
+//   f + y.b
+//
+// with y the dual decision variables.  polVectorMatrices are
+// described in SDP.h.
+//
 SDP bootstrapSDP(const Vector &affineObjective,
                  const vector<PolynomialVectorMatrix> &polVectorMatrices) {
+  // Convert polVectorMatrices into DualConstraintGroup's
   vector<DualConstraintGroup> dualConstraintGroups;
   for (vector<PolynomialVectorMatrix>::const_iterator m = polVectorMatrices.begin();
        m != polVectorMatrices.end(); m++)
     dualConstraintGroups.push_back(dualConstraintGroupFromPolVecMat(*m));
 
-  Vector objective = affineObjective;
-  objective.erase(objective.begin());
+  // Split affineObjective into objectiveConst f and dualObjective b
   Real objectiveConst = affineObjective[0];
+  Vector dualObjective = affineObjective;
+  dualObjective.erase(dualObjective.begin());
 
-  return sdpFromDualConstraintGroups(objective, objectiveConst, dualConstraintGroups);
+  return sdpFromDualConstraintGroups(dualObjective, objectiveConst, dualConstraintGroups);
 }
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/sdpb.git



More information about the debian-science-commits mailing list