Part I · 第 6 章 优化 · 6.2Part I · Ch. 6 Optimization · 6.2

凸性Convexity

优化里最重要的一个"好性质":碗状的地形里只有一个谷底,沿着坡往下走,一定走得到。数学上把这种碗叫凸函数。一个问题是凸的,意味着局部最小就是全局最小,算法有保证、有速度、结果可复现;不是凸的,就要靠运气和经验。认清哪些机器人问题凸、哪些不凸,是选对工具的第一步。 The single most valuable "nice property" in optimization: in a bowl-shaped landscape there is only one valley floor, and walking downhill is sure to reach it. Mathematically such a bowl is a convex function. If a problem is convex, a local minimum is the global minimum, and algorithms come with guarantees, speed and reproducible results; if not, you rely on luck and experience. Telling which robot problems are convex and which are not is the first step in choosing the right tool.

约 25 分钟~25 min 前置:6.1 什么是优化问题 · 3.5 Hessian · 1.11 特征值Prereqs: 6.1 Optimization problems · 3.5 Hessian · 1.11 Eigenvalues 5 个交互5 interactives

    1为什么机器人需要它Why robots need this

    机器人领域有一条几乎通用的工程经验:能写成凸问题的,就写成凸问题。全身控制每毫秒要解一个二次规划 (QP),模型预测控制 (MPC) 在线性模型下是一个凸 QP,线性最小二乘标定一步到位。它们都是凸的,所以求解器几毫秒内给出可靠、唯一、可复现的答案,不用担心卡在局部最小、不用调初值。

    反过来,机械臂的逆运动学、视觉里程计的位姿优化、神经网络训练都不是凸的,我们只能找"一个够好的谷底"。这一节要建立的是一副"眼镜":给你一个问题,你能判断它的地形是碗还是山脉,从而知道可以对结果有多大的信心。

    Robotics has an almost universal engineering rule of thumb: if you can pose it as a convex problem, do. Whole-body control solves a quadratic program (QP) every millisecond; model predictive control (MPC) with a linear model is a convex QP; linear least-squares calibration is one-shot. All are convex, so solvers return a reliable, unique, reproducible answer in milliseconds, with no worry about local minima and no need to tune the initial guess.

    Conversely, inverse kinematics of an arm, pose optimization in visual odometry and neural-network training are not convex, and all we can find is "a good enough valley". This lesson builds a pair of glasses: given a problem, you can tell whether its landscape is a bowl or a mountain range, and therefore how much to trust the result.

    2直觉:弦在曲线之上Intuition: the chord stays above the curve

    取函数曲线上任意两点,连一条线段(弦)。如果无论你取哪两点,弦都不会钻到曲线下面,这个函数就是凸的:它像一个碗,向上"兜住"每一条弦。只要有一对点,弦钻到了曲线下面,就说明那里有个"凸起",凸性被破坏。

    这个看似平淡的性质威力巨大。假设碗里有两个"谷底",它们之间的弦必须在曲线之上(或重合);可两个谷底都是最低值 \(m\),弦的高度恰好是 \(m\),而曲线又不可能低于 \(m\),于是两点之间的曲线被夹住,处处等于 \(m\):两个谷底其实是同一片平地。如果两个谷底一高一低,弦从高的那个谷底出发就向下倾斜,紧挨着它的曲线也被压到它的高度之下,它根本不是局部最小(第 7 节给出严格证明)。凸函数不可能有彼此孤立的两个局部最小值。先亲手试试弦测试。

    Pick any two points on a function's curve and join them with a segment (the chord). If, whichever two points you pick, the chord never dips below the curve, the function is convex: it behaves like a bowl that holds up every chord. If a single pair has a chord that dips under the curve, there is a "bump" there and convexity fails.

    This humble property is powerful. Suppose a bowl had two separate "valley floors". The chord between them must lie on or above the curve; but both floors are at the lowest value \(m\), so the chord sits at height exactly \(m\), and the curve cannot go below \(m\), so between them it is squeezed to equal \(m\) everywhere: the two floors are really one flat stretch. If one floor were higher than the other, the chord from the higher one would slope downward, pushing the curve right next to it below its height, so it would not be a local minimum at all (Section 7 proves this properly). A convex function cannot have two isolated local minima. First, try the chord test by hand.

    3动手玩:弦测试Play: the chord test

    选一个函数,拖动曲线上的两个点 A、B。弦在曲线之上的部分填绿色,钻到曲线之下的部分填红色。滑块 \(\theta\) 在弦上取一点,对比 \(f(\theta a+(1-\theta)b)\) 与弦的高度 \(\theta f(a)+(1-\theta)f(b)\)。"全面扫描"会测试 780 对点(区间上 40 个点两两配对),告诉你有多大比例的弦违反了凸性。

    Choose a function and drag the two points A and B along the curve. Where the chord lies above the curve it is filled green; where it dips below, red. The slider \(\theta\) picks a point on the chord so you can compare \(f(\theta a+(1-\theta)b)\) with the chord height \(\theta f(a)+(1-\theta)f(b)\). "Full scan" tests 780 pairs (every pair of 40 points across the interval) and tells you what fraction of chords violate convexity.

    FIG 1一维弦测试The 1D chord test
    六个函数:\(0.4x^2\)、\(0.25e^{0.8x}\)、\(0.04x^4\)、双谷 \(0.08(x^2-2)^2\)、波浪 \(1.5+0.9\sin1.7x+0.12x^2\)、凹函数 \(3-0.3x^2\)。判定用密集采样 (200 点) 逐点比较弦与曲线,不是目测。 Six functions: \(0.4x^2\), \(0.25e^{0.8x}\), \(0.04x^4\), the double well \(0.08(x^2-2)^2\), the wave \(1.5+0.9\sin1.7x+0.12x^2\), and the concave \(3-0.3x^2\). The verdict compares chord and curve at 200 sample points, it is not eyeballed.
    试一试Try this
    • 在"双谷"或"波浪"上找到一对点,让弦钻到曲线之下。On the "double well" or the "wave", find a pair whose chord dips below the curve.
    • 在 \(0.04x^4\) 上做"全面扫描":它在 \(x=0\) 处几乎是平的,却仍然是凸的,违反比例是 0。Run a "full scan" on \(0.04x^4\): it is almost flat at \(x=0\) yet still convex; the violation rate is 0.
    • 在凹函数 \(3-0.3x^2\) 上扫描:违反比例是多少?为什么凹函数的"弦"总在曲线下面?Scan the concave function \(3-0.3x^2\): what is the violation rate, and why does its chord always sit below the curve?
    核心洞见Key insight

    凸性是一个"全局"性质,却能用"两点之间"来检验。你不需要知道整个地形,只要任意两点之间的弦不下沉,就知道没有多余的谷底。这也是为什么它能给出全局保证:局部信息(梯度为零)加上凸性,就等于全局信息。

    Convexity is a "global" property, but you test it "between two points". You do not need the whole landscape; if no chord between any two points sinks, you know there are no spare valleys. That is why it yields global guarantees: local information (zero gradient) plus convexity equals global information.

    4凸集:约束的形状Convex sets: the shape of constraints

    同样的"弦测试"用在集合上:一个集合是凸的,当且仅当其中任意两点之间的线段完全留在集合里。球、半空间、盒子是凸的;有凹口的"月牙"、带洞的区域、几块分离的区域都不是。

    它为什么重要?因为可行集(6.1 节)就是一个集合。如果约束是凸的,从可行点出发朝另一个可行点走,永远不会"撞墙"。反之,一个障碍物就能把可行集变成非凸的:从左边绕还是从右边绕,是两条不同的路,这正是路径规划难的原因。

    The same "chord test" applies to sets: a set is convex if the segment between any two of its points stays entirely inside. Balls, half-spaces and boxes are convex; a "crescent" with a dent, a region with a hole, or several separate blobs are not.

    Why does it matter? Because the feasible set (Lesson 6.1) is a set. With convex constraints, walking from one feasible point towards another never hits a wall. A single obstacle, by contrast, makes the feasible set non-convex: going around on the left or on the right are two different routes, which is exactly why path planning is hard.

    FIG 2这个集合是凸的吗?Is this set convex?
    拖动 A、B。线段落在集合内的部分是绿色,落在外面的部分是红色。"随机扫描"在集合内随机抽 3000 对点,数一数有多少条弦会跑出集合。 Drag A and B. The part of the segment inside the set is green; the part outside is red. "Random scan" draws 3000 random pairs of points inside the set and counts how many chords leave it.
    试一试Try this
    • 在"月牙"或"星形"里,把 A、B 都放在集合内,却让弦跑出集合。In the "crescent" or the "star", put both A and B inside the set yet make the chord leave it.
    • 选"透镜"(圆盘 ∩ 半平面)并做随机扫描:两个凸集的交仍然是凸集,违反数为 0。Pick the "lens" (disk ∩ half-plane) and run a random scan: the intersection of two convex sets is again convex, so zero violations.

    5第二个视角:切线在下,曲率向上A second view: tangents below, curvature up

    弦测试需要同时看两个点,不方便。对可导函数,有两个"单点"检验:

    • 一阶条件:凸函数整条曲线都在它任何一条切线之上。选一点 \(x_0\),画出切线,曲线不能钻到切线下面。
    • 二阶条件:曲率处处非负,即 \(f''(x)\ge0\)(多维时是 Hessian \(\nabla^2 f\succeq0\),3.5 节)。曲线始终"向上弯"。

    下面拖动 \(x_0\):上图画切线,红色表示曲线跑到了切线之下;下图画 \(f''\),红色表示曲率为负。你会发现这两件事严格同步:只要某处 \(f''<0\),就一定能找到一条切线被曲线穿透;反之,\(f''\ge0\) 处处成立则切线永远在下面。

    The chord test must look at two points at once, which is awkward. For differentiable functions there are two "single-point" tests:

    • First-order condition: a convex function lies above every one of its tangent lines. Pick a point \(x_0\), draw its tangent; the curve may not dip below it.
    • Second-order condition: curvature is everywhere non-negative, \(f''(x)\ge0\) (in several dimensions, the Hessian \(\nabla^2 f\succeq0\), Lesson 3.5). The curve always bends upward.

    Drag \(x_0\) below: the top panel draws the tangent, red where the curve dips below it; the bottom panel draws \(f''\), red where curvature is negative. The two stay in lockstep: wherever \(f''<0\) there is a tangent the curve pierces; if \(f''\ge0\) everywhere, every tangent stays below.

    FIG 3切线测试与曲率Tangent test and curvature
    上:曲线、\(x_0\) 处的切线(紫色);曲线低于切线的区间标红。下:\(f''(x)\)(解析式);负值标红。选 \(0.04x^4\):\(x=0\) 处 \(f''=0\),切线是水平线,曲线仍然不会钻下去:二阶条件是"\(\ge0\)",不是"\(>0\)"。 Top: the curve and the tangent at \(x_0\) (purple); intervals where the curve is below the tangent are red. Bottom: \(f''(x)\) (closed form); negative values are red. Choose \(0.04x^4\): at \(x=0\) we have \(f''=0\), the tangent is horizontal and the curve still does not dip below it: the second-order condition is "\(\ge0\)", not "\(>0\)".
    • 在"双谷"上拖动 \(x_0\),找到一个位置使得切线被曲线穿透。此时 \(f''\) 在 \(x_0\) 处一定为负吗?(不一定:试试 \(x_0=1\)。)On the "double well" drag \(x_0\) until the tangent is pierced by the curve. Must \(f''\) be negative at \(x_0\) itself? (Not necessarily: try \(x_0=1\).)
    • 在"指数"上拖遍整条曲线:切线是否永远在曲线之下?On "exp", drag over the whole curve: does the tangent ever rise above the curve?

    6二维地形:弦、Hessian 与"负曲率区"2D landscapes: chords, Hessians and "negative-curvature zones"

    到了二维,把 \(x_0\) 换成平面上的点,曲率换成 Hessian 的两个特征值 \(\lambda_1\ge\lambda_2\)(1.11 节)。\(\lambda_2\ge0\) 说明各个方向都向上弯,是碗;\(\lambda_2<0\le\lambda_1\) 说明有的方向向下弯,是鞍;两个都为负是山顶。凸函数要求处处是碗。

    下图在平面上拖动 A、B,下方的小图画出 \(f\) 沿这条线段的剖面(实线)和弦(虚线)。红色背景标出 Hessian 有负特征值的地方,那是"非凸区"。试试四种地形:只有第一个是凸的。

    In two dimensions the point \(x_0\) becomes a point in the plane and curvature becomes the two Hessian eigenvalues \(\lambda_1\ge\lambda_2\) (Lesson 1.11). \(\lambda_2\ge0\) means it curves upward in every direction: a bowl. \(\lambda_2<0\le\lambda_1\) means some direction curves downward: a saddle; both negative is a hilltop. A convex function must be a bowl everywhere.

    In the figure drag A and B in the plane; the small plot below shows the profile of \(f\) along the segment (solid) and the chord (dashed). The red tint marks places where the Hessian has a negative eigenvalue: the "non-convex zone". Try the four terrains: only the first is convex.

    FIG 4平面上的弦与 HessianChords and Hessians in the plane
    沿线段 A→B 的剖面Profile along A→B
    四个地形:log-sum-exp \(\log(e^x+e^{-x}+e^y+e^{-y})\)(凸)、Rosenbrock \(\tfrac12[(1-x)^2+100(y-x^2)^2]\)(只有一个谷但不凸)、双谷(6.3 节)、鞍 \(\tfrac12x^2+\tfrac14y^4-\tfrac12y^2\)。Hessian 用梯度的中心差分数值计算,特征值取自 1.11 节的对称 2×2 公式。 Four terrains: log-sum-exp \(\log(e^x+e^{-x}+e^y+e^{-y})\) (convex), Rosenbrock \(\tfrac12[(1-x)^2+100(y-x^2)^2]\) (one valley, yet not convex), the two minima of Lesson 6.3 and the saddle \(\tfrac12x^2+\tfrac14y^4-\tfrac12y^2\). The Hessian is computed numerically by central differences of the gradient; eigenvalues use the symmetric 2×2 formula of Lesson 1.11.
    • 在 Rosenbrock 上放 A、B,使剖面鼓到弦之上(它只有一个谷底,却不是凸的)。On Rosenbrock place A and B so the profile pokes above the chord (one valley floor, yet not convex).
    • 在 log-sum-exp 上随便拖拽 A、B:剖面永远在弦下面,红色区域也不出现。On log-sum-exp drag A and B anywhere: the profile always stays below the chord and no red zone appears.

    7再看数学The math

    提示:悬停在带底色的符号上,FIG 1、3、4 里对应的元素(弦、切线、非凸区)会被强调。Tip: hover the highlighted symbols; the matching elements in FIG 1, 3 and 4 (chord, tangent, non-convex zone) are emphasized.

    定义Definitions

    集合 \(C\) 是凸集,如果对任意 \(\x,\y\in C\) 与 \(\theta\in[0,1]\),都有 \(\theta\x+(1-\theta)\y\in C\)。函数 \(f\) 是凸函数,如果定义域是凸集,且

    A set \(C\) is convex if \(\theta\x+(1-\theta)\y\in C\) for all \(\x,\y\in C\) and \(\theta\in[0,1]\). A function \(f\) is convex if its domain is convex and

    $$ f\big(\theta\x+(1-\theta)\y\big)\ \le\ \hl{jensen}{\cv{\theta f(\x)+(1-\theta)f(\y)}}\qquad\forall\,\x,\y,\ \theta\in[0,1] $$

    左边是弦下方曲线上的点的高度,右边是弦的高度(FIG 1 的滑块 \(\theta\))。把 \(\le\) 换成 \(<\)(\(\x\ne\y\),\(\theta\in(0,1)\))就是严格凸:碗底没有平的部分,最小点唯一。\(-f\) 凸则称 \(f\) 为凹。

    The left side is the height of the curve under the chord; the right side is the chord's height (the slider \(\theta\) of FIG 1). Replacing \(\le\) by \(<\) (for \(\x\ne\y\), \(\theta\in(0,1)\)) gives strict convexity: no flat part at the bottom, hence a unique minimizer. If \(-f\) is convex, \(f\) is concave.

    一阶与二阶条件First- and second-order conditions

    若 \(f\) 可微,则 \(f\) 凸 \(\iff\) 对所有 \(\x,\y\):

    If \(f\) is differentiable, \(f\) is convex \(\iff\) for all \(\x,\y\):

    $$ f(\y)\ \ge\ f(\x)+\hl{tangent}{\cw{\nabla f(\x)^\top(\y-\x)}} $$

    右边正是 \(f\) 在 \(\x\) 处的一阶泰勒展开(切线 / 切平面,FIG 3 的紫线)。若 \(f\) 二阶可微,则 \(f\) 凸 \(\iff\)

    The right-hand side is exactly the first-order Taylor expansion of \(f\) at \(\x\) (the tangent line / plane, the purple line of FIG 3). If \(f\) is twice differentiable, \(f\) is convex \(\iff\)

    $$ \hl{hess}{\nabla^2 f(\x)\succeq 0}\quad\forall\,\x\qquad\Longleftrightarrow\qquad\lambda_{\min}\big(\nabla^2 f(\x)\big)\ge0\quad\forall\,\x $$

    为什么凸问题"容易"Why convex problems are "easy"

    1. 局部最小就是全局最小。设 \(\x^\star\) 是局部最小,却有 \(\y\) 使 \(f(\y)<f(\x^\star)\)。沿线段取点 \(\x_t=(1-t)\x^\star+t\y\),由凸性 \(f(\x_t)\le(1-t)f(\x^\star)+tf(\y)<f(\x^\star)\),对任意小的 \(t>0\) 都成立,而 \(\x_t\) 可以任意接近 \(\x^\star\),与"局部最小"矛盾。

    2. 梯度为零就够了。在一阶条件里令 \(\nabla f(\x^\star)=\mathbf0\),得 \(f(\y)\ge f(\x^\star)\ \forall\y\):驻点就是全局最小。6.1 节说"梯度为零只是必要条件",对凸函数它也是充分条件。

    3. 算法有保证。强凸(\(m I\preceq\nabla^2f\preceq L I\))时,梯度下降的误差按 \(\big(\tfrac{\kappa-1}{\kappa+1}\big)^k\) 衰减,\(\kappa=L/m\) 就是 6.3 节的条件数;Newton 法(6.6 节)在最优点附近二次收敛。

    1. A local minimum is the global minimum. Let \(\x^\star\) be a local minimizer and suppose some \(\y\) has \(f(\y)<f(\x^\star)\). Take \(\x_t=(1-t)\x^\star+t\y\) on the segment; convexity gives \(f(\x_t)\le(1-t)f(\x^\star)+tf(\y)<f(\x^\star)\) for every small \(t>0\), while \(\x_t\) comes arbitrarily close to \(\x^\star\), contradicting local minimality.

    2. Zero gradient is enough. Put \(\nabla f(\x^\star)=\mathbf0\) in the first-order condition: \(f(\y)\ge f(\x^\star)\ \forall\y\). A stationary point is a global minimizer. Lesson 6.1 said "zero gradient is only necessary"; for convex functions it is also sufficient.

    3. Algorithms come with guarantees. For strongly convex \(f\) (\(m I\preceq\nabla^2f\preceq L I\)), gradient descent's error decays like \(\big(\tfrac{\kappa-1}{\kappa+1}\big)^k\), where \(\kappa=L/m\) is the condition number of Lesson 6.3; Newton's method (Lesson 6.6) converges quadratically near the optimum.

    怎样得到凸函数:保凸运算Building convex functions: operations that preserve convexity

    运算Operation结论Result机器人里的例子Robotics example
    非负加权和non-negative weighted sum\(\sum_i w_if_i,\ w_i\ge0\)误差 + \(\lambda\)·能耗error + \(\lambda\)·energy
    与仿射映射复合composition with an affine map\(f(A\x+\mathbf b)\)\(\|A\x-\mathbf b\|^2\):线性最小二乘(1.13 节)linear least squares (Lesson 1.13)
    逐点取最大pointwise maximum\(\max_i f_i\)最大关节误差;\(\ell_\infty\) 范数worst joint error; the \(\ell_\infty\) norm
    范数、二次型 (PSD)norms, PSD quadratics\(\|\x\|,\ \x^\top Q\x\)马氏距离、力矩平方Mahalanobis distance, squared torques
    凸集的交intersection of convex sets\(C_1\cap C_2\)限位 ∩ 速度上限 ∩ 摩擦锥position limits ∩ velocity limits ∩ friction cone

    注意非线性复合会破坏凸性:\(\|A\x-\mathbf b\|^2\) 凸,但 \(\|\mathrm{FK}(\mathbf q)-\mathbf t\|^2\) 里的 \(\mathrm{FK}\) 不是仿射的,所以逆运动学的代价对关节角 \(\mathbf q\) 不凸,见下一节。

    Note that nonlinear composition breaks convexity: \(\|A\x-\mathbf b\|^2\) is convex, but \(\mathrm{FK}\) inside \(\|\mathrm{FK}(\mathbf q)-\mathbf t\|^2\) is not affine, so the IK cost is not convex in the joint angles \(\mathbf q\), as the next section shows.

    8机器人中的它:逆运动学为什么不凸In robotics: why inverse kinematics is not convex

    对于一个目标位置 \(\mathbf t\),最小化 \(f(\mathbf q)=\tfrac12\|\mathrm{FK}(\mathbf q)-\mathbf t\|^2\)。如果把末端位置 \(\mathbf p\) 当变量,\(\tfrac12\|\mathbf p-\mathbf t\|^2\) 是一个完美的碗;可变量是关节角 \(\mathbf q\),\(\mathbf p=\mathrm{FK}(\mathbf q)\) 里全是 \(\sin,\cos\),碗被"揉皱"了。最直接的证据:肘朝上和肘朝下两个解的代价都是 0,而在关节空间里把两个解连成一条线段,中点的代价却大于 0,弦在曲线下面。

    拖动下图右侧的 A、B(初始在两个解上,拖动目标会自动吸附到新解),滑块 \(t\) 让手臂沿着这条线段在关节空间里"插值"。注意中途手爪明显偏离了目标,代价鼓起一个包。红色区域是 Hessian 有负特征值的地方。

    For a target \(\mathbf t\), minimize \(f(\mathbf q)=\tfrac12\|\mathrm{FK}(\mathbf q)-\mathbf t\|^2\). Take the end-effector position \(\mathbf p\) as the variable and \(\tfrac12\|\mathbf p-\mathbf t\|^2\) is a perfect bowl; but the variable is the joint angle \(\mathbf q\), and \(\mathbf p=\mathrm{FK}(\mathbf q)\) is full of \(\sin,\cos\): the bowl gets crumpled. The cleanest evidence: elbow up and elbow down both have cost 0, yet the midpoint of the segment joining the two solutions in joint space has cost above 0: the chord lies below the curve.

    Drag A and B on the right (they start on the two solutions; moving the target snaps them to the new solutions) and use the slider \(t\) to "interpolate" the arm along that segment in joint space. Mid-way the gripper is visibly off target and the cost bulges. The red zone is where the Hessian has a negative eigenvalue.

    FIG 5关节空间里的弦:IK 代价A chord in joint space: the IK cost
    左:工作空间,拖动目标;淡色手臂是 A、B 两端,实心手臂是 \(\mathbf q(t)=(1-t)\mathbf q_A+t\mathbf q_B\)。右:关节空间,\(q_1,q_2\in[-\pi,\pi]\)。下:\(f(\mathbf q(t))\) 与弦。当 A、B 都是零代价解时弦是一条贴着 0 的横线,曲线却在中间鼓起来。 Left: the workspace, drag the target; faint arms are the ends A and B, the solid arm is \(\mathbf q(t)=(1-t)\mathbf q_A+t\mathbf q_B\). Right: joint space, \(q_1,q_2\in[-\pi,\pi]\). Bottom: \(f(\mathbf q(t))\) and the chord. When A and B are both zero-cost solutions the chord is a flat line at 0 while the curve bulges in the middle.
    • 把滑块 \(t\) 拖到中间 (0.4–0.6),读出中点代价:它是否大于两端代价的平均值?Slide \(t\) to the middle (0.4–0.6) and read the midpoint cost: is it larger than the average of the endpoint costs?
    真实系统里In real systems

    这解释了机器人领域的一个普遍现象:"把不凸的部分藏到凸的外面"。解 IK 时通常先在关节空间做一次非凸迭代,再在每一步里解一个凸的线性化子问题(雅可比 \(J\) 把问题局部变成线性最小二乘,6.6、6.9 节)。全身控制则更进一步:在加速度层面,动力学对力矩 \(\boldsymbol\tau\) 与加速度 \(\ddot{\mathbf q}\) 是线性的,于是整个问题是一个凸 QP(6.8 节、第 IV 部分):只要约束可行,求解器就能在 1 kHz 下可靠地给出全局最优解。凸与不凸,常常取决于你选了哪个变量。

    This explains a recurring pattern in robotics: "hide the non-convex part outside the convex part". IK is usually solved with a non-convex outer iteration in joint space, but every step solves a convex linearized subproblem (the Jacobian \(J\) turns the problem locally into a linear least-squares one; Lessons 6.6 and 6.9). Whole-body control goes further: at the acceleration level, dynamics are linear in torques \(\boldsymbol\tau\) and accelerations \(\ddot{\mathbf q}\), so the entire problem is a convex QP (Lesson 6.8, Part IV): as long as the constraints are feasible, the solver reliably returns the global optimum at 1 kHz. Whether a problem is convex often depends on which variable you chose.

    9常见误区Common pitfalls

    误区 1:只有一个谷底,所以是凸的Pitfall 1: one valley floor means convex

    反例就是 Rosenbrock(FIG 4):只有一个最小点,却不是凸的,弦能钻到曲线下面。"单峰"(unimodal)比"凸"弱得多。不凸但单谷的函数,局部算法通常也能找到最小点,只是没有凸性那样的速度保证(沿弯曲山谷爬得很慢)。

    Rosenbrock (FIG 4) is the counterexample: a single minimizer, yet not convex, with chords that dip below the curve. "Unimodal" is far weaker than "convex". For non-convex single-valley functions local algorithms usually still find the minimum, just without convexity's speed guarantees (they crawl along the curved valley).

    误区 2:Hessian 在某一点为正定,函数就是凸的Pitfall 2: a positive-definite Hessian at one point means convex

    二阶条件必须在整个定义域上成立。一个点的 Hessian 正定只说明局部像碗(它是局部最小的二阶充分条件)。FIG 4 里的双谷在每个谷底都是正定的,整体却不凸。

    The second-order condition must hold on the whole domain. A positive-definite Hessian at one point only says the function looks like a bowl locally (a second-order sufficient condition for a local minimum). The double well of FIG 4 has a positive-definite Hessian at each valley floor yet is not convex overall.

    误区 3:等式约束 \(\|\x\|=1\) 和不等式约束 \(\|\x\|\le1\) 差不多Pitfall 3: the equality \(\|\x\|=1\) is about the same as \(\|\x\|\le1\)

    单位球(\(\le\))是凸集,单位球面(\(=\))不是:球面上两点连线穿过球内部。这就是为什么"四元数模长为 1"、"旋转矩阵正交"这类约束让问题变得不凸,也是第 6.10 节要在流形上直接优化的原因之一。非线性等式约束一般都会破坏凸性;凸问题里的等式约束必须是仿射的。

    The unit ball (\(\le\)) is convex; the unit sphere (\(=\)) is not: a chord between two points on the sphere passes through the interior. That is why constraints such as "quaternion has unit norm" or "rotation matrix is orthogonal" make a problem non-convex, and one of the reasons Lesson 6.10 optimizes directly on manifolds. Nonlinear equality constraints generally destroy convexity; equality constraints in a convex problem must be affine.

    误区 4:凸问题就一定好解Pitfall 4: convex problems are always easy to solve

    凸性保证"没有坏的局部最小",但不保证"快"。条件数 \(\kappa\) 很大的凸问题,梯度下降仍然龟速(6.3 节);规模巨大的凸问题仍然需要好的算法和实现。反过来,也有很多不凸的问题(如神经网络训练)在实践中被解得很好。

    Convexity guarantees "no bad local minima", not "fast". A convex problem with a huge condition number \(\kappa\) still crawls under gradient descent (Lesson 6.3), and enormous convex problems still need good algorithms and implementations. Conversely, many non-convex problems (such as neural-network training) are solved very well in practice.

    10小练习Check yourself

    1. 下列哪个函数在整个 \(\mathbb R\) 上是凸的?1. Which function is convex on all of \(\mathbb R\)?
    \((x^4)''=12x^2\ge0\) 处处成立(\(x=0\) 处等于 0 也没关系,条件是 \(\ge0\))。\(\sin x\) 的二阶导数 \(-\sin x\) 会变负;\(-x^2\) 是凹的;\(x^3\) 的二阶导数 \(6x\) 在 \(x<0\) 时为负。\((x^4)''=12x^2\ge0\) everywhere (equal to 0 at \(x=0\) is fine; the condition is \(\ge0\)). \(\sin x\) has second derivative \(-\sin x\), which turns negative; \(-x^2\) is concave; \(x^3\) has \(6x\), negative for \(x<0\).
    2. \(f(x,y)=x^2+4xy+y^2\) 是凸函数吗?2. Is \(f(x,y)=x^2+4xy+y^2\) convex?
    \(\partial_{xx}=2,\ \partial_{xy}=4,\ \partial_{yy}=2\)。特征值 \(2\pm4\),即 6 与 \(-2\)(对应方向 \((1,1)\) 和 \((1,-1)\))。沿 \((1,-1)\) 方向 \(f(t,-t)=-2t^2\) 向下弯,这是个鞍,既不凸也不凹。交叉项 \(4xy\) 可以压过平方项:不能只看对角线上的系数。\(\partial_{xx}=2,\ \partial_{xy}=4,\ \partial_{yy}=2\). Eigenvalues \(2\pm4\): 6 and \(-2\) (directions \((1,1)\) and \((1,-1)\)). Along \((1,-1)\) we get \(f(t,-t)=-2t^2\), which curves downward, so it is a saddle, neither convex nor concave. The cross term \(4xy\) can override the squares: you cannot just look at the diagonal coefficients.
    3. \(f\) 是凸函数,且在某点 \(\x^\star\) 处 \(\nabla f(\x^\star)=\mathbf 0\)。可以得出什么?3. \(f\) is convex and \(\nabla f(\x^\star)=\mathbf 0\) at some point \(\x^\star\). What follows?
    一阶条件 \(f(\y)\ge f(\x^\star)+\nabla f(\x^\star)^\top(\y-\x^\star)=f(\x^\star)\) 对所有 \(\y\) 成立,所以是全局最小。凸函数没有鞍点(鞍需要某个方向向下弯)。最小点是否唯一取决于是否严格凸,这里无法得出。The first-order condition \(f(\y)\ge f(\x^\star)+\nabla f(\x^\star)^\top(\y-\x^\star)=f(\x^\star)\) holds for every \(\y\), so it is a global minimum. Convex functions have no saddles (a saddle needs a downward-curving direction). Uniqueness depends on strict convexity, which is not given.
    4. 下列约束集合中,哪一个不是凸集?4. Which of these constraint sets is not convex?
    前三个是盒子、盒子、圆盘:凸。"在圆盘之外"的补集不是凸集:圆盘两侧各取一点,连线穿过圆盘。这就是避障让规划变得非凸的根本原因(FIG 2 的"月牙"与"两个圆"同理)。The first three are a box, a box and a disk: convex. The complement of a disk is not: take a point on each side of the disk and the segment crosses it. That is the root reason obstacle avoidance makes planning non-convex (the "crescent" and "two disks" of FIG 2 are the same story).

    11延伸阅读Further reading

    • S. Boyd & L. Vandenberghe, Convex Optimization, Ch. 2–3 — 凸集、凸函数、保凸运算的完整讲解,含大量图示(可免费下载)The definitive treatment of convex sets, convex functions and operations preserving convexity, richly illustrated (free to download)
    • J. Nocedal & S. Wright, Numerical Optimization, 2nd ed., Ch. 1–2 & App. A — 凸性在局部最优性条件中的作用The role of convexity in local optimality conditions
    • G. Strang, Linear Algebra and Learning from Data, Ch. VI — 凸函数、正定性与深度学习中的优化Convex functions, positive definiteness and optimization for deep learning