File size: 9,288 Bytes
9126e0d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
"""Sparse journal figures: vector mathematics and measured evidence only."""
from pathlib import Path
import json
import figures_r2 as old
ROOT=Path(__file__).resolve().parents[1];F=ROOT/'figures'
def write(name,body):old.write(name,body)
def framework():
    write('Fig1_framework',r'''
\begin{tikzpicture}[x=1mm,y=1mm]
\path[use as bounding box] (0,-3) rectangle (164,57);
\node[anchor=west,font=\bfseries\small] at (0,54) {(a) Scope and projection};
\node[anchor=west,font=\bfseries\small] at (99,54) {(b) Spatial eligibility};
\node (q) at (4,34) {$I,q$};
\node[draw,rectangle,minimum width=14mm,minimum height=10mm] (f) at (28,34) {$f_{\theta}$};
\node (p) at (54,34) {$P_q,P_t,P_a$};
\node[draw,rectangle,minimum width=15mm,minimum height=10mm] (proj) at (80,34) {$\Pi_r$};
\draw[link] (q)--(f);
\draw[link] (f)--(p);
\draw[link] (p)--(proj);
\node[font=\small] at (28,43) {$\theta$ fixed};
\node (guard) at (28,16) {$S(q)\in\{0,1\}$};
\draw[link] (q.south)|-(guard.west);
\draw[link] (guard.north)--node[right,font=\scriptsize] {$S=1$}(f.south);
\draw[link,dashed] (guard.east)--(80,16)--(proj.south);
\node[font=\scriptsize,fill=white,inner sep=1pt] at (57,16) {fallback $M_q$};
\node[anchor=west,font=\scriptsize] at (0,0) {$\widehat M=\Pi_r(P_q,P_t,P_a)$ if $S(q)\land V$; otherwise $M_q$.};
\draw[rule] (95,3)--(95,49);
\draw[->,line width=.5pt] (103,8)--(162,8) node[below] {$x$};
\draw[->,line width=.5pt] (103,8)--(103,46) node[left] {$y$};
\fill[black!7] (131,9) rectangle (159,44);
\draw[dashed,muted] (131,8)--(131,46);
\node[anchor=south,font=\scriptsize] at (131,46) {$x_A+\epsilon_g$};
\draw[fill=black!15,line width=.6pt] (117,25) circle (3.8);
\node at (117,25) {$A$};
\draw[line width=.6pt] (111,37) ellipse (4 and 2.4);
\node[above] at (111,39) {$C_1$};
\draw[teal,fill=teal!14,line width=.8pt] (141,32) ellipse (4.5 and 3);
\draw[teal,fill=teal!14,line width=.8pt] (150,18) ellipse (4 and 2.8);
\node[above] at (141,35) {$C_2$};
\node[above] at (150,21) {$C_3$};
\draw[link] (121,25)--(136,31);
\node[anchor=north,font=\small] at (132,3) {$\mathcal E_{\rightarrow}=\{C_2,C_3\}$};
\end{tikzpicture}''')
def coverage(data):
    lines=[r'\begin{tikzpicture}[x=1mm,y=1mm]']
    for j,(model,title) in enumerate([('clipseg','CLIPSeg'),('groundedsam','Grounded SAM')]):
        x=j*82
        lines.append(r'\node[anchor=west,font=\bfseries\small] at (%s,50) {%s};'%(x,title))
        lines.append(r'\begin{axis}[journal,at={(%s mm,0mm)},anchor=south west,width=64mm,height=40mm,xmin=0,xmax=6,ymin=-.02,ymax=.2,xlabel={Accepted expressions (\%%)},ylabel={$\Delta$gIoU (pp)},axis lines=left,xtick={0,1,2,3,4,5,6}]'%(x+10))
        coords=' '.join('(%.5f,%.6f)'%(z['coverage']*100,z['delta']*100) for z in data[model]['coverage'])
        lines.append(r'\addplot[teal,line width=.8pt,mark=*] coordinates {'+coords+'};')
        for z,label in zip(data[model]['coverage'],['R$_s$','R','S','L']):
            v=z['delta']*100;lo,hi=[v*100 for v in z['ci']];xx=z['coverage']*100
            lines.append(r'\addplot[teal,error bars/.cd,y dir=both,y explicit] coordinates {(%.6f,%.6f) += (0,%.6f) -= (0,%.6f)};'%(xx,v,hi-v,v-lo))
            anchor='north east' if label.startswith('R$_s') else 'south west'
            shift=-.004 if label.startswith('R$_s') else .003
            lines.append(r'\node[anchor=%s,font=\scriptsize] at (axis cs:%.5f,%.6f) {%s};'%(anchor,xx+.02,v+shift,label))
        lines.append(r'\end{axis}')
    lines.append(r'\end{tikzpicture}');write('Fig6_natural_effects','\n'.join(lines))
def sensitivity(data):
    names=['primary','anchor_margin_0.02','anchor_margin_0.1','target_margin_0.02','target_margin_0.1','geometry_0.01','geometry_0.05','size_factor_0.5','size_factor_2.0','threshold_offset_-0.05','threshold_offset_0.05']
    labels=[r'Primary',r'$\delta_a=.02$',r'$\delta_a=.10$',r'$\delta_t=.02$',r'$\delta_t=.10$',r'$\epsilon_g=.01$',r'$\epsilon_g=.05$',r'$a_{\min}\times.5$',r'$a_{\min}\times2$',r'$t_0-.05$',r'$t_0+.05$']
    lines=[r'\begin{tikzpicture}[x=1mm,y=1mm]']
    for j,(model,title) in enumerate([('clipseg','CLIPSeg'),('groundedsam','Grounded SAM')]):
        dx=j*82;lines.append(r'\node[anchor=west,font=\bfseries\small] at (%s,76) {%s};'%(dx,title))
        lines.append(r'\begin{axis}[journal,at={(%s mm,0mm)},anchor=south west,width=50mm,height=65mm,xmin=0,xmax=.18,ymin=-.7,ymax=10.7,ytick=\empty,xlabel={$\Delta$gIoU (pp)},axis lines=left,xtick={0,.05,.1,.15}]'%(dx+26))
        table={r['config']:r for r in data[model]['sensitivity']}
        for i,(key,label) in enumerate(zip(names,labels)):
            z=table[key];y=10-i;v=z['delta']*100;lo,hi=[k*100 for k in z['ci']];col='black' if i==0 else 'teal'
            lines.append(r'\node[anchor=east,font=\scriptsize] at (axis cs:-.005,%s) {%s};'%(y,label))
            lines.append(r'\addplot[%s,mark=*,mark size=1.5pt,error bars/.cd,x dir=both,x explicit] coordinates {(%.6f,%s) += (%.6f,0) -= (%.6f,0)};'%(col,v,y,hi-v,v-lo))
        lines.append(r'\end{axis}')
    lines.append(r'\end{tikzpicture}');write('Fig9_threshold_robustness','\n'.join(lines))
def harm(data):
    keys=['harmed','plural_union','already_correct','correct_to_incorrect','boundary_sensitive','component_filter_sensitive']
    labels=['Any IoU loss','Plural union','Initially correct','Crossed below .5','Geometry sensitive','Size-filter sensitive']
    lines=[r'\begin{tikzpicture}[x=1mm,y=1mm]']
    for j,(model,title) in enumerate([('clipseg','CLIPSeg'),('groundedsam','Grounded SAM')]):
        dx=j*82;lines.append(r'\node[anchor=west,font=\bfseries\small] at (%s,61) {%s};'%(dx,title))
        lines.append(r'\begin{axis}[journal,at={(%s mm,0mm)},anchor=south west,width=42mm,height=51mm,xmin=0,xmax=600,ymin=-.6,ymax=5.7,ytick=\empty,xlabel={Expressions},axis lines=left,xtick={0,200,400,600}]'%(dx+38))
        for i,(key,label) in enumerate(zip(keys,labels)):
            y=5-i;n=data[model]['harm']['reason_counts']['plural'] if key=='plural_union' else data[model]['harm'][key]
            lines.append(r'\node[anchor=east,font=\scriptsize] at (axis cs:-12,%s) {%s};'%(y,label))
            lines.append(r'\addplot[black!60,line width=.5pt] coordinates {(0,%s)(%s,%s)};'%(y,n,y))
            lines.append(r'\addplot[black,only marks,mark=*,mark size=2pt] coordinates {(%s,%s)};'%(n,y))
            lines.append(r'\node[anchor=south west,font=\scriptsize] at (axis cs:%s,%s) {%s};'%(n,y,n))
        lines.append(r'\end{axis}')
    lines.append(r'\end{tikzpicture}');write('Fig10_harm_signatures','\n'.join(lines))
def rich_primary():
    lines=[r'\begin{tikzpicture}[x=1mm,y=1mm]']
    for j,(title,rows) in enumerate([('Flat',[('Grounded SAM',.0833,8.0),('CLIPSeg',4.5208,17.4792)]),('Rich',[('Grounded SAM',.5,17.3333),('CLIPSeg',3.2708,9.0)])]):
        dx=j*82;lines.append(r'\node[anchor=west,font=\bfseries\small] at (%s,44) {%s};'%(dx,title))
        lines.append(r'\begin{axis}[journal,at={(%s mm,0mm)},anchor=south west,width=65mm,height=32mm,xmin=0,xmax=21,ymin=-.5,ymax=1.6,ytick=\empty,xlabel={PC$_{.5}$ (\%%)},axis lines=left,xtick={0,5,10,15,20}]'%(dx+10))
        for y,(model,frozen,repaired) in enumerate(rows):
            lines.append(r'\addplot[black!55,line width=.6pt] coordinates {(%.4f,%s)(%.4f,%s)};'%(frozen,y,repaired,y))
            lines.append(r'\addplot[black,only marks,mark=o,mark size=2.3pt] coordinates {(%.4f,%s)};'%(frozen,y))
            lines.append(r'\addplot[black,only marks,mark=*,mark size=2.3pt] coordinates {(%.4f,%s)};'%(repaired,y))
            lines.append(r'\node[anchor=south east,font=\scriptsize] at (axis cs:20.8,%s) {%s};'%(y+.12,model))
        lines.append(r'\end{axis}')
    lines.append(r'\end{tikzpicture}');write('Fig8_rich_performance','\n'.join(lines))
def monochrome_legend():
    p=F/'Fig5_thresholds.tex';s=p.read_text()
    start=s.index(r'\node[anchor=west,font=\sffamily\fontsize{7.8}{9}\selectfont] at (0,-17)')
    stop=s.index(';',start)+1
    parts=[]
    for x,label,style in [(0,'Frozen','dashed'),(32,'Global','densely dotted'),(64,'Anchor PC','solid'),(100,'CACP','dashdotted'),(130,'Anchor Pr','dashed')]:
        parts.append(r'\draw[black,%s,line width=.75pt] (%s,-17)--(%s,-17);\node[anchor=west,font=\scriptsize] at (%s,-17) {%s};'%(style,x,x+5,x+6,label))
        if label=='Anchor Pr':parts.append(r'\draw[fill=white] (132,-17.6) rectangle (133.2,-16.4);')
    s=s[:start]+'\n'.join(parts)+s[stop:]
    s=s.replace('ymax=65','ymax=80').replace('teal,dashed,opacity=.5,line width=.8pt','teal,dashed,line width=.7pt,mark=square,mark size=1.5pt,mark options={fill=white}')
    p.write_text(s)
def main():
    (F/'assets').mkdir(parents=True,exist_ok=True)
    old.atlas();old.paired_render();old.multiplicity();old.thresholds();old.absence_tradeoff();old.rich_performance()
    framework();rich_primary();monochrome_legend()
    datafile=ROOT/'results/r3/review_results.json'
    if datafile.exists():
        data=json.loads(datafile.read_text());coverage(data);sensitivity(data);harm(data)
    for p in F.glob('Fig*.tex'):
        s=p.read_text().replace(r'\sffamily',r'\rmfamily')
        s=s.replace(r'\node[anchor=west,font=\rmfamily\bfseries\fontsize{10}{12}\selectfont] at (0,5) {A richer test of the same five command regimes};','')
        p.write_text(s)
if __name__=='__main__':main()