Algorithm Search⌘K

Algorithmadvanced

Simplicial approximation

Also called Director-Hachtel design centering.

Director and Hachtel's design centering. A polytope built from boundary points approximates the feasible region, and the design moves to the center of its largest inscribed ball.

Time
O(K (m log m + s)) worst
Space
O(m) extra
Where
K = the number of rounds; m = the number of boundary points, at most 4 + K in the plane; s = the number of circuit evaluations per line search
Properties
deterministicnot exactofflineiterative
Origin
Stephen W. Director, Gary D. Hachtel, 1977

Simplicial approximation is a method for design centering that Director and Hachtel published in 1977. The acceptable region RR of the circuit parameters, the set where every specification holds, is known only through circuit simulation. The method assumes that RR is convex. It finds points on the boundary of RR by line searches, takes their convex hull as an inner approximation of RR, and puts the nominal design at the center of the largest ball inscribed in that polytope, which is a linear program. It then adds a boundary point near a face that touches the ball and repeats. The ball is a hypersphere in the parameter space as scaled. If the parameters are first scaled by their spreads, the ball is an ellipsoid in the original units. This page proves what the method guarantees on a convex region, shows a region where the polytope stops growing, and shows a nonconvex region where the method fails.

In plain words

A circuit works for some parameter settings and fails for others. The settings that work form a region, and its edge is costly to find, since each test is a simulation. The goal is to put the design deep inside the region, so that manufacturing errors do not push it out.

The method walks from a working design in a few directions until the circuit fails, and keeps the points where it crossed the edge. Joining these points gives a shape with flat sides that lies inside the region, if the region has no dents. Inside the shape it finds the largest round ball, and the center of that ball is the new design.

Then it looks at the flat sides that touch the ball, walks outward from the middle of the largest one to find a new edge point, and grows the shape. The ball can only grow.

The problem

The input is a point x0x_0 inside R⊂RnR \subset \mathbb{R}^n and a line search oracle: for x∈Rx \in R and a direction dd, exit(x,d)\mathrm{exit}(x, d) is the last point of the ray x+tdx + td, t≥0t \ge 0, that lies in RR. In practice the oracle is a bisection on tt with one circuit simulation per step. The output is a center cc and a radius rr with B(c,r)⊆RB(c, r) \subseteq R, as large as the method can certify. The parameters are assumed to be scaled so that a ball is the right shape for the tolerances: with a covariance Σ\Sigma of the process spreads, the scaled parameters are Σ−1/2x\Sigma^{-1/2} x, and a ball there is the ellipsoid {x:(x−c)TΣ−1(x−c)≤r2}\{x : (x - c)^T \Sigma^{-1} (x - c) \le r^2\} in the original units.

The key subproblem is the largest ball in a polytope P={x:nf⋅x≤bf}P = \{x : n_f \cdot x \le b_f\} with unit normals nfn_f. A ball B(c,r)B(c, r) lies in the half-space of face ff if and only if nf⋅c+r≤bfn_f \cdot c + r \le b_f, because the farthest point of the ball along nfn_f is c+rnfc + r n_f. So the largest ball is the linear program

max⁡ rsubject tonf⋅c+r≤bffor every face f,\max\ r \quad\text{subject to}\quad n_f \cdot c + r \le b_f \quad\text{for every face } f,

in the n+1n + 1 variables (c,r)(c, r). Its center is often called a Chebyshev center of PP. A face is tangent when its constraint is tight at the optimum, that is when it touches the ball.

The algorithm

  1. SIMPLICIAL-APPROXIMATION(exit, x0, K)
  2. 1S ← {exit(x0, +e_j), exit(x0, −e_j) : j = 1, …, n} ▷ 2n line searches
  3. 2repeat at most K times
  4. 3P ← the convex hull of S, as faces n_f · x ≤ b_f with unit normals
  5. 4(c, r) ← argmax r subject to n_f · c + r ≤ b_f for every face f
  6. 5T ← the faces of P with n_f · c + r = b_f ▷ tangent faces
  7. 6sort T by decreasing size (in the plane, edge length)
  8. 7for each face f of T that is not marked: q ← the center of the largest ball inside f
  9. 8y ← exit(q, n_f) ▷ search outward along the normal
  10. 9if y ≠ q then S ← S ∪ {y}; go to the next round
  11. 10else mark f ▷ f lies on a supporting hyperplane of R
  12. 11if no point was added then stop ▷ every tangent face supports R
  13. 12return c, r

In the plane, a face is an edge, and the center of the largest ball inside it is its midpoint. The implementation works in the plane. It builds the hull with Andrew's monotone chain and solves the three-variable linear program of line L4 with the simplex method under Bland's rule, starting from the basis of slack variables around the centroid of the hull vertices.

Example

The region is the triangle x≥0x \ge 0, y≥0y \ge 0, x+y≤6x + y \le 6. Its largest inscribed disc has radius 6−32≈1.75746 - 3\sqrt{2} \approx 1.7574 and center (1.7574,1.7574)(1.7574, 1.7574). The start is x0=(1,4)x_0 = (1, 4), and the four line searches of L1 return (2,4)(2, 4), (1,5)(1, 5), (0,4)(0, 4) and (1,0)(1, 0). The last column gives the area of the hull divided by the area 18 of the triangle.

round new point center cc radius rr step of lines L5 to L10 area ratio
0 the four of L1 (1, 3.723) 0.903 all 4 edges touch; the longest, (0, 4) to (1, 0), has midpoint (0.5, 2), and the search finds (0, 1.875) 0.278
1 (0, 1.875) (0.937, 3.612) 0.937 longest tangent edge (1, 0) to (2, 4), midpoint (1.5, 2), new point (4.833, 1.167) 0.337
2 (4.833, 1.167) (1.798, 1.926) 1.610 the longest tangent edge lies on x+y=6x + y = 6, so the search returns its midpoint and the edge is marked; the next, (1, 0) to (4.833, 1.167), gives (3.094, 0) 0.730
3 (3.094, 0) (1.995, 1.659) 1.659 the longest unmarked tangent edge, (0, 1.875) to (1, 0), gives (0, 0.671) 0.798
4 (0, 0.671) (1.757, 1.757) 1.757 the four tangent edges, two of them on x=0x = 0, lie on the three sides of the triangle: stop 0.832

The method stops with the exact inscribed disc after eight line searches that found a point and four that did not. The hull covers only 83 percent of the triangle at the stop. The method needs the boundary only where the ball touches it.

On regions with a curved boundary the method does not stop, and the measured behavior depends on the shape. The table gives the area ratio ∣Pk∣/∣R∣|P_k| / |R| and the radius rkr_k for a unit disc started at (0.3,−0.2)(0.3, -0.2) and for the ellipse x2/4+y2≤1x^2/4 + y^2 \le 1 started at (0.5,0.3)(0.5, 0.3), whose largest inscribed disc has radius 1. The "longest edge" rule refines the longest edge of the whole hull in place of the longest tangent edge.

region and rule round 0 round 5 round 10 round 20 round 40 round 59
disc, tangent rule: area 0.595 0.906 0.965 0.987 0.996 0.998
disc, tangent rule: rkr_k 0.666 0.904 0.966 0.987 0.995 0.998
ellipse, tangent rule: area 0.588 0.872 0.880 0.880 0.880 0.880
ellipse, tangent rule: rkr_k 0.846 0.967 0.998 1.000 1.000 1.000
ellipse, longest edge: area 0.588 0.906 0.956 0.982 0.995 0.998

On the ellipse the tangent rule finds the right radius by round 20 and then keeps refining near the two points (0,±1)(0, \pm 1) where the ball touches, so the polytope never covers more than 88 percent of the region. This is correct for centering, but it means the polytope is not a good model of the whole region.

Correctness

The full proof shows four facts for a compact convex region with a nonempty interior, and one failure for a nonconvex region.

The ball is a linear program. As shown above, B(c,r)⊆PB(c, r) \subseteq P if and only if nf⋅c+r≤bfn_f \cdot c + r \le b_f for all faces.

Inclusion, nesting and monotone radius. The points of SS lie in RR and RR is convex, so each hull PkP_k lies in RR, and so does each ball. Points are only added, so Pk⊆Pk+1P_k \subseteq P_{k+1}, the old ball is feasible in the next round, and r0≤r1≤⋯≤r(R)r_0 \le r_1 \le \cdots \le r(R), where r(R)r(R) is the radius of the largest ball in RR.

The stop test is sound. If the outward search from the midpoint of a face, or from any point in its relative interior, does not move, then the hyperplane of that face supports RR. Otherwise a point of RR beyond the face and the face itself would span points of RR just outside the midpoint.

A fixed point is optimal. Suppose every tangent face supports RR. By LP duality and complementary slackness, there are weights λf≥0\lambda_f \ge 0 on the tangent faces with ∑λfnf=0\sum \lambda_f n_f = 0, ∑λf=1\sum \lambda_f = 1 and ∑λfbf=r\sum \lambda_f b_f = r. Any ball B(c′,r′)B(c', r') in RR satisfies nf⋅c′+r′≤bfn_f \cdot c' + r' \le b_f for these faces, and the weighted sum gives r′≤rr' \le r. So when the method stops at line L11, its ball is a largest ball in RR.

What is not guaranteed. The rule does not make the polytope converge to RR, as the ellipse shows. This page does not prove that rkr_k tends to r(R)r(R) when the method runs forever; the disc and ellipse runs only measure it. Director and Hachtel discuss convergence for convex regions in their paper, and the reader should take the exact statement from there.

Nonconvex regions. For the L-shaped region [0,4]×[0,2]∪[0,2]×[0,4][0,4] \times [0,2] \cup [0,2] \times [0,4] started at (1,1)(1, 1), the first hull is the quadrilateral with corners (0,1)(0, 1), (1,0)(1, 0), (4,1)(4, 1) and (1,4)(1, 4). It contains (2.4,2.4)(2.4, 2.4), which is not in RR, and its inscribed disc, with center (1.573,1.573)(1.573, 1.573) and radius 1.311, contains (2.5,2.5)(2.5, 2.5), which is not in RR either. The run ends with a radius of 1.464, while no disc in RR has a radius above 22/(1+2)≈1.1722\sqrt{2}/(1 + \sqrt{2}) \approx 1.172.

Proof: What simplicial approximation guarantees on a convex region, and how it fails on a nonconvex onefull

Setting. R⊂RnR \subset \mathbb{R}^n is a compact convex set with a nonempty interior, the acceptable region. For x∈Rx \in R and a direction d≠0d \ne 0, the line search returns exit(x,d)=x+t∗d\mathrm{exit}(x, d) = x + t^* d with t∗=max⁡{t≥0:x+td∈R}t^* = \max\{t \ge 0 : x + t d \in R\}. Because RR is convex and closed, {t≥0:x+td∈R}=[0,t∗]\{t \ge 0 : x + td \in R\} = [0, t^*]. The method starts from an interior point x0x_0. SkS_k is the set of boundary points after round kk, Pk=conv⁡(Sk)P_k = \operatorname{conv}(S_k), and (ck,rk)(c_k, r_k) is the optimum of the linear program of line L4 for PkP_k. The inscribed radius of a set AA is r(A)=sup⁡{r:B(c,r)⊆A for some c}r(A) = \sup\{r : B(c, r) \subseteq A \text{ for some } c\}.

Lemma 1 (the largest ball is a linear program). Let P={x:nf⋅x≤bf, f=1,…,m}P = \{x : n_f \cdot x \le b_f,\ f = 1, \ldots, m\} with ∥nf∥2=1\|n_f\|_2 = 1. Then B(c,r)⊆PB(c, r) \subseteq P if and only if nf⋅c+r≤bfn_f \cdot c + r \le b_f for every ff. So r(P)r(P) is the optimum of

max⁡ rsubject tonf⋅c+r≤bf (f=1,…,m),\max\ r \quad\text{subject to}\quad n_f \cdot c + r \le b_f \ (f = 1, \ldots, m),

a linear program in the n+1n + 1 variables (c,r)(c, r).

Proof. The largest value of nf⋅xn_f \cdot x over x∈B(c,r)x \in B(c, r) is nf⋅c+r∥nf∥2=nf⋅c+rn_f \cdot c + r \|n_f\|_2 = n_f \cdot c + r, reached at x=c+rnfx = c + r n_f. The ball lies in the half-space of face ff if and only if this value is at most bfb_f, and it lies in PP if and only if it lies in every half-space. □\square

The center cc of an optimal ball is often called a Chebyshev center of PP. If the norms are not normalized, the constraint reads nf⋅c+r∥nf∥2≤bfn_f \cdot c + r \|n_f\|_2 \le b_f, which is still linear in (c,r)(c, r).

Lemma 2 (the start). P0P_0 has a nonempty interior and contains x0x_0 in its interior.

Proof. x0x_0 is interior, so each of the 2n2n line searches along ±ej\pm e_j returns x0±tj±ejx_0 \pm t_j^{\pm} e_j with tj±>0t_j^{\pm} > 0. The hull of these points contains the cross-polytope {x0+∑jyjej:∑j∣yj∣/min⁡(tj+,tj−)≤1}\{x_0 + \sum_j y_j e_j : \sum_j |y_j| / \min(t_j^+, t_j^-) \le 1\}, which contains a ball around x0x_0. □\square

Theorem 1 (inclusion, nesting and monotone radius). For every round kk:

  1. B(ck,rk)⊆Pk⊆RB(c_k, r_k) \subseteq P_k \subseteq R.
  2. Pk⊆Pk+1P_k \subseteq P_{k+1}.
  3. r0≤r1≤⋯≤rk≤r(R)r_0 \le r_1 \le \cdots \le r_k \le r(R).

Proof. Every point of SkS_k is in RR, and RR is convex, so the convex hull PkP_k of SkS_k is in RR. The ball is in PkP_k by Lemma 1. Points are only added, so Sk⊆Sk+1S_k \subseteq S_{k+1} and Pk⊆Pk+1P_k \subseteq P_{k+1}. The optimal ball of round kk lies in Pk+1P_{k+1}, so it is feasible for the program of round k+1k + 1, and rk+1≥rkr_{k+1} \ge r_k. Finally, B(ck,rk)⊆RB(c_k, r_k) \subseteq R gives rk≤r(R)r_k \le r(R). □\square

So each center is a feasible design with a safety margin of at least rkr_k in every direction, and the margin never shrinks from one round to the next.

Lemma 3 (the stop test). Let FF be a facet of PkP_k with outward unit normal nFn_F and hyperplane nF⋅x=bFn_F \cdot x = b_F, and let qq be a point in the relative interior of FF. If exit(q,nF)=q\mathrm{exit}(q, n_F) = q, then R⊆{x:nF⋅x≤bF}R \subseteq \{x : n_F \cdot x \le b_F\}, so the hyperplane of FF supports RR.

Proof. F⊆Pk⊆RF \subseteq P_k \subseteq R, so q∈Rq \in R and the line search is defined. Suppose some y∈Ry \in R has α=nF⋅y−bF>0\alpha = n_F \cdot y - b_F > 0. Write y−q=αnF+wy - q = \alpha n_F + w, where ww is parallel to the hyperplane of FF. Since qq is in the relative interior of FF and the affine hull of FF is that hyperplane, q−δw∈Fq - \delta w \in F for some small δ>0\delta > 0. Let ε=δ/(1+δ)\varepsilon = \delta / (1 + \delta), so that ε/(1−ε)=δ\varepsilon / (1 - \varepsilon) = \delta. The point

z=(1−ε)(q−δw)+εy=q+εαnFz = (1 - \varepsilon)(q - \delta w) + \varepsilon y = q + \varepsilon \alpha n_F

is a convex combination of points of RR, so z∈Rz \in R. Then t∗≥εα>0t^* \ge \varepsilon \alpha > 0 for the search from qq along nFn_F, which contradicts exit(q,nF)=q\mathrm{exit}(q, n_F) = q. □\square

In the plane, a facet is an edge and the center of the largest (n−1)(n-1)-ball in it is its midpoint, which is in its relative interior. In higher dimensions the center of the largest ball inscribed in a facet is also in its relative interior when the facet has a nonempty relative interior.

Theorem 2 (a fixed point is optimal). Suppose that at round kk every face that touches the optimal ball, that is with nf⋅ck+rk=bfn_f \cdot c_k + r_k = b_f, supports RR. Then rk=r(R)r_k = r(R), and B(ck,rk)B(c_k, r_k) is a largest ball in RR. In particular, when the method stops at line L11, every tangent face was marked by Lemma 3, and the returned ball is a largest ball in RR.

Proof. The dual of the program of Lemma 1 is

min⁡∑fλfbfsubject to∑fλfnf=0,  ∑fλf=1,  λ≥0.\min \sum_f \lambda_f b_f \quad\text{subject to}\quad \sum_f \lambda_f n_f = 0,\ \ \sum_f \lambda_f = 1,\ \ \lambda \ge 0 .

The primal is feasible and bounded, so by strong duality the dual has an optimal λ\lambda with ∑fλfbf=rk\sum_f \lambda_f b_f = r_k, and by complementary slackness λf>0\lambda_f > 0 only for faces that touch the optimal ball. Take any ball B(c′,r′)⊆RB(c', r') \subseteq R. For each touching face ff, RR lies in its half-space, so by Lemma 1 nf⋅c′+r′≤bfn_f \cdot c' + r' \le b_f. Multiply by λf≥0\lambda_f \ge 0 and add:

r′=∑fλfr′=∑fλf(nf⋅c′+r′)−(∑fλfnf)⋅c′≤∑fλfbf=rk.r' = \sum_f \lambda_f r' = \sum_f \lambda_f (n_f \cdot c' + r') - \Big(\sum_f \lambda_f n_f\Big) \cdot c' \le \sum_f \lambda_f b_f = r_k .

So no ball in RR is larger than rkr_k, and with Theorem 1, rk=r(R)r_k = r(R). A mark set in an earlier round stays valid, because a supporting hyperplane of RR stays a supporting hyperplane. □\square

The proof shows more: the optimal ball needs only the faces that touch it to lie on supporting hyperplanes of RR. The polytope can be far from RR elsewhere. On the triangle of the page, the method stops with the exact inscribed disc while the hull covers only 83 percent of the triangle.

What is not proved here. Two natural claims are not given a proof on this page.

  • Convergence of the polytope to RR. The rule refines only faces that touch the ball, so the polytope need not fill RR. On the ellipse x2/4+y2≤1x^2/4 + y^2 \le 1 the tests measure that the area of PkP_k stays at 88.0 percent of the area of RR from round 20 to round 60, while rkr_k has reached r(R)=1r(R) = 1. The variant that refines the longest edge of the whole hull adds points with gaps that shrink along the whole boundary, and in the same test it reaches 99.8 percent.
  • Convergence of rkr_k to r(R)r(R) when the method never stops. The tests measure it on a disc (0.998 after 60 rounds) and an ellipse, but the general statement is not proved here. Director and Hachtel (1977) give the method and their own discussion of its convergence for convex regions, and the reader should consult the paper for its exact statement.

Theorem 3 (failure on a nonconvex region). Let RR be the L-shaped region [0,4]×[0,2] ∪ [0,2]×[0,4][0,4] \times [0,2] \,\cup\, [0,2] \times [0,4] and x0=(1,1)x_0 = (1, 1). Then P0⊈RP_0 \not\subseteq R, and the optimal ball of P0P_0 is not contained in RR.

Proof. The four line searches from (1,1)(1, 1) return (4,1)(4, 1), (1,4)(1, 4), (0,1)(0, 1) and (1,0)(1, 0). Their hull is the quadrilateral bounded by x+y≥1x + y \ge 1, x−3y≤1x - 3y \le 1, x+y≤5x + y \le 5 and y−3x≤1y - 3x \le 1. The point (2.4,2.4)(2.4, 2.4) satisfies all four inequalities, but it lies in the removed square (2,4]×(2,4](2, 4] \times (2, 4], so it is not in RR. By the symmetry in xx and yy, the program of Lemma 1 has an optimal center (a,a)(a, a) that touches x+y=5x + y = 5, x−3y=1x - 3y = 1 and y−3x=1y - 3x = 1, so (5−2a)/2=(1+2a)/10(5 - 2a)/\sqrt{2} = (1 + 2a)/\sqrt{10}. This gives a=(55−1)/(2+25)≈1.5729a = (5\sqrt{5} - 1)/(2 + 2\sqrt{5}) \approx 1.5729 and r0=(5−2a)/2≈1.3110r_0 = (5 - 2a)/\sqrt{2} \approx 1.3110. The ball contains c0+r0(1,1)/2=(2.5,2.5)c_0 + r_0 (1, 1)/\sqrt{2} = (2.5, 2.5), which is not in RR. □\square

The run goes on to stop with a radius of 1.4645, while every disc in RR has radius at most 22/(1+2)≈1.17162\sqrt{2}/(1 + \sqrt{2}) \approx 1.1716. It stops because the midpoint (2.5,2.5)(2.5, 2.5) of a tangent edge is outside RR, so the line search has no valid start, and the implementation reads this as a face on the boundary. So on a nonconvex region the method can report a center whose ball holds infeasible designs, and a radius that no ball in RR reaches.

Complexity

In the plane, round kk has m≤4+km \le 4 + k boundary points. The hull costs O(mlog⁡m)O(m \log m), the three-variable program costs O(m)O(m) with Megiddo's method for fixed dimension, and a round runs at most one successful line search plus one search for each newly marked face. Each face is marked at most once, so KK rounds cost O(K(mlog⁡m+s))O(K(m \log m + s)) arithmetic and circuit evaluations, where ss is the number of simulations per line search. In practice the simulations dominate: a bisection to a relative accuracy of 10−310^{-3} takes about 10 of them. The implementation uses the simplex method, which is fast on these small programs but has no such worst-case bound.

In nn dimensions the hull of mm points can have on the order of m⌊n/2⌋m^{\lfloor n/2 \rfloor} faces, by the upper bound theorem for polytopes, and the program has one constraint per face. This is why the method is practical only for a few parameters, often fewer than ten.

Properties

  • Inner approximation. For a convex region every polytope and every ball lie inside RR, so the center is always a working design and rkr_k is a certified margin.
  • Monotone. The radius never decreases, and the polytope only grows. With a distribution of the parameters, the probability of the polytope around the nominal point is a lower bound on the yield, and it grows from round to round, as Bandler and Chen note.
  • Exact at a fixed point. When all tangent faces support RR the ball is a largest ball in RR. On polygons and polytopes this stop can happen after finitely many rounds, as on the triangle.
  • Local refinement. Only the boundary near the ball is explored, which saves simulations but leaves the rest of the region unknown.
  • Needs convexity. Every guarantee above rests on the convexity of RR.

Variants and improvements

  • Scaling and ellipsoids. Scaling by the process covariance before the method turns the ball into an ellipsoid of equal probability density under a normal law. A worst-case tolerance box needs a different body and a different program.
  • Refining the whole boundary. Choosing the longest face overall, as in the ellipse table, makes the polytope fill the region, at the cost of searches far from the ball. Such a polytope is better for yield estimation.
  • Yield estimation. Director, Hachtel and Vidigal (1978) estimate the yield from the polytope, by integrating the parameter density over it, which is cheap since membership in a polytope needs no simulation.
  • Other centering methods. The design centering page lists the gravity method, statistical Monte Carlo methods and worst-case distance methods, which do not need a convex region.
  • Operability analysis. Goyal and Ierapetritou (2002) used the same steps to map the feasible operating region of chemical processes.

When to use it

Use it when the acceptable region is known or expected to be convex, the number of parameters is small, and each simulation is expensive enough that a few dozen line searches are the budget. It gives a centered design with a certified margin. Do not use it when the region may be nonconvex, for example when several specifications pull in different directions, or for more than a handful of parameters. In those cases a statistical method or a worst-case distance method is safer.

Pitfalls

  • Nonconvex regions. The polytope can contain failing designs, and the reported margin can be larger than any margin in RR, as in the L-shaped example. Nothing in the method warns about this; a check of the center and of a few points of the ball by simulation catches the worst cases.
  • Unscaled parameters. A ball in raw units treats a resistor in ohms and a width in micrometers as equal. Scale by the spreads first.
  • Inexact line searches. A bisection that stops early returns a point slightly inside or outside RR. A point outside breaks the inclusion. Bias the search to return the last feasible point.
  • Ties and degenerate faces. Several faces can touch the ball, and several can have the same size. A fixed tie rule keeps runs reproducible.
  • Using the polytope as the region. The polytope is accurate only near the ball. A yield computed from it is a lower bound, and it can be far below the true yield, as on the ellipse.
  • Starting point. x0x_0 must be strictly inside RR; otherwise the first hull can be flat and the program has no ball.

Implementations

Each implementation follows the pseudocode above. A comment @line links a line of code to a line of the pseudocode. Point at a line of the pseudocode to see the matching code. The build runs the native tests of each language.

regions.pyI0RawGitHub
# SPDX-License-Identifier: MIT
# Shared helper of the pr3 eda pages of https://algorithm.tamnd.com/. The authors are listed in prov/.
"""Plane regions with exact line search oracles, for the simplicial approximation tests.

Each region has inside(p), exit_point(x, d) and area. exit_point returns the
point where the ray x + t d, t >= 0, first leaves the closed region, for x
in the region; a point on the boundary that moves outward exits at t = 0.
"""

import math


class Ellipse:
    """(x - cx)^2 / a^2 + (y - cy)^2 / b^2 <= 1; a = b gives a disc."""

    def __init__(self, cx, cy, a, b):
        self.cx, self.cy, self.a, self.b = cx, cy, a, b
        self.area = math.pi * a * b

    def inside(self, p, eps=1e-9):
        return ((p[0] - self.cx) / self.a) ** 2 + ((p[1] - self.cy) / self.b) ** 2 <= 1 + eps

    def exit_point(self, x, d):
        u = ((x[0] - self.cx) / self.a, (x[1] - self.cy) / self.b)
        e = (d[0] / self.a, d[1] / self.b)
        qa = e[0] ** 2 + e[1] ** 2
        qb = 2 * (u[0] * e[0] + u[1] * e[1])
        qc = min(u[0] ** 2 + u[1] ** 2 - 1, 0.0)
        t = (-qb + math.sqrt(max(qb * qb - 4 * qa * qc, 0.0))) / (2 * qa)
        return (x[0] + t * d[0], x[1] + t * d[1])


class ConvexPolygon:
    """The intersection of the half-planes n . p <= c of its edges; vertices counterclockwise."""

    def __init__(self, vertices):
        self.vertices = vertices
        self.halfplanes = []
        for i, a in enumerate(vertices):
            b = vertices[(i + 1) % len(vertices)]
            dx, dy = b[0] - a[0], b[1] - a[1]
            n = (dy / math.hypot(dx, dy), -dx / math.hypot(dx, dy))
            self.halfplanes.append((n, n[0] * a[0] + n[1] * a[1]))
        self.area = abs(shoelace(vertices))

    def inside(self, p, eps=1e-9):
        return all(n[0] * p[0] + n[1] * p[1] <= c + eps for n, c in self.halfplanes)

    def exit_time(self, x, d):
        t = math.inf
        for n, c in self.halfplanes:
            nd = n[0] * d[0] + n[1] * d[1]
            if nd > 1e-15:
                t = min(t, max((c - n[0] * x[0] - n[1] * x[1]) / nd, 0.0))
        return t

    def exit_point(self, x, d):
        t = self.exit_time(x, d)
        return (x[0] + t * d[0], x[1] + t * d[1])


class Union:
    """A union of convex polygons, possibly nonconvex, with the exact first exit along a ray."""

    def __init__(self, pieces, area):
        self.pieces, self.area = pieces, area

    def inside(self, p, eps=1e-9):
        return any(q.inside(p, eps) for q in self.pieces)

    def exit_point(self, x, d):
        t = 0.0
        while True:
            p = (x[0] + t * d[0], x[1] + t * d[1])
            nxt = max((t + q.exit_time(p, d) for q in self.pieces if q.inside(p)), default=t)
            if nxt <= t + 1e-15:
                return p
            t = nxt


def shoelace(vertices):
    return sum(a[0] * b[1] - b[0] * a[1] for a, b in zip(vertices, vertices[1:] + vertices[:1])) / 2
simplicial_approximation.py 123 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/simplicial-approximation/. The authors are listed in prov/TB95X2.jsonl.
"""Simplicial approximation for design centering in the plane (after Director and Hachtel 1977).

The feasible region R is known only through a line search oracle:
exit_point(x, d) returns the point where the ray x + t d, t >= 0, first
leaves R, for a point x of R. The method keeps a set of boundary points,
takes their convex hull, puts the largest inscribed disc in the hull by a
linear program, and adds a new boundary point found from the middle of the
longest edge that touches the disc, along the outward normal of that edge.

simplicial_approximation returns one record per iteration with the hull,
the centre and the radius. The method assumes that R is convex; on a
nonconvex region the hull can leave R.
"""

import math


def convex_hull(points):
    """Andrew's monotone chain; vertices in counterclockwise order, no collinear ones."""
    pts = sorted(set(points))
    if len(pts) <= 2:
        return pts

    def cross(o, a, b):
        return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0])

    lower, upper = [], []
    for p in pts:
        while len(lower) >= 2 and cross(lower[-2], lower[-1], p) <= 1e-12:
            lower.pop()
        lower.append(p)
    for p in reversed(pts):
        while len(upper) >= 2 and cross(upper[-2], upper[-1], p) <= 1e-12:
            upper.pop()
        upper.append(p)
    return lower[:-1] + upper[:-1]


def edges(hull):
    """Edges (a, b, unit outward normal, offset): the hull is n . x <= offset."""
    out = []
    for i, a in enumerate(hull):
        b = hull[(i + 1) % len(hull)]
        dx, dy = b[0] - a[0], b[1] - a[1]
        length = math.hypot(dx, dy)
        nrm = (dy / length, -dx / length)
        out.append((a, b, nrm, nrm[0] * a[0] + nrm[1] * a[1]))
    return out


def inscribed_disc(faces, inner):
    """The LP max r subject to n_f . c + r <= b_f, by the simplex method.

    inner is a point strictly inside the polygon. The variables are
    c - inner split into positive and negative parts, and r, so the origin
    is a feasible basis. Bland's rule prevents cycling.
    """
    m = len(faces)
    rows = []
    for i, (_, _, (nx, ny), off) in enumerate(faces):
        slack = [1.0 if j == i else 0.0 for j in range(m)]
        rows.append([nx, -nx, ny, -ny, 1.0] + slack + [off - nx * inner[0] - ny * inner[1]])
    cost = [0.0, 0.0, 0.0, 0.0, -1.0] + [0.0] * m + [0.0]
    basis = [5 + i for i in range(m)]
    while True:
        enter = next((j for j in range(5 + m) if cost[j] < -1e-12), None)
        if enter is None:
            break
        best = None
        for i in range(m):
            if rows[i][enter] > 1e-12:
                ratio = rows[i][-1] / rows[i][enter]
                if best is None or ratio < best[0] - 1e-15 or (abs(ratio - best[0]) <= 1e-15 and basis[i] < basis[best[1]]):
                    best = (ratio, i)
        i = best[1]
        piv = rows[i][enter]
        rows[i] = [x / piv for x in rows[i]]
        for k in range(m):
            if k != i and rows[k][enter] != 0.0:
                f = rows[k][enter]
                rows[k] = [x - f * y for x, y in zip(rows[k], rows[i])]
        f = cost[enter]
        cost = [x - f * y for x, y in zip(cost, rows[i])]
        basis[i] = enter
    x = [0.0] * 5
    for i, j in enumerate(basis):
        if j < 5:
            x[j] = rows[i][-1]
    return (inner[0] + x[0] - x[1], inner[1] + x[2] - x[3]), x[4]


def simplicial_approximation(exit_point, x0, iterations, rule="tangent", tol=1e-9):
    points = [exit_point(x0, d) for d in ((1, 0), (0, 1), (-1, 0), (0, -1))]  # @line L1
    on_boundary = set()
    history = []
    for _ in range(iterations):  # @line L2
        hull = convex_hull(points)  # @line L3
        faces = edges(hull)
        inner = (sum(p[0] for p in hull) / len(hull), sum(p[1] for p in hull) / len(hull))
        centre, radius = inscribed_disc(faces, inner)  # @line L4
        history.append({"hull": hull, "centre": centre, "radius": radius})
        scale = max(1.0, radius)
        if rule == "tangent":  # @line L5
            cand = [f for f in faces if f[3] - f[2][0] * centre[0] - f[2][1] * centre[1] - radius <= 1e-7 * scale]
        else:
            cand = list(faces)
        cand.sort(key=lambda f: -math.dist(f[0], f[1]))  # @line L6
        added = False
        for a, b, nrm, _ in cand:
            if (a, b) in on_boundary:
                continue
            mid = ((a[0] + b[0]) / 2, (a[1] + b[1]) / 2)  # @line L7
            y = exit_point(mid, nrm)  # @line L8
            if math.dist(y, mid) > tol * scale:
                points.append(y)  # @line L9
                added = True
                break
            on_boundary.add((a, b))  # @line L10
        if not added:  # @line L11
            break
    return history  # @line L12
test_simplicial_approximation.py 133 lines
# SPDX-License-Identifier: MIT
# Part of https://algorithm.tamnd.com/simplicial-approximation/. The authors are listed in prov/TB95X2.jsonl.

import itertools
import math
import random

from regions import ConvexPolygon, Ellipse, Union, shoelace
from simplicial_approximation import convex_hull, edges, inscribed_disc, simplicial_approximation

TRIANGLE = ConvexPolygon([(0, 0), (6, 0), (0, 6)])
PENTAGON = ConvexPolygon([(0, 0), (4, 0), (5, 3), (2, 5), (-1, 3)])
DISC = Ellipse(0, 0, 1, 1)
ELLIPSE = Ellipse(0, 0, 2, 1)
L_SHAPE = Union([ConvexPolygon([(0, 0), (4, 0), (4, 2), (0, 2)]), ConvexPolygon([(0, 0), (2, 0), (2, 4), (0, 4)])], 12.0)


def solve3(a, y):
    det = lambda m: (m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1]) - m[0][1] * (m[1][0] * m[2][2] - m[1][2] * m[2][0]) + m[0][2] * (m[1][0] * m[2][1] - m[1][1] * m[2][0]))
    d = det(a)
    if abs(d) < 1e-12:
        return None
    out = []
    for j in range(3):
        m = [row[:] for row in a]
        for i in range(3):
            m[i][j] = y[i]
        out.append(det(m) / d)
    return out


def brute_radius(faces):
    # The LP optimum is at a vertex: try every triple of tight faces.
    best = 0.0
    for f in itertools.combinations(faces, 3):
        x = solve3([[n[0], n[1], 1.0] for _, _, n, _ in f], [b for _, _, _, b in f])
        if x and all(n[0] * x[0] + n[1] * x[1] + x[2] <= b + 1e-9 for _, _, n, b in faces):
            best = max(best, x[2])
    return best


def random_convex_polygon(rng):
    while True:
        hull = convex_hull([(rng.uniform(-3, 3), rng.uniform(-3, 3)) for _ in range(rng.randint(3, 9))])
        if len(hull) >= 3 and abs(shoelace(hull)) > 1:
            return hull


def test_convex_hull_contains_all_points():
    rng = random.Random(5)
    for _ in range(100):
        pts = [(rng.uniform(-1, 1), rng.uniform(-1, 1)) for _ in range(rng.randint(3, 12))]
        hull = convex_hull(pts)
        assert set(hull) <= set(pts)
        assert all(n[0] * p[0] + n[1] * p[1] <= b + 1e-12 for _, _, n, b in edges(hull) for p in pts)


def test_inscribed_disc_lp_against_brute_force():
    rng = random.Random(6)
    for _ in range(150):
        faces = edges(random_convex_polygon(rng))
        hull = [f[0] for f in faces]
        inner = (sum(p[0] for p in hull) / len(hull), sum(p[1] for p in hull) / len(hull))
        centre, radius = inscribed_disc(faces, inner)
        assert math.isclose(radius, brute_radius(faces), rel_tol=1e-9, abs_tol=1e-12)
        assert all(n[0] * centre[0] + n[1] * centre[1] + radius <= b + 1e-9 for _, _, n, b in faces)


def check_run(region, x0, iterations, r_region):
    history = simplicial_approximation(region.exit_point, x0, iterations)
    previous = None
    for rec in history:
        hull, c, r = rec["hull"], rec["centre"], rec["radius"]
        # Every vertex is a point of R, so for convex R the whole hull is in R.
        assert all(region.inside(p) for p in hull)
        assert all(n[0] * c[0] + n[1] * c[1] + r <= b + 1e-9 for _, _, n, b in edges(hull))
        assert r <= r_region + 1e-9
        if previous:
            assert r >= previous["radius"] - 1e-9
            assert all(n[0] * p[0] + n[1] * p[1] <= b + 1e-9 for _, _, n, b in edges(hull) for p in previous["hull"])
        previous = rec
    return history


def test_convex_regions_inside_nested_and_monotone():
    check_run(DISC, (0.3, -0.2), 60, 1.0)
    check_run(ELLIPSE, (0.5, 0.3), 60, 1.0)
    check_run(TRIANGLE, (1.0, 4.0), 60, 6 - 3 * math.sqrt(2))
    check_run(PENTAGON, (1.0, 1.0), 60, brute_radius(edges(PENTAGON.vertices)))


def test_polygon_stops_at_its_inscribed_disc():
    h = check_run(TRIANGLE, (1.0, 4.0), 60, 6 - 3 * math.sqrt(2))
    r = 6 - 3 * math.sqrt(2)
    assert len(h) == 5
    assert math.isclose(h[-1]["radius"], r, rel_tol=1e-9)
    assert math.dist(h[-1]["centre"], (r, r)) < 1e-8
    rng = random.Random(7)
    for _ in range(40):
        region = ConvexPolygon(random_convex_polygon(rng))
        x0 = tuple(sum(p[i] for p in region.vertices) / len(region.vertices) for i in range(2))
        want = brute_radius(edges(region.vertices))
        h = check_run(region, x0, 200, want)
        assert len(h) < 200
        assert math.isclose(h[-1]["radius"], want, rel_tol=1e-7)


def test_measured_area_ratios():
    # Measured, not proved: the tangent rule fills the disc but stalls on the ellipse.
    disc = simplicial_approximation(DISC.exit_point, (0.3, -0.2), 60)
    ratio = [shoelace(rec["hull"]) / DISC.area for rec in disc]
    assert [round(ratio[k], 3) for k in (0, 10, 40, 59)] == [0.595, 0.965, 0.996, 0.998]
    ell = simplicial_approximation(ELLIPSE.exit_point, (0.5, 0.3), 60)
    assert round(shoelace(ell[-1]["hull"]) / ELLIPSE.area, 3) == 0.880
    assert math.isclose(ell[-1]["radius"], 1.0, rel_tol=1e-6)
    longest = simplicial_approximation(ELLIPSE.exit_point, (0.5, 0.3), 60, rule="longest")
    assert shoelace(longest[-1]["hull"]) / ELLIPSE.area > 0.997


def test_nonconvex_region_breaks_the_method():
    h = simplicial_approximation(L_SHAPE.exit_point, (1.0, 1.0), 20)
    first = h[0]
    assert first["hull"] == [(0.0, 1.0), (1.0, 0.0), (4.0, 1.0), (1.0, 4.0)]
    # The hull holds points that are not in R.
    assert not L_SHAPE.inside((2.4, 2.4))
    assert all(n[0] * 2.4 + n[1] * 2.4 <= b for _, _, n, b in edges(first["hull"]))
    # The final disc is larger than any disc in R and pokes out of R.
    last = h[-1]
    c, r = last["centre"], last["radius"]
    best = 2 * math.sqrt(2) / (1 + math.sqrt(2))
    assert r > best + 0.2
    far = (c[0] + r / math.sqrt(2), c[1] + r / math.sqrt(2))
    assert not L_SHAPE.inside(far)

History

Director and Hachtel published simplicial approximation in 1977, at a time when design centering by Monte Carlo methods needed thousands of simulations. Their idea was to replace the unknown region by a polytope that is cheap to work with, and to spend simulations only on line searches. Director, Hachtel and Vidigal (1978) used the same polytope to estimate the yield. Later surveys, such as that of Bandler and Chen (1988), list the method among the first geometric centering methods and note that its convexity assumption limits its use. The method was later applied to the operability of chemical processes by Goyal and Ierapetritou (2002).

References

  1. Stephen W. Director and Gary D. Hachtel, The simplicial approximation approach to design centering, IEEE Transactions on Circuits and Systems CAS-24(7), 363 to 372, July 1977, the method (boundary points by line searches, the convex hull, the inscribed hypersphere by a linear program, expansion from the largest face that touches the sphere) and its assumption that the region is convex; the section numbers were not checked
  2. Stephen W. Director, Gary D. Hachtel and Luis M. Vidigal, Computationally efficient yield estimation procedures based on simplicial approximation, IEEE Transactions on Circuits and Systems 25(3), 121 to 130, 1978, yield estimation from the polytope of the method
  3. John W. Bandler and Shao Hua Chen, Circuit optimization, the state of the art, IEEE Transactions on Microwave Theory and Techniques 36(2), 424 to 443, February 1988, Section V.B, the simplicial approach, which gives a lower bound on the yield that increases monotonically and is limited by its convexity assumption
  4. Vishal Goyal and Marianthi G. Ierapetritou, Determination of operability limits using simplicial approximation, AIChE Journal 48(12), 2002, a step-by-step restatement of the method and its use outside circuit design (the page range was not confirmed)

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH1 sketch
  • a full proof of time.worst
  • a full proof of space.extra
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
Code (python)I0 not checked yet
  • the tests did not run in this build
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW2 basic
  • a scene preset for the example