Faster Lasso regression
Fit a Lasso regression on a 1990 × 3980 random design faster than scikit-learn, reaching the same objective value to within 1e-5.
Update the checks and the files they read from shoal-catalog cfb093e61504
Browse files+1 −0 cover.svg added View file
| @@ -0,0 +1 @@ | ||
| 1 | +<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 304" role="img"><title>The Lasso solution for an instance of the task at n = 12: 21 non-zero coefficients of 120, the other 99 exactly zero</title><style>svg{--ink:#1f1f1f;--ink2:#3c4043;--faint:#9aa0a6;--line:#dadce0;--sand:#b8862c;--bg:#ffffff;--muted:#5f6368;--f:#9b59d0}@media (prefers-color-scheme: dark){svg{--ink:#e8eaed;--ink2:#c4c7c5;--faint:#6f7479;--line:#3c4043;--sand:#d9b26a;--bg:#1f2023;--muted:#9aa0a6;--f:#c9a2f3}}.ink{fill:var(--ink)}.ink-s{stroke:var(--ink);fill:none}.ink2-s{stroke:var(--ink2);fill:none}.f{fill:var(--f)}.f-s{stroke:var(--f);fill:none}.f-soft{fill:var(--f);fill-opacity:.14}.sand{fill:var(--sand)}.sand-s{stroke:var(--sand);fill:none}.faint{fill:var(--faint)}.faint-s{stroke:var(--faint);fill:none}.ring{stroke:var(--bg);stroke-width:3}.bg{fill:var(--bg)}.soft{fill-opacity:.16}.lbl{fill:var(--muted);font:400 19px ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}line,path,polyline{stroke-linecap:round;stroke-linejoin:round}</style><line class="faint-s" x1="20" y1="214" x2="620" y2="214" stroke-width="2"/><circle class="faint" cx="35.9" cy="214" r="3"/><circle class="faint" cx="40.8" cy="214" r="3"/><circle class="faint" cx="45.8" cy="214" r="3"/><circle class="faint" cx="55.6" cy="214" r="3"/><circle class="faint" cx="65.5" cy="214" r="3"/><circle class="faint" cx="70.5" cy="214" r="3"/><circle class="faint" cx="75.4" cy="214" r="3"/><circle class="faint" cx="80.4" cy="214" r="3"/><circle class="faint" cx="85.3" cy="214" r="3"/><circle class="faint" cx="90.2" cy="214" r="3"/><circle class="faint" cx="95.2" cy="214" r="3"/><circle class="faint" cx="100.1" cy="214" r="3"/><circle class="faint" cx="110" cy="214" r="3"/><circle class="faint" cx="114.9" cy="214" r="3"/><circle class="faint" cx="119.9" cy="214" r="3"/><circle class="faint" cx="124.8" cy="214" r="3"/><circle class="faint" cx="129.8" cy="214" r="3"/><circle class="faint" cx="134.7" cy="214" r="3"/><circle class="faint" cx="139.6" cy="214" r="3"/><circle class="faint" cx="144.6" cy="214" r="3"/><circle class="faint" cx="149.5" cy="214" r="3"/><circle class="faint" cx="154.5" cy="214" r="3"/><circle class="faint" cx="169.3" cy="214" r="3"/><circle class="faint" cx="179.2" cy="214" r="3"/><circle class="faint" cx="184.1" cy="214" r="3"/><circle class="faint" cx="189.1" cy="214" r="3"/><circle class="faint" cx="203.9" cy="214" r="3"/><circle class="faint" cx="208.8" cy="214" r="3"/><circle class="faint" cx="213.8" cy="214" r="3"/><circle class="faint" cx="218.7" cy="214" r="3"/><circle class="faint" cx="223.6" cy="214" r="3"/><circle class="faint" cx="228.6" cy="214" r="3"/><circle class="faint" cx="233.5" cy="214" r="3"/><circle class="faint" cx="238.5" cy="214" r="3"/><circle class="faint" cx="243.4" cy="214" r="3"/><circle class="faint" cx="248.4" cy="214" r="3"/><circle class="faint" cx="263.2" cy="214" r="3"/><circle class="faint" cx="268.1" cy="214" r="3"/><circle class="faint" cx="273.1" cy="214" r="3"/><circle class="faint" cx="278" cy="214" r="3"/><circle class="faint" cx="282.9" cy="214" r="3"/><circle class="faint" cx="287.9" cy="214" r="3"/><circle class="faint" cx="292.8" cy="214" r="3"/><circle class="faint" cx="297.8" cy="214" r="3"/><circle class="faint" cx="307.6" cy="214" r="3"/><circle class="faint" cx="312.6" cy="214" r="3"/><circle class="faint" cx="317.5" cy="214" r="3"/><circle class="faint" cx="327.4" cy="214" r="3"/><circle class="faint" cx="332.4" cy="214" r="3"/><circle class="faint" cx="337.3" cy="214" r="3"/><circle class="faint" cx="347.2" cy="214" r="3"/><circle class="faint" cx="352.1" cy="214" r="3"/><circle class="faint" cx="357.1" cy="214" r="3"/><circle class="faint" cx="362" cy="214" r="3"/><circle class="faint" cx="366.9" cy="214" r="3"/><circle class="faint" cx="376.8" cy="214" r="3"/><circle class="faint" cx="381.8" cy="214" r="3"/><circle class="faint" cx="386.7" cy="214" r="3"/><circle class="faint" cx="391.6" cy="214" r="3"/><circle class="faint" cx="396.6" cy="214" r="3"/><circle class="faint" cx="401.5" cy="214" r="3"/><circle class="faint" cx="406.5" cy="214" r="3"/><circle class="faint" cx="411.4" cy="214" r="3"/><circle class="faint" cx="416.4" cy="214" r="3"/><circle class="faint" cx="426.2" cy="214" r="3"/><circle class="faint" cx="431.2" cy="214" r="3"/><circle class="faint" cx="436.1" cy="214" r="3"/><circle class="faint" cx="441.1" cy="214" r="3"/><circle class="faint" cx="446" cy="214" r="3"/><circle class="faint" cx="450.9" cy="214" r="3"/><circle class="faint" cx="455.9" cy="214" r="3"/><circle class="faint" cx="460.8" cy="214" r="3"/><circle class="faint" cx="465.8" cy="214" r="3"/><circle class="faint" cx="470.7" cy="214" r="3"/><circle class="faint" cx="475.6" cy="214" r="3"/><circle class="faint" cx="480.6" cy="214" r="3"/><circle class="faint" cx="485.5" cy="214" r="3"/><circle class="faint" cx="490.5" cy="214" r="3"/><circle class="faint" cx="495.4" cy="214" r="3"/><circle class="faint" cx="505.3" cy="214" r="3"/><circle class="faint" cx="510.2" cy="214" r="3"/><circle class="faint" cx="515.2" cy="214" r="3"/><circle class="faint" cx="520.1" cy="214" r="3"/><circle class="faint" cx="525.1" cy="214" r="3"/><circle class="faint" cx="530" cy="214" r="3"/><circle class="faint" cx="534.9" cy="214" r="3"/><circle class="faint" cx="539.9" cy="214" r="3"/><circle class="faint" cx="544.8" cy="214" r="3"/><circle class="faint" cx="549.8" cy="214" r="3"/><circle class="faint" cx="554.7" cy="214" r="3"/><circle class="faint" cx="559.6" cy="214" r="3"/><circle class="faint" cx="564.6" cy="214" r="3"/><circle class="faint" cx="569.5" cy="214" r="3"/><circle class="faint" cx="574.5" cy="214" r="3"/><circle class="faint" cx="579.4" cy="214" r="3"/><circle class="faint" cx="584.4" cy="214" r="3"/><circle class="faint" cx="589.3" cy="214" r="3"/><circle class="faint" cx="604.1" cy="214" r="3"/><circle class="faint" cx="609.1" cy="214" r="3"/><line class="f-s" x1="26" y1="214" x2="26" y2="212.3" stroke-width="4"/><circle class="f ring" cx="26" cy="212.3" r="6"/><line class="f-s" x1="30.9" y1="214" x2="30.9" y2="184.7" stroke-width="4"/><circle class="f ring" cx="30.9" cy="184.7" r="6"/><line class="f-s" x1="50.7" y1="214" x2="50.7" y2="153.3" stroke-width="4"/><circle class="f ring" cx="50.7" cy="153.3" r="6"/><line class="f-s" x1="60.6" y1="214" x2="60.6" y2="208.1" stroke-width="4"/><circle class="f ring" cx="60.6" cy="208.1" r="6"/><line class="f-s" x1="105.1" y1="214" x2="105.1" y2="126.5" stroke-width="4"/><circle class="f ring" cx="105.1" cy="126.5" r="6"/><line class="f-s" x1="159.4" y1="214" x2="159.4" y2="213.7" stroke-width="4"/><circle class="f ring" cx="159.4" cy="213.7" r="6"/><line class="f-s" x1="164.4" y1="214" x2="164.4" y2="154.1" stroke-width="4"/><circle class="f ring" cx="164.4" cy="154.1" r="6"/><line class="f-s" x1="174.2" y1="214" x2="174.2" y2="211.8" stroke-width="4"/><circle class="f ring" cx="174.2" cy="211.8" r="6"/><line class="f-s" x1="194" y1="214" x2="194" y2="212.1" stroke-width="4"/><circle class="f ring" cx="194" cy="212.1" r="6"/><line class="f-s" x1="198.9" y1="214" x2="198.9" y2="204.5" stroke-width="4"/><circle class="f ring" cx="198.9" cy="204.5" r="6"/><line class="f-s" x1="253.3" y1="214" x2="253.3" y2="207.3" stroke-width="4"/><circle class="f ring" cx="253.3" cy="207.3" r="6"/><line class="f-s" x1="258.2" y1="214" x2="258.2" y2="211.9" stroke-width="4"/><circle class="f ring" cx="258.2" cy="211.9" r="6"/><line class="f-s" x1="302.7" y1="214" x2="302.7" y2="88.6" stroke-width="4"/><circle class="f ring" cx="302.7" cy="88.6" r="6"/><line class="f-s" x1="322.5" y1="214" x2="322.5" y2="211.8" stroke-width="4"/><circle class="f ring" cx="322.5" cy="211.8" r="6"/><line class="f-s" x1="342.2" y1="214" x2="342.2" y2="30" stroke-width="4"/><circle class="f ring" cx="342.2" cy="30" r="6"/><line class="f-s" x1="371.9" y1="214" x2="371.9" y2="119.6" stroke-width="4"/><circle class="f ring" cx="371.9" cy="119.6" r="6"/><line class="f-s" x1="421.3" y1="214" x2="421.3" y2="214" stroke-width="4"/><circle class="f ring" cx="421.3" cy="214" r="6"/><line class="f-s" x1="500.4" y1="214" x2="500.4" y2="132.5" stroke-width="4"/><circle class="f ring" cx="500.4" cy="132.5" r="6"/><line class="f-s" x1="594.2" y1="214" x2="594.2" y2="192.3" stroke-width="4"/><circle class="f ring" cx="594.2" cy="192.3" r="6"/><line class="f-s" x1="599.2" y1="214" x2="599.2" y2="211.6" stroke-width="4"/><circle class="f ring" cx="599.2" cy="211.6" r="6"/><line class="f-s" x1="614" y1="214" x2="614" y2="158.9" stroke-width="4"/><circle class="f ring" cx="614" cy="158.9" r="6"/><text class="lbl" x="320" y="288" text-anchor="middle">120 coefficients, 99 of them exactly zero</text></svg> | |
+63 −0 figure.py added View file
| @@ -0,0 +1,63 @@ | ||
| 1 | +"""What the Lasso returns: a solution that is mostly exact zeros. | |
| 2 | + | |
| 3 | +No data file: the instance is the task's own generator (README, "Task"), at a size that fits on a card. With n = 12 | |
| 4 | +it draws X (m = 5n by d = 10n, standard normal), beta with n standard normal non-zeros at random positions and | |
| 5 | +y = X beta + 0.01 eps, then minimises f(w) = 1/(2m)||y - Xw||^2 + 0.1||w||_1 by cyclic coordinate descent, the | |
| 6 | +reference solver's method. The figure checks the solution with the optimality conditions of that objective, so the | |
| 7 | +zeros drawn are exact zeros, not small numbers. | |
| 8 | +""" | |
| 9 | +import random | |
| 10 | +from pathlib import Path | |
| 11 | + | |
| 12 | +import kit | |
| 13 | + | |
| 14 | +ALPHA = 0.1 | |
| 15 | +n = 12 | |
| 16 | +m, d = 5 * n, 10 * n | |
| 17 | +rnd = random.Random(0) | |
| 18 | +X = [[rnd.gauss(0, 1) for _ in range(d)] for _ in range(m)] | |
| 19 | +beta = [0.0] * d | |
| 20 | +for j in rnd.sample(range(d), n): | |
| 21 | + beta[j] = rnd.gauss(0, 1) | |
| 22 | +y = [sum(X[i][j] * beta[j] for j in range(d)) + 0.01 * rnd.gauss(0, 1) for i in range(m)] | |
| 23 | + | |
| 24 | +col = [[X[i][j] for i in range(m)] for j in range(d)] | |
| 25 | +nrm = [sum(v * v for v in c) / m for c in col] | |
| 26 | +w = [0.0] * d | |
| 27 | +r = list(y) # r = y - Xw | |
| 28 | +for _ in range(2000): | |
| 29 | + shift = 0.0 | |
| 30 | + for j in range(d): | |
| 31 | + rho = sum(col[j][i] * r[i] for i in range(m)) / m + nrm[j] * w[j] | |
| 32 | + new = (abs(rho) - ALPHA) / nrm[j] * (1 if rho > 0 else -1) if abs(rho) > ALPHA else 0.0 | |
| 33 | + if new != w[j]: | |
| 34 | + shift = max(shift, abs(new - w[j])) | |
| 35 | + for i in range(m): | |
| 36 | + r[i] -= col[j][i] * (new - w[j]) | |
| 37 | + w[j] = new | |
| 38 | + if shift < 1e-12: | |
| 39 | + break | |
| 40 | +else: | |
| 41 | + raise SystemExit('coordinate descent did not converge') | |
| 42 | + | |
| 43 | +# optimality of the Lasso objective: |grad| <= alpha where w_j = 0, = alpha sign(w_j) where it is not | |
| 44 | +for j in range(d): | |
| 45 | + g = sum(col[j][i] * r[i] for i in range(m)) / m | |
| 46 | + assert abs(g) <= ALPHA + 1e-9 if w[j] == 0 else abs(g - ALPHA * (1 if w[j] > 0 else -1)) < 1e-9 | |
| 47 | +nz = [j for j in range(d) if w[j] != 0] | |
| 48 | +assert 0 < len(nz) < d | |
| 49 | + | |
| 50 | +base, top = 214.0, 30.0 | |
| 51 | +X_ = lambda j: 26 + j * (588 / (d - 1)) | |
| 52 | +hi = max(abs(v) for v in w) | |
| 53 | +body = kit.line(20, base, 620, base, 'faint-s', 2) | |
| 54 | +body += ''.join(kit.circle(X_(j), base, 3, 'faint') for j in range(d) if w[j] == 0) | |
| 55 | +for j in nz: | |
| 56 | + yv = base - abs(w[j]) / hi * (base - top) | |
| 57 | + body += kit.line(X_(j), base, X_(j), yv, 'f-s', 4) | |
| 58 | + body += kit.dot(X_(j), yv, 6, 'f') | |
| 59 | +label = f'{d} coefficients, {d - len(nz)} of them exactly zero' | |
| 60 | +kit.write(__file__, 'computer-science', body, label, | |
| 61 | + f'The Lasso solution for an instance of the task at n = {n}: {len(nz)} non-zero coefficients ' | |
| 62 | + f'of {d}, the other {d - len(nz)} exactly zero') | |
| 63 | +print(label, 'nonzero at', nz) | |
+124 −0 kit.py added View file
| @@ -0,0 +1,124 @@ | ||
| 1 | +"""The drawing kit for problem cards: one canvas, one palette, light and dark built in. | |
| 2 | + | |
| 3 | +It lives here only: tools/cards/kit.py in the catalog, which each problem folder links as kit.py. The Shoal site | |
| 4 | +serves no copy of it: a card's cover is the problem's poster (tools/cards/posters.py), and what this kit draws is kept | |
| 5 | +for the problem's own page. | |
| 6 | + | |
| 7 | +A figure.py at a problem's root, with this file beside it, imports it, draws the problem's object and writes cover.svg | |
| 8 | +next to itself (docs/cards.md says what a figure must be): | |
| 9 | + | |
| 10 | + import kit | |
| 11 | + body = kit.circle(320, 152, 40, 'f') | |
| 12 | + kit.write(__file__, 'mathematics', body, label='what is drawn') | |
| 13 | + | |
| 14 | +Classes (each colour means one thing on a figure; pick the meaning, then the class): | |
| 15 | + ink, ink-s the object itself (fill / stroke) | |
| 16 | + ink2-s secondary structure (edges, outlines) | |
| 17 | + f, f-s, f-soft the field's colour: the part the question is about (fill / stroke / pale fill) | |
| 18 | + sand, sand-s the one accent: a second colour class, an open or contested part | |
| 19 | + faint, faint-s context: grids, axes, ghosts | |
| 20 | + ring a halo in the page's colour, so dots read on top of lines | |
| 21 | + bg a fill in the page's colour, to hide what lies behind (front faces, occluding balls) | |
| 22 | + soft a pale fill of any class's colour: add it next to f, sand or ink (class="sand soft") | |
| 23 | + lbl the one label line | |
| 24 | +""" | |
| 25 | +import math | |
| 26 | +from pathlib import Path | |
| 27 | + | |
| 28 | +W, H = 640, 304 # shown at 320 x 152 on a card, larger on a featured card | |
| 29 | + | |
| 30 | +# the site's field colours (public/app.css, --f-*), light and dark | |
| 31 | +FIELD = { | |
| 32 | + 'mathematics': ('#4f6bed', '#93a6ff'), 'computer-science': ('#9b59d0', '#c9a2f3'), | |
| 33 | + 'physics-astronomy': ('#129d96', '#5fd0c8'), 'chemistry-materials': ('#d08a17', '#f2c063'), | |
| 34 | + 'life-health': ('#5a9e2c', '#a3d47a'), 'earth-environment': ('#2a8ccf', '#7cc4f2'), | |
| 35 | + 'engineering-energy': ('#d4533f', '#f29484'), 'social-economics': ('#c2448f', '#f09ac8'), | |
| 36 | +} | |
| 37 | +LIGHT = dict(ink='#1f1f1f', ink2='#3c4043', faint='#9aa0a6', line='#dadce0', sand='#b8862c', bg='#ffffff', muted='#5f6368') | |
| 38 | +DARK = dict(ink='#e8eaed', ink2='#c4c7c5', faint='#6f7479', line='#3c4043', sand='#d9b26a', bg='#1f2023', muted='#9aa0a6') | |
| 39 | + | |
| 40 | + | |
| 41 | +def _vars(c, f): | |
| 42 | + return (f'--ink:{c["ink"]};--ink2:{c["ink2"]};--faint:{c["faint"]};--line:{c["line"]};--sand:{c["sand"]};' | |
| 43 | + f'--bg:{c["bg"]};--muted:{c["muted"]};--f:{f}') | |
| 44 | + | |
| 45 | + | |
| 46 | +def style(field): | |
| 47 | + light, dark = FIELD[field] | |
| 48 | + return (f'<style>svg{{{_vars(LIGHT, light)}}}@media (prefers-color-scheme: dark){{svg{{{_vars(DARK, dark)}}}}}' | |
| 49 | + '.ink{fill:var(--ink)}.ink-s{stroke:var(--ink);fill:none}.ink2-s{stroke:var(--ink2);fill:none}' | |
| 50 | + '.f{fill:var(--f)}.f-s{stroke:var(--f);fill:none}.f-soft{fill:var(--f);fill-opacity:.14}' | |
| 51 | + '.sand{fill:var(--sand)}.sand-s{stroke:var(--sand);fill:none}.faint{fill:var(--faint)}.faint-s{stroke:var(--faint);fill:none}' | |
| 52 | + '.ring{stroke:var(--bg);stroke-width:3}.bg{fill:var(--bg)}.soft{fill-opacity:.16}' | |
| 53 | + '.lbl{fill:var(--muted);font:400 19px ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}' | |
| 54 | + 'line,path,polyline{stroke-linecap:round;stroke-linejoin:round}</style>') | |
| 55 | + | |
| 56 | + | |
| 57 | +def f1(n): | |
| 58 | + return f'{round(n, 1):g}' | |
| 59 | + | |
| 60 | + | |
| 61 | +def circle(x, y, r, cls, extra=''): | |
| 62 | + return f'<circle class="{cls}" cx="{f1(x)}" cy="{f1(y)}" r="{f1(r)}"{extra}/>' | |
| 63 | + | |
| 64 | + | |
| 65 | +def dot(x, y, r=6, cls='ink'): | |
| 66 | + """A point that stays readable on top of lines: filled, with a halo in the page's colour.""" | |
| 67 | + return circle(x, y, r, f'{cls} ring') | |
| 68 | + | |
| 69 | + | |
| 70 | +def line(x1, y1, x2, y2, cls='ink2-s', w=2, extra=''): | |
| 71 | + return f'<line class="{cls}" x1="{f1(x1)}" y1="{f1(y1)}" x2="{f1(x2)}" y2="{f1(y2)}" stroke-width="{w}"{extra}/>' | |
| 72 | + | |
| 73 | + | |
| 74 | +def path(d, cls='ink2-s', w=2, extra=''): | |
| 75 | + return f'<path class="{cls}" d="{d}" stroke-width="{w}"{extra}/>' | |
| 76 | + | |
| 77 | + | |
| 78 | +def polygon(pts, cls='f-soft', extra=''): | |
| 79 | + return f'<polygon class="{cls}" points="{" ".join(f"{f1(x)},{f1(y)}" for x, y in pts)}"{extra}/>' | |
| 80 | + | |
| 81 | + | |
| 82 | +def polyline(pts, cls='ink2-s', w=2, extra=''): | |
| 83 | + return f'<polyline class="{cls}" points="{" ".join(f"{f1(x)},{f1(y)}" for x, y in pts)}" stroke-width="{w}"{extra}/>' | |
| 84 | + | |
| 85 | + | |
| 86 | +DASH = ' stroke-dasharray="7 6"' # pass as `extra` for a dashed stroke | |
| 87 | + | |
| 88 | + | |
| 89 | +def polypath(pts, cls='ink2-s', w=2, closed=False, extra=''): | |
| 90 | + """Many points as one relative path: the same line as polyline, a fraction of the bytes.""" | |
| 91 | + (x0, y0), d, px, py = pts[0], [], pts[0][0], pts[0][1] | |
| 92 | + for x, y in pts[1:]: | |
| 93 | + d.append(f'{f1(x - px)} {f1(y - py)}'); px, py = x, y | |
| 94 | + return path(f'M{f1(x0)} {f1(y0)}l' + ' '.join(d) + ('z' if closed else ''), cls, w, extra) | |
| 95 | + | |
| 96 | + | |
| 97 | +def arrow(x1, y1, x2, y2, cls='ink2-s', w=2, head=10): | |
| 98 | + """A line ending in an open arrowhead at (x2, y2).""" | |
| 99 | + a = math.atan2(y2 - y1, x2 - x1) | |
| 100 | + tips = [(x2 - head * math.cos(a - s), y2 - head * math.sin(a - s)) for s in (0.45, -0.45)] | |
| 101 | + return line(x1, y1, x2, y2, cls, w) + polyline([tips[0], (x2, y2), tips[1]], cls, w) | |
| 102 | + | |
| 103 | + | |
| 104 | +def text(x, y, s, cls='lbl', anchor='middle'): | |
| 105 | + s = s.replace('&', '&').replace('<', '<').replace('>', '>') | |
| 106 | + return f'<text class="{cls}" x="{f1(x)}" y="{f1(y)}" text-anchor="{anchor}">{s}</text>' | |
| 107 | + | |
| 108 | + | |
| 109 | +def svg(field, body, label=None, title=''): | |
| 110 | + """The whole figure. `label` is the one line naming what is drawn, at the bottom; leave room for it (y < 262).""" | |
| 111 | + if field not in FIELD: | |
| 112 | + raise ValueError(f'unknown field {field!r}') | |
| 113 | + if label and len(label) > 50: | |
| 114 | + raise ValueError(f'label over 50 characters (more does not fit at card size): {label!r}') | |
| 115 | + t = f'<title>{title or label or ""}</title>' | |
| 116 | + tail = text(W / 2, H - 16, label) if label else '' | |
| 117 | + return f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {W} {H}" role="img">{t}{style(field)}{body}{tail}</svg>\n' | |
| 118 | + | |
| 119 | + | |
| 120 | +def write(figure_py, field, body, label=None, title=''): | |
| 121 | + """Writes cover.svg next to the figure.py that calls it.""" | |
| 122 | + out = Path(figure_py).resolve().parent / 'cover.svg' | |
| 123 | + out.write_text(svg(field, body, label, title)) | |
| 124 | + return out | |
+0 −0 poster.webp added View file
+6 −0 posters.json added View file
| @@ -0,0 +1,6 @@ | ||
| 1 | +{ | |
| 2 | + "poster.webp": { | |
| 3 | + "style": "poster", | |
| 4 | + "idea": "A handcrafted coefficient-sorting table shows sparse selection, with parallel brass solver tracks reaching the same model at different speeds." | |
| 5 | + } | |
| 6 | +} | |