@knowvah/dot-engine 2.10.3 → 2.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (342) hide show
  1. package/dist/common/agerr.d.ts +12 -0
  2. package/dist/common/agerr.d.ts.map +1 -1
  3. package/dist/gvc/context.d.ts.map +1 -1
  4. package/dist/gvc/emit-xdot.d.ts.map +1 -1
  5. package/dist/gvc/layout-reset.d.ts +38 -1
  6. package/dist/gvc/layout-reset.d.ts.map +1 -1
  7. package/dist/index.d.ts +2 -0
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +1260 -387
  10. package/dist/index.js.map +4 -4
  11. package/dist/layout/circo/circular.d.ts.map +1 -1
  12. package/dist/layout/dot/edge-route-chain.d.ts.map +1 -1
  13. package/dist/layout/dot/edge-route-helpers.d.ts +6 -1
  14. package/dist/layout/dot/edge-route-helpers.d.ts.map +1 -1
  15. package/dist/layout/dot/edge-route-rank.d.ts +4 -1
  16. package/dist/layout/dot/edge-route-rank.d.ts.map +1 -1
  17. package/dist/layout/dot/index.d.ts.map +1 -1
  18. package/dist/layout/dot/init.d.ts.map +1 -1
  19. package/dist/layout/fdp/cluster-edges.d.ts +11 -0
  20. package/dist/layout/fdp/cluster-edges.d.ts.map +1 -1
  21. package/dist/layout/neato/closest.d.ts +20 -0
  22. package/dist/layout/neato/closest.d.ts.map +1 -0
  23. package/dist/layout/neato/constrained-majorization.d.ts +13 -0
  24. package/dist/layout/neato/constrained-majorization.d.ts.map +1 -1
  25. package/dist/layout/neato/embed-graph.d.ts +20 -0
  26. package/dist/layout/neato/embed-graph.d.ts.map +1 -0
  27. package/dist/layout/neato/fdp-adjust.d.ts.map +1 -1
  28. package/dist/layout/neato/index.d.ts.map +1 -1
  29. package/dist/layout/neato/init-dim.d.ts +54 -0
  30. package/dist/layout/neato/init-dim.d.ts.map +1 -0
  31. package/dist/layout/neato/init.d.ts +1 -11
  32. package/dist/layout/neato/init.d.ts.map +1 -1
  33. package/dist/layout/neato/kk.d.ts +4 -2
  34. package/dist/layout/neato/kk.d.ts.map +1 -1
  35. package/dist/layout/neato/matrix-ops-dense.d.ts +34 -0
  36. package/dist/layout/neato/matrix-ops-dense.d.ts.map +1 -0
  37. package/dist/layout/neato/pca.d.ts +14 -0
  38. package/dist/layout/neato/pca.d.ts.map +1 -0
  39. package/dist/layout/neato/sgd.d.ts +2 -3
  40. package/dist/layout/neato/sgd.d.ts.map +1 -1
  41. package/dist/layout/neato/start.d.ts +5 -5
  42. package/dist/layout/neato/start.d.ts.map +1 -1
  43. package/dist/layout/neato/stress-kernel.d.ts +10 -2
  44. package/dist/layout/neato/stress-kernel.d.ts.map +1 -1
  45. package/dist/layout/neato/stress-subspace.d.ts +39 -0
  46. package/dist/layout/neato/stress-subspace.d.ts.map +1 -0
  47. package/dist/layout/neato/vpsc-adjust.d.ts.map +1 -1
  48. package/dist/layout/pack/ccomps.d.ts +4 -2
  49. package/dist/layout/pack/ccomps.d.ts.map +1 -1
  50. package/dist/layout/sfdp/index.d.ts.map +1 -1
  51. package/dist/layout/sfdp/init.d.ts +6 -7
  52. package/dist/layout/sfdp/init.d.ts.map +1 -1
  53. package/dist/layout/twopi/circle.d.ts.map +1 -1
  54. package/dist/layout/twopi/index.d.ts.map +1 -1
  55. package/dist/render/dot/attrs.d.ts +7 -0
  56. package/dist/render/dot/attrs.d.ts.map +1 -1
  57. package/dist/render.js +1637 -770
  58. package/dist/render.js.map +4 -4
  59. package/package.json +4 -4
  60. package/src/common/agerr.ts +49 -1
  61. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.1 +20 -0
  62. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.2 +20 -0
  63. package/src/gvc/__fixtures__/rerender/abom-shift-pack.dot.plain.nofree.3 +20 -0
  64. package/src/gvc/__fixtures__/rerender/abom-shift-pack.gv +1 -0
  65. package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.1 +22 -0
  66. package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.2 +22 -0
  67. package/src/gvc/__fixtures__/rerender/abom-shift-parity.dot.plain.nofree.3 +22 -0
  68. package/src/gvc/__fixtures__/rerender/abom-shift-parity.gv +1 -0
  69. package/src/gvc/__fixtures__/rerender/abom-shift.dot.plain.nofree.1 +13 -0
  70. package/src/gvc/__fixtures__/rerender/abom-shift.dot.plain.nofree.2 +13 -0
  71. package/src/gvc/__fixtures__/rerender/abom-shift.dot.plain.nofree.3 +13 -0
  72. package/src/gvc/__fixtures__/rerender/abom-shift.gv +1 -0
  73. package/src/gvc/__fixtures__/rerender/cluster-edge-splines.fdp.plain.1 +10 -0
  74. package/src/gvc/__fixtures__/rerender/cluster-edge-splines.fdp.plain.2 +11 -0
  75. package/src/gvc/__fixtures__/rerender/cluster-edge-splines.gv +9 -0
  76. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.dot.1 +40 -0
  77. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.dot.2 +40 -0
  78. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.plain.noaddr.1 +15 -0
  79. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.plain.noaddr.2 +17 -0
  80. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-dot-plain.1 +40 -0
  81. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-dot-plain.2 +15 -0
  82. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-dot-svg.1 +40 -0
  83. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-dot-svg.2 +99 -0
  84. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-json-json.1 +489 -0
  85. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-json-json.2 +503 -0
  86. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-nofree-dot-svg.1 +40 -0
  87. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.seq-nofree-dot-svg.2 +109 -0
  88. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.xdot.1 +69 -0
  89. package/src/gvc/__fixtures__/rerender/cluster-edges.fdp.xdot.2 +70 -0
  90. package/src/gvc/__fixtures__/rerender/cluster-edges.gv +15 -0
  91. package/src/gvc/__fixtures__/rerender/fdp-1581.fdp.dot.1 +104 -0
  92. package/src/gvc/__fixtures__/rerender/fdp-1581.fdp.dot.2 +104 -0
  93. package/src/gvc/__fixtures__/rerender/fdp-1581.gv +26 -0
  94. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.1 +34 -0
  95. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.2 +34 -0
  96. package/src/gvc/__fixtures__/rerender/flat-rev-stale.dot.plain.nofree.3 +34 -0
  97. package/src/gvc/__fixtures__/rerender/flat-rev-stale.gv +33 -0
  98. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.1 +181 -0
  99. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.2 +218 -0
  100. package/src/gvc/__fixtures__/rerender/multi-edge.dot.svg.nofree.3 +255 -0
  101. package/src/gvc/__fixtures__/rerender/regen.sh +25 -0
  102. package/src/gvc/context.ts +7 -2
  103. package/src/gvc/emit-xdot.ts +37 -7
  104. package/src/gvc/layout-reset.ts +59 -1
  105. package/src/index.ts +4 -0
  106. package/src/layout/circo/circular.ts +3 -1
  107. package/src/layout/dot/edge-route-chain.ts +79 -7
  108. package/src/layout/dot/edge-route-helpers.ts +8 -2
  109. package/src/layout/dot/edge-route-rank.ts +20 -2
  110. package/src/layout/dot/index.ts +17 -2
  111. package/src/layout/dot/init.ts +9 -17
  112. package/src/layout/dot/splines-flat.ts +12 -12
  113. package/src/layout/dot/splines.ts +2 -2
  114. package/src/layout/fdp/cluster-edges.ts +0 -0
  115. package/src/layout/fdp/index.ts +2 -2
  116. package/src/layout/neato/__fixtures__/dim/circuit-dim3.dot +33 -0
  117. package/src/layout/neato/__fixtures__/dim/circuit-dim3.gv +12 -0
  118. package/src/layout/neato/__fixtures__/dim/circuit-dim3.stderr +0 -0
  119. package/src/layout/neato/__fixtures__/dim/circuit-dim3.xdot +54 -0
  120. package/src/layout/neato/__fixtures__/dim/dim11-dimen11.dot +32 -0
  121. package/src/layout/neato/__fixtures__/dim/dim11-dimen11.gv +11 -0
  122. package/src/layout/neato/__fixtures__/dim/dim11-dimen11.stderr +0 -0
  123. package/src/layout/neato/__fixtures__/dim/dim11-dimen11.xdot +53 -0
  124. package/src/layout/neato/__fixtures__/dim/dim3-dimen3.dot +32 -0
  125. package/src/layout/neato/__fixtures__/dim/dim3-dimen3.gv +11 -0
  126. package/src/layout/neato/__fixtures__/dim/dim3-dimen3.stderr +0 -0
  127. package/src/layout/neato/__fixtures__/dim/dim3-dimen3.xdot +53 -0
  128. package/src/layout/neato/__fixtures__/dim/dim3.dot +31 -0
  129. package/src/layout/neato/__fixtures__/dim/dim3.gv +10 -0
  130. package/src/layout/neato/__fixtures__/dim/dim3.stderr +0 -0
  131. package/src/layout/neato/__fixtures__/dim/dim3.xdot +52 -0
  132. package/src/layout/neato/__fixtures__/dim/dim4-dimen4.dot +32 -0
  133. package/src/layout/neato/__fixtures__/dim/dim4-dimen4.gv +11 -0
  134. package/src/layout/neato/__fixtures__/dim/dim4-dimen4.stderr +0 -0
  135. package/src/layout/neato/__fixtures__/dim/dim4-dimen4.xdot +53 -0
  136. package/src/layout/neato/__fixtures__/dim/dimen3.dot +31 -0
  137. package/src/layout/neato/__fixtures__/dim/dimen3.gv +10 -0
  138. package/src/layout/neato/__fixtures__/dim/dimen3.stderr +0 -0
  139. package/src/layout/neato/__fixtures__/dim/dimen3.xdot +52 -0
  140. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.dot +267 -0
  141. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.gv +84 -0
  142. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.stderr +0 -0
  143. package/src/layout/neato/__fixtures__/dim/hier-big-dim3.xdot +468 -0
  144. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.dot +267 -0
  145. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.gv +84 -0
  146. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.stderr +0 -0
  147. package/src/layout/neato/__fixtures__/dim/hier-big-dim4.xdot +468 -0
  148. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.dot +268 -0
  149. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.gv +85 -0
  150. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.stderr +0 -0
  151. package/src/layout/neato/__fixtures__/dim/hier-big-subset-dim3.xdot +469 -0
  152. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.dot +484 -0
  153. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.gv +151 -0
  154. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.stderr +0 -0
  155. package/src/layout/neato/__fixtures__/dim/hier-big110-dim3.xdot +852 -0
  156. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.dot +34 -0
  157. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.gv +13 -0
  158. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.stderr +0 -0
  159. package/src/layout/neato/__fixtures__/dim/hier-circuit-dim3.xdot +55 -0
  160. package/src/layout/neato/__fixtures__/dim/hier-dim3.dot +33 -0
  161. package/src/layout/neato/__fixtures__/dim/hier-dim3.gv +12 -0
  162. package/src/layout/neato/__fixtures__/dim/hier-dim3.stderr +0 -0
  163. package/src/layout/neato/__fixtures__/dim/hier-dim3.xdot +54 -0
  164. package/src/layout/neato/__fixtures__/dim/hier-dim4.dot +33 -0
  165. package/src/layout/neato/__fixtures__/dim/hier-dim4.gv +12 -0
  166. package/src/layout/neato/__fixtures__/dim/hier-dim4.stderr +0 -0
  167. package/src/layout/neato/__fixtures__/dim/hier-dim4.xdot +54 -0
  168. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim2.dot +32 -0
  169. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim2.gv +11 -0
  170. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim2.stderr +0 -0
  171. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim2.xdot +53 -0
  172. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim3.dot +34 -0
  173. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim3.gv +13 -0
  174. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim3.stderr +0 -0
  175. package/src/layout/neato/__fixtures__/dim/hier-dirnone-dim3.xdot +55 -0
  176. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.dot +37 -0
  177. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.gv +12 -0
  178. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.stderr +0 -0
  179. package/src/layout/neato/__fixtures__/dim/hier-len-dim3.xdot +58 -0
  180. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.dot +141 -0
  181. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.gv +48 -0
  182. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.stderr +1 -0
  183. package/src/layout/neato/__fixtures__/dim/hier-noedge-big.xdot +233 -0
  184. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim2.dot +21 -0
  185. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim2.gv +8 -0
  186. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim2.stderr +1 -0
  187. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim2.xdot +33 -0
  188. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim3.dot +23 -0
  189. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim3.gv +10 -0
  190. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim3.stderr +1 -0
  191. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim3.xdot +35 -0
  192. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim4.dot +23 -0
  193. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim4.gv +10 -0
  194. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim4.stderr +1 -0
  195. package/src/layout/neato/__fixtures__/dim/hier-noedge-dim4.xdot +35 -0
  196. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim2.dot +26 -0
  197. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim2.gv +7 -0
  198. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim2.stderr +0 -0
  199. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim2.xdot +44 -0
  200. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim3.dot +28 -0
  201. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim3.gv +9 -0
  202. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim3.stderr +0 -0
  203. package/src/layout/neato/__fixtures__/dim/hier-nohier-dim3.xdot +46 -0
  204. package/src/layout/neato/__fixtures__/dim/hier-pack-dim3.dot +48 -0
  205. package/src/layout/neato/__fixtures__/dim/hier-pack-dim3.gv +15 -0
  206. package/src/layout/neato/__fixtures__/dim/hier-pack-dim3.stderr +0 -0
  207. package/src/layout/neato/__fixtures__/dim/hier-pack-dim3.xdot +79 -0
  208. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.dot +56 -0
  209. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.gv +17 -0
  210. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.stderr +0 -0
  211. package/src/layout/neato/__fixtures__/dim/hier-ring-dim3.xdot +94 -0
  212. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.dot +47 -0
  213. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.gv +14 -0
  214. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.stderr +0 -0
  215. package/src/layout/neato/__fixtures__/dim/hier-star-dim3.xdot +78 -0
  216. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim3.dot +34 -0
  217. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim3.gv +13 -0
  218. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim3.stderr +0 -0
  219. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim3.xdot +55 -0
  220. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.dot +34 -0
  221. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.gv +13 -0
  222. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.stderr +0 -0
  223. package/src/layout/neato/__fixtures__/dim/hier-stresswt1-dim4.xdot +55 -0
  224. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.dot +34 -0
  225. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.gv +13 -0
  226. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.stderr +0 -0
  227. package/src/layout/neato/__fixtures__/dim/hier-subset-dim3.xdot +55 -0
  228. package/src/layout/neato/__fixtures__/dim/hier-two-dim3.dot +15 -0
  229. package/src/layout/neato/__fixtures__/dim/hier-two-dim3.gv +6 -0
  230. package/src/layout/neato/__fixtures__/dim/hier-two-dim3.stderr +0 -0
  231. package/src/layout/neato/__fixtures__/dim/hier-two-dim3.xdot +22 -0
  232. package/src/layout/neato/__fixtures__/dim/ipsep-dim3.dot +33 -0
  233. package/src/layout/neato/__fixtures__/dim/ipsep-dim3.gv +12 -0
  234. package/src/layout/neato/__fixtures__/dim/ipsep-dim3.stderr +0 -0
  235. package/src/layout/neato/__fixtures__/dim/ipsep-dim3.xdot +54 -0
  236. package/src/layout/neato/__fixtures__/dim/kk-dim3.dot +33 -0
  237. package/src/layout/neato/__fixtures__/dim/kk-dim3.gv +12 -0
  238. package/src/layout/neato/__fixtures__/dim/kk-dim3.stderr +0 -0
  239. package/src/layout/neato/__fixtures__/dim/kk-dim3.xdot +54 -0
  240. package/src/layout/neato/__fixtures__/dim/kk-dim4-dimen4.dot +33 -0
  241. package/src/layout/neato/__fixtures__/dim/kk-dim4-dimen4.gv +12 -0
  242. package/src/layout/neato/__fixtures__/dim/kk-dim4-dimen4.stderr +0 -0
  243. package/src/layout/neato/__fixtures__/dim/kk-dim4-dimen4.xdot +54 -0
  244. package/src/layout/neato/__fixtures__/dim/kk-pins-dim3.dot +39 -0
  245. package/src/layout/neato/__fixtures__/dim/kk-pins-dim3.gv +15 -0
  246. package/src/layout/neato/__fixtures__/dim/kk-pins-dim3.stderr +0 -0
  247. package/src/layout/neato/__fixtures__/dim/kk-pins-dim3.xdot +60 -0
  248. package/src/layout/neato/__fixtures__/dim/overlap-false-dim3.dot +33 -0
  249. package/src/layout/neato/__fixtures__/dim/overlap-false-dim3.gv +12 -0
  250. package/src/layout/neato/__fixtures__/dim/overlap-false-dim3.stderr +0 -0
  251. package/src/layout/neato/__fixtures__/dim/overlap-false-dim3.xdot +54 -0
  252. package/src/layout/neato/__fixtures__/dim/overlap-scale-dim3.dot +33 -0
  253. package/src/layout/neato/__fixtures__/dim/overlap-scale-dim3.gv +12 -0
  254. package/src/layout/neato/__fixtures__/dim/overlap-scale-dim3.stderr +0 -0
  255. package/src/layout/neato/__fixtures__/dim/overlap-scale-dim3.xdot +54 -0
  256. package/src/layout/neato/__fixtures__/dim/overlap-vpsc-dim3.dot +33 -0
  257. package/src/layout/neato/__fixtures__/dim/overlap-vpsc-dim3.gv +12 -0
  258. package/src/layout/neato/__fixtures__/dim/overlap-vpsc-dim3.stderr +0 -0
  259. package/src/layout/neato/__fixtures__/dim/overlap-vpsc-dim3.xdot +54 -0
  260. package/src/layout/neato/__fixtures__/dim/pack-dim3.dot +47 -0
  261. package/src/layout/neato/__fixtures__/dim/pack-dim3.gv +14 -0
  262. package/src/layout/neato/__fixtures__/dim/pack-dim3.stderr +0 -0
  263. package/src/layout/neato/__fixtures__/dim/pack-dim3.xdot +78 -0
  264. package/src/layout/neato/__fixtures__/dim/pins-dim3.dot +38 -0
  265. package/src/layout/neato/__fixtures__/dim/pins-dim3.gv +14 -0
  266. package/src/layout/neato/__fixtures__/dim/pins-dim3.stderr +0 -0
  267. package/src/layout/neato/__fixtures__/dim/pins-dim3.xdot +59 -0
  268. package/src/layout/neato/__fixtures__/dim/regen.sh +24 -0
  269. package/src/layout/neato/__fixtures__/dim/regular-dim3.dot +33 -0
  270. package/src/layout/neato/__fixtures__/dim/regular-dim3.gv +12 -0
  271. package/src/layout/neato/__fixtures__/dim/regular-dim3.stderr +0 -0
  272. package/src/layout/neato/__fixtures__/dim/regular-dim3.xdot +54 -0
  273. package/src/layout/neato/__fixtures__/dim/sgd-dim3.dot +33 -0
  274. package/src/layout/neato/__fixtures__/dim/sgd-dim3.gv +12 -0
  275. package/src/layout/neato/__fixtures__/dim/sgd-dim3.stderr +0 -0
  276. package/src/layout/neato/__fixtures__/dim/sgd-dim3.xdot +54 -0
  277. package/src/layout/neato/__fixtures__/dim/smart-units.json +16 -0
  278. package/src/layout/neato/__fixtures__/dim/subset-dim3.dot +33 -0
  279. package/src/layout/neato/__fixtures__/dim/subset-dim3.gv +12 -0
  280. package/src/layout/neato/__fixtures__/dim/subset-dim3.stderr +0 -0
  281. package/src/layout/neato/__fixtures__/dim/subset-dim3.xdot +54 -0
  282. package/src/layout/neato/closest.ts +206 -0
  283. package/src/layout/neato/constrained-majorization.ts +4 -23
  284. package/src/layout/neato/embed-graph.ts +81 -0
  285. package/src/layout/neato/fdp-adjust.ts +22 -8
  286. package/src/layout/neato/index.ts +26 -17
  287. package/src/layout/neato/init-dim.ts +165 -0
  288. package/src/layout/neato/init.ts +9 -35
  289. package/src/layout/neato/kk.ts +47 -41
  290. package/src/layout/neato/matrix-ops-dense.ts +232 -0
  291. package/src/layout/neato/pca.ts +60 -0
  292. package/src/layout/neato/sgd.ts +14 -13
  293. package/src/layout/neato/start.ts +8 -5
  294. package/src/layout/neato/stress-kernel.ts +65 -5
  295. package/src/layout/neato/stress-subspace.ts +371 -0
  296. package/src/layout/neato/vpsc-adjust.ts +3 -1
  297. package/src/layout/pack/__fixtures__/cc-reuse/circo.dot +23 -0
  298. package/src/layout/pack/__fixtures__/cc-reuse/circo.gv +1 -0
  299. package/src/layout/pack/__fixtures__/cc-reuse/circo.stderr +0 -0
  300. package/src/layout/pack/__fixtures__/cc-reuse/circo.xdot +38 -0
  301. package/src/layout/pack/__fixtures__/cc-reuse/neato.dot +23 -0
  302. package/src/layout/pack/__fixtures__/cc-reuse/neato.gv +1 -0
  303. package/src/layout/pack/__fixtures__/cc-reuse/neato.stderr +0 -0
  304. package/src/layout/pack/__fixtures__/cc-reuse/neato.xdot +38 -0
  305. package/src/layout/pack/__fixtures__/cc-reuse/osage.dot +23 -0
  306. package/src/layout/pack/__fixtures__/cc-reuse/osage.gv +1 -0
  307. package/src/layout/pack/__fixtures__/cc-reuse/osage.stderr +0 -0
  308. package/src/layout/pack/__fixtures__/cc-reuse/osage.xdot +38 -0
  309. package/src/layout/pack/__fixtures__/cc-reuse/regen.sh +24 -0
  310. package/src/layout/pack/__fixtures__/cc-reuse/sfdp.dot +21 -0
  311. package/src/layout/pack/__fixtures__/cc-reuse/sfdp.gv +1 -0
  312. package/src/layout/pack/__fixtures__/cc-reuse/sfdp.stderr +0 -0
  313. package/src/layout/pack/__fixtures__/cc-reuse/sfdp.xdot +36 -0
  314. package/src/layout/pack/__fixtures__/cc-reuse/twopi.dot +21 -0
  315. package/src/layout/pack/__fixtures__/cc-reuse/twopi.gv +1 -0
  316. package/src/layout/pack/__fixtures__/cc-reuse/twopi.stderr +1 -0
  317. package/src/layout/pack/__fixtures__/cc-reuse/twopi.xdot +36 -0
  318. package/src/layout/pack/ccomps.ts +34 -6
  319. package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.dot +32 -0
  320. package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.gv +11 -0
  321. package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.stderr +0 -0
  322. package/src/layout/sfdp/__fixtures__/dim/dim3-dimen3.xdot +53 -0
  323. package/src/layout/sfdp/__fixtures__/dim/dim3.dot +31 -0
  324. package/src/layout/sfdp/__fixtures__/dim/dim3.gv +10 -0
  325. package/src/layout/sfdp/__fixtures__/dim/dim3.stderr +0 -0
  326. package/src/layout/sfdp/__fixtures__/dim/dim3.xdot +52 -0
  327. package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.dot +32 -0
  328. package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.gv +11 -0
  329. package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.stderr +0 -0
  330. package/src/layout/sfdp/__fixtures__/dim/dim4-dimen4.xdot +53 -0
  331. package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.dot +33 -0
  332. package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.gv +12 -0
  333. package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.stderr +0 -0
  334. package/src/layout/sfdp/__fixtures__/dim/overlap-prism-dim3.xdot +54 -0
  335. package/src/layout/sfdp/__fixtures__/dim/regen.sh +24 -0
  336. package/src/layout/sfdp/index.ts +15 -10
  337. package/src/layout/sfdp/init.ts +26 -11
  338. package/src/layout/twopi/circle.ts +5 -1
  339. package/src/layout/twopi/index.ts +3 -0
  340. package/src/render/dot/agwrite.ts +2 -2
  341. package/src/render/dot/attrs.ts +16 -0
  342. package/src/render/dot/write-back.ts +2 -2
@@ -8,14 +8,15 @@
8
8
  * where C uses double/long double (long double == double on AArch64
9
9
  * macOS, where the reference SVGs were generated).
10
10
  *
11
- * smart_init (sparse subspace estimation) is not ported — no `start`
12
- * attr in the suite, so checkStart always yields INIT_RANDOM.
11
+ * The smart initial layout (sparse subspace estimation) is stress-subspace.ts;
12
+ * mode=hier reaches it. The default solver's start=self stays loud (start.ts).
13
13
  *
14
14
  * @see lib/neatogen/stress.c:stress_majorization_kD_mkernel
15
15
  * @see lib/neatogen/conjgrad.c:conjugate_gradient_mkernel
16
16
  */
17
17
 
18
18
  import type { Node } from '../../model/node.js';
19
+ import { fma } from '../../common/fma.js';
19
20
  import { drand48 } from '../../common/random.js';
20
21
  import { bfs } from './bfs.js';
21
22
  import { dijkstra, type VtxData } from './dijkstra.js';
@@ -32,10 +33,18 @@ import {
32
33
  vectorsInnerProductF,
33
34
  } from './matrix-ops.js';
34
35
  import { fmaf } from './quad-prog-solve.js';
35
- import { OPT_EXP_FLAG, TOLERANCE_CG } from './stress.js';
36
+ import { OPT_EXP_FLAG, OPT_SMART_INIT, TOLERANCE_CG } from './stress.js';
37
+ import { sparseStressSubspaceMajorizationKD } from './stress-subspace.js';
36
38
 
37
39
  const fr = Math.fround;
38
40
 
41
+ /** At most 50 iterations within the subspace. @see lib/neatogen/stress.c:stress_majorization_kD_mkernel */
42
+ const SMART_SUBSPACE_ITERATIONS = 50;
43
+ /** `num_pivots_stress` @see lib/neatogen/stress.h */
44
+ const NUM_PIVOTS_STRESS = 40;
45
+ /** The scale of the small random noise on a smart start. @see lib/neatogen/stress.c:stress_majorization_kD_mkernel */
46
+ const SMART_NOISE = 1e-6;
47
+
39
48
  /**
40
49
  * Packed all-pairs shortest paths over unit weights (BFS hops).
41
50
  * @see lib/neatogen/stress.c:compute_apsp_packed
@@ -96,6 +105,7 @@ export function initLayout(
96
105
  if (hasPos(np)) {
97
106
  coords[0]![i] = np.info.pos?.[0] ?? 0;
98
107
  coords[1]![i] = np.info.pos?.[1] ?? 0;
108
+ for (let d = 2; d < dim; d++) coords[d]![i] = np.info.pos?.[d] ?? 0;
99
109
  if (isFixed(np)) pinned = true;
100
110
  } else {
101
111
  coords[0]![i] = drand48();
@@ -238,6 +248,13 @@ function solveAxis(st: KernelState, k: number, havePinned: boolean, nodes: Node[
238
248
  return 0;
239
249
  }
240
250
 
251
+ /** What the smart initial layout needs beyond the distances `Dij`. */
252
+ export interface SmartInit {
253
+ graph: VtxData[];
254
+ /** `model == MODEL_SUBSET`. */
255
+ reweightGraph: boolean;
256
+ }
257
+
241
258
  /** Options for stressMajorizationKDMkernel. */
242
259
  export interface StressOpts {
243
260
  dim: number;
@@ -246,6 +263,48 @@ export interface StressOpts {
246
263
  /** MODEL_* — only the resulting Dij matters here; pass it in. */
247
264
  maxi: number;
248
265
  epsilon: number;
266
+ /** Set by the callers whose C path reaches `opt_smart_init` (mode=hier). */
267
+ smart?: SmartInit;
268
+ }
269
+
270
+ /**
271
+ * Optimize quickly within a subspace to get an estimate, then scale each axis
272
+ * down for numerical stability and add small random noise. Returns -1 when the
273
+ * subspace optimization fails, else 0: a smart start pins nothing.
274
+ * @see lib/neatogen/stress.c:stress_majorization_kD_mkernel
275
+ */
276
+ function smartLayout(
277
+ smart: SmartInit, n: number, dCoords: Float64Array[], o: StressOpts,
278
+ ): number {
279
+ const { dim } = o;
280
+ const iterations = sparseStressSubspaceMajorizationKD(smart.graph, n, dCoords, {
281
+ dim, exp: o.opts & OPT_EXP_FLAG, reweightGraph: smart.reweightGraph,
282
+ nIterations: SMART_SUBSPACE_ITERATIONS, numCenters: NUM_PIVOTS_STRESS, epsilon: o.epsilon,
283
+ });
284
+ if (iterations < 0) return -1;
285
+ for (let i = 0; i < dim; i++) {
286
+ const c = dCoords[i]!;
287
+ let max = 1;
288
+ for (let j = 0; j < n; j++) {
289
+ if (Math.abs(c[j]!) > max) max = Math.abs(c[j]!);
290
+ }
291
+ for (let j = 0; j < n; j++) c[j] = c[j]! / max;
292
+ for (let j = 0; j < n; j++) c[j] = fma(drand48() - 0.5, SMART_NOISE, c[j]!);
293
+ orthog1(n, c);
294
+ }
295
+ return 0;
296
+ }
297
+
298
+ /**
299
+ * The initial layout: `smart_ini && n > 1` takes the subspace estimate. Returns
300
+ * -1 on failure, else whether some node is pinned, as 0 or 1.
301
+ * @see lib/neatogen/stress.c:stress_majorization_kD_mkernel
302
+ */
303
+ function initialLayout(n: number, dCoords: Float64Array[], nodes: Node[], o: StressOpts): number {
304
+ if (o.smart !== undefined && (o.opts & OPT_SMART_INIT) !== 0 && n > 1) {
305
+ return smartLayout(o.smart, n, dCoords, o);
306
+ }
307
+ return initLayout(n, o.dim, dCoords, nodes) ? 1 : 0;
249
308
  }
250
309
 
251
310
  /**
@@ -259,7 +318,9 @@ export function stressMajorizationKDMkernel(
259
318
  const { dim, maxi } = o;
260
319
  const exp = o.opts & OPT_EXP_FLAG;
261
320
  if (maxi < 0) return 0;
262
- const havePinned = initLayout(n, dim, dCoords, nodes);
321
+ const layout = initialLayout(n, dCoords, nodes, o);
322
+ if (layout < 0) return -1;
323
+ const havePinned = layout === 1;
263
324
  if (n === 1 || maxi === 0) return 0;
264
325
 
265
326
  const coords: Float32Array[] = [];
@@ -289,7 +350,6 @@ export function stressMajorizationKDMkernel(
289
350
  for (; iterations < maxi && !converged; iterations++) {
290
351
  buildLap1(st.lap1, lap2, coords, { n, dim, exp, ops: st.ops });
291
352
  const newStress = computeStress(st);
292
- if (typeof process !== 'undefined' && process.env['STRESS_DEBUG'] && iterations % 5 === 0) console.error(newStress.toFixed(3));
293
353
  const change = Math.abs(oldStress - newStress);
294
354
  converged = change / oldStress < o.epsilon || newStress < o.epsilon;
295
355
  oldStress = newStress;
@@ -0,0 +1,371 @@
1
+ // SPDX-License-Identifier: EPL-2.0
2
+
3
+ /**
4
+ * The fastest and least accurate stress optimization: a sparse distance matrix
5
+ * (40 pivots) within a vector space (the principal axes of a high-dimensional
6
+ * embedding). It only gives the initial layout of a smart start, reached from
7
+ * `stress_majorization_kD_mkernel` when `opt_smart_init` is set.
8
+ *
9
+ * Its one caller always passes a nonzero `smart_ini` and 40 pivots, so C's random
10
+ * directions and no-pivots branches cannot be reached and are not ported; nor is
11
+ * `visited_nodes`, always empty since `bfs_bounded` left. C aliases non-pivot rows
12
+ * into shared storage; here each row has its own arrays. C overruns that storage
13
+ * when a non-pivot node exists with n < 40 (only through a zero-length `len`
14
+ * truncation), which the port cannot reproduce.
15
+ *
16
+ * Fusion follows the 16.1 arm64 disassembly of `_compute_stress1` and the code
17
+ * inlined into `_stress_majorization_kD_mkernel`.
18
+ *
19
+ * @see lib/neatogen/stress.c:sparse_stress_subspace_majorization_kD
20
+ */
21
+
22
+ import { crand } from '../../common/crand.js';
23
+ import { fma } from '../../common/fma.js';
24
+ import { conjugateGradientF } from './conjgrad.js';
25
+ import type { VtxData } from './dijkstra.js';
26
+ import { centerCoordinate, embedGraph, pivotDistances, saveWeights } from './embed-graph.js';
27
+ import { computeNewWeights, restoreOldWeights } from './kkutils.js';
28
+ import { multDenseMat, multSparseDenseMatTranspose, rightMultWithVectorD, rightMultWithVectorTranspose } from './matrix-ops-dense.js';
29
+ import { iterativePCA1D, pcaAlloc } from './pca.js';
30
+ import { TOLERANCE_CG } from './stress.js';
31
+
32
+ const fr = Math.fround;
33
+
34
+ /** `stress_pca_dim`: dimensionality of the subspace. @see lib/neatogen/stress.c */
35
+ const STRESS_PCA_DIM = 50;
36
+ /** `MAX(2 * subspace_dim, 50)`'s floor. @see lib/neatogen/stress.c */
37
+ const MIN_EMBEDDING_PIVOTS = 50;
38
+ /** `dist_ij > 1e-30`: skip zero distances. @see lib/neatogen/stress.c */
39
+ const ZERO_DISTANCE = 1e-30;
40
+ /** `new_stress + 1e-10`. @see lib/neatogen/stress.c */
41
+ const STRESS_GUARD = 1e-10;
42
+
43
+ /**
44
+ * The scalar parameters of `sparse_stress_subspace_majorization_kD`, plus the
45
+ * `Epsilon` global.
46
+ */
47
+ export interface SubspaceOpts {
48
+ dim: number;
49
+ /** Scale exponent, 1 or 2. */
50
+ exp: number;
51
+ /** `model == MODEL_SUBSET`. */
52
+ reweightGraph: boolean;
53
+ nIterations: number;
54
+ /** Number of pivots in the sparse distance matrix. */
55
+ numCenters: number;
56
+ epsilon: number;
57
+ }
58
+
59
+ /** A row of the sparse distance matrix. @see lib/neatogen/stress.c:dist_data */
60
+ export interface DistData {
61
+ nedges: number;
62
+ edges: Int32Array;
63
+ edist: Int32Array;
64
+ }
65
+
66
+ /**
67
+ * Euclidean distance between nodes `i` and `j` in `dim` dimensions.
68
+ * @see lib/neatogen/kkutils.c:distance_kD
69
+ */
70
+ export function distanceKD(coords: readonly Float64Array[], dim: number, i: number, j: number): number {
71
+ let sum = 0;
72
+ for (let k = 0; k < dim; k++) {
73
+ const d = coords[k]![i]! - coords[k]![j]!;
74
+ sum = fma(d, d, sum);
75
+ }
76
+ return Math.sqrt(sum);
77
+ }
78
+
79
+ /**
80
+ * The overall stress.
81
+ * @see lib/neatogen/stress.c:compute_stress1
82
+ */
83
+ export function computeStress1(
84
+ coords: readonly Float64Array[], distances: readonly DistData[], dim: number, n: number, exp: number,
85
+ ): number {
86
+ let sum = 0;
87
+ for (let i = 0; i < n; i++) {
88
+ const row = distances[i]!;
89
+ for (let j = 0; j < row.nedges; j++) {
90
+ const node = row.edges[j]!;
91
+ if (node <= i) continue;
92
+ const dist = distanceKD(coords, dim, i, node);
93
+ const Dij = row.edist[j]!;
94
+ sum += exp === 2
95
+ ? ((Dij - dist) * (Dij - dist)) / (Dij * Dij)
96
+ : ((Dij - dist) * (Dij - dist)) / Dij;
97
+ }
98
+ }
99
+ return sum;
100
+ }
101
+
102
+ /** The pivots of the sparse distance matrix. */
103
+ interface Pivots {
104
+ /** If i is a pivot, its index; otherwise -1. C leaves a repeated pivot's last index. */
105
+ centerIndex: Int32Array;
106
+ /** The pivot nodes. */
107
+ invCenterIndex: Int32Array;
108
+ /** The distance between each pivot and each node. */
109
+ Dij: Int32Array[];
110
+ }
111
+
112
+ /**
113
+ * Lower `dist` to the new pivot's distances and pick the farthest node; a tie may
114
+ * take the later node, by a draw from libc's stream (`dist[j] == 0` ties too).
115
+ * @see lib/neatogen/stress.c:sparse_stress_subspace_majorization_kD
116
+ */
117
+ function nextPivot(dist: Int32Array, Di: Int32Array, n: number, from: number): number {
118
+ let node = from;
119
+ let maxDist = 0;
120
+ for (let j = 0; j < n; j++) {
121
+ dist[j] = Math.min(dist[j]!, Di[j]!);
122
+ if (dist[j]! > maxDist || (dist[j] === maxDist && crand() % (j + 1) === 0)) {
123
+ node = j;
124
+ maxDist = dist[j]!;
125
+ }
126
+ }
127
+ return node;
128
+ }
129
+
130
+ /**
131
+ * Select `numCenters` pivots uniformly spread over the graph; the first one is
132
+ * random.
133
+ * @see lib/neatogen/stress.c:sparse_stress_subspace_majorization_kD
134
+ */
135
+ function selectPivots(graph: VtxData[], n: number, numCenters: number, reweightGraph: boolean): Pivots {
136
+ const centerIndex = new Int32Array(n).fill(-1);
137
+ const invCenterIndex = new Int32Array(numCenters);
138
+ const Dij = Array.from({ length: numCenters }, () => new Int32Array(n));
139
+ const dist = new Int32Array(n);
140
+
141
+ let node = crand() % n;
142
+ centerIndex[node] = 0;
143
+ invCenterIndex[0] = node;
144
+ pivotDistances(node, graph, n, reweightGraph, Dij[0]!);
145
+
146
+ // find the most distant node from the first pivot
147
+ let maxDist = 0;
148
+ for (let i = 0; i < n; i++) {
149
+ dist[i] = Dij[0]![i]!;
150
+ if (dist[i]! > maxDist) {
151
+ node = i;
152
+ maxDist = dist[i]!;
153
+ }
154
+ }
155
+ // select the others
156
+ for (let i = 1; i < numCenters; i++) {
157
+ centerIndex[node] = i;
158
+ invCenterIndex[i] = node;
159
+ pivotDistances(node, graph, n, reweightGraph, Dij[i]!);
160
+ node = nextPivot(dist, Dij[i]!, n, node);
161
+ }
162
+ return { centerIndex, invCenterIndex, Dij };
163
+ }
164
+
165
+ /** A pivot's row: its distance to every other node. */
166
+ function pivotRow(i: number, n: number, Di: Int32Array): DistData {
167
+ const edges = new Int32Array(n - 1);
168
+ const edist = new Int32Array(n - 1);
169
+ for (let j = 0; j < i; j++) {
170
+ edges[j] = j;
171
+ edist[j] = Di[j]!;
172
+ }
173
+ for (let j = i + 1; j < n; j++) {
174
+ edges[j - 1] = j;
175
+ edist[j - 1] = Di[j]!;
176
+ }
177
+ return { nedges: n - 1, edges, edist };
178
+ }
179
+
180
+ /** A non-pivot's row: its distance to all pivots. */
181
+ function nonPivotRow(i: number, numCenters: number, p: Pivots): DistData {
182
+ const edges = new Int32Array(numCenters);
183
+ const edist = new Int32Array(numCenters);
184
+ for (let j = 0; j < numCenters; j++) {
185
+ edges[j] = p.invCenterIndex[j]!;
186
+ edist[j] = p.Dij[j]![i]!;
187
+ }
188
+ return { nedges: numCenters, edges, edist };
189
+ }
190
+
191
+ /**
192
+ * Construct the sparse distance matrix.
193
+ * @see lib/neatogen/stress.c:sparse_stress_subspace_majorization_kD
194
+ */
195
+ function buildDistances(n: number, numCenters: number, p: Pivots): DistData[] {
196
+ const distances: DistData[] = [];
197
+ for (let i = 0; i < n; i++) {
198
+ const index = p.centerIndex[i]!;
199
+ distances.push(index >= 0 ? pivotRow(i, n, p.Dij[index]!) : nonPivotRow(i, numCenters, p));
200
+ }
201
+ return distances;
202
+ }
203
+
204
+ /**
205
+ * The Laplacian of the sparse distances: self loop first, weights C `float`.
206
+ * @see lib/neatogen/stress.c:sparse_stress_subspace_majorization_kD
207
+ */
208
+ function buildSparseLaplacian(distances: readonly DistData[], n: number, exp: number): VtxData[] {
209
+ const lap: VtxData[] = [];
210
+ for (let i = 0; i < n; i++) {
211
+ const row = distances[i]!;
212
+ const edges = [i];
213
+ const ewgts = [0];
214
+ let degree = 0;
215
+ for (let j = 0; j < row.nedges; j++) {
216
+ const d = fr(row.edist[j]!);
217
+ const w = exp === 2 ? fr(-1 / fr(d * d)) : fr(-1 / d);
218
+ edges.push(row.edges[j]!);
219
+ ewgts.push(w);
220
+ degree -= w;
221
+ }
222
+ ewgts[0] = fr(degree);
223
+ lap.push({ nedges: row.nedges + 1, edges, ewgts });
224
+ }
225
+ return lap;
226
+ }
227
+
228
+ /**
229
+ * The smart initial direction vectors; the layout is subspace*directions.
230
+ * @see lib/neatogen/stress.c:sparse_stress_subspace_majorization_kD
231
+ */
232
+ function initialDirections(subspace: readonly Float64Array[], subspaceDim: number, n: number, dim: number): Float64Array[] {
233
+ // one block, as C: with fewer nodes than dimensions `directions[k][k]` lands in a later row
234
+ const storage = new Float64Array(dim * subspaceDim);
235
+ const directions = Array.from({ length: dim }, (_, k) => storage.subarray(k * subspaceDim, (k + 1) * subspaceDim));
236
+ if (dim !== 2) {
237
+ // use the first vectors in the eigenspace: each direction points to its principal axis
238
+ for (let k = 0; k < dim; k++) storage[k * subspaceDim + k] = 1;
239
+ return directions;
240
+ }
241
+ // for the frequent 2-D case we prefer iterative-PCA over PCA
242
+ directions[0]![0] = 1; // first pca projection vector
243
+ if (!iterativePCA1D(subspace, subspaceDim, n, directions[1]!)) {
244
+ directions[1]!.fill(0);
245
+ directions[1]![1] = 1;
246
+ }
247
+ return directions;
248
+ }
249
+
250
+ /** Everything the optimization loop reads. */
251
+ interface SubspaceState {
252
+ readonly n: number;
253
+ readonly dim: number;
254
+ readonly subspaceDim: number;
255
+ readonly subspace: readonly Float64Array[];
256
+ readonly distances: readonly DistData[];
257
+ readonly lap: readonly VtxData[];
258
+ readonly matrix: readonly Float32Array[];
259
+ readonly directions: readonly Float64Array[];
260
+ readonly coords: readonly Float64Array[];
261
+ readonly b: Float64Array;
262
+ readonly bRestricted: Float64Array;
263
+ }
264
+
265
+ /**
266
+ * The vector b of axis `k`: multiply on the fly with the distance-based
267
+ * Laplacian. `-ewgts[j] * dist_list[j]` is C `float` arithmetic.
268
+ * @see lib/neatogen/stress.c:sparse_stress_subspace_majorization_kD
269
+ */
270
+ function computeB(st: SubspaceState, k: number): void {
271
+ const { n, dim, coords, distances, lap, b } = st;
272
+ const ck = coords[k]!;
273
+ for (let i = 0; i < n; i++) {
274
+ let degree = 0;
275
+ let bi = 0;
276
+ const { edges, ewgts, nedges } = lap[i]!;
277
+ const edist = distances[i]!.edist;
278
+ for (let j = 1; j < nedges; j++) {
279
+ const node = edges[j]!;
280
+ const distIj = distanceKD(coords, dim, i, node);
281
+ if (distIj > ZERO_DISTANCE) { // skip zero distances
282
+ const Lij = fr(-ewgts[j]! * fr(edist[j - 1]!)) / distIj; // L_ij=w_{ij}*d_{ij}/dist_{ij}
283
+ degree -= Lij;
284
+ bi = fma(Lij, ck[node]!, bi);
285
+ }
286
+ }
287
+ b[i] = fma(degree, ck[i]!, bi);
288
+ }
289
+ }
290
+
291
+ /** Axis-by-axis optimization. Returns true when conjugate gradient fails. */
292
+ function optimizeAxes(st: SubspaceState): boolean {
293
+ const { n, dim, subspaceDim, subspace, matrix, directions, coords, b, bRestricted } = st;
294
+ for (let k = 0; k < dim; k++) {
295
+ computeB(st, k);
296
+ rightMultWithVectorD(subspace, subspaceDim, n, b, bRestricted);
297
+ const rc = conjugateGradientF(matrix, directions[k]!, bRestricted, subspaceDim, {
298
+ tol: TOLERANCE_CG, maxIterations: subspaceDim, ortho1: false,
299
+ });
300
+ if (rc !== 0) return true;
301
+ rightMultWithVectorTranspose(subspace, n, subspaceDim, directions[k]!, coords[k]!);
302
+ }
303
+ return false;
304
+ }
305
+
306
+ /**
307
+ * Layout optimization. Returns the iteration count, or -1 when conjugate
308
+ * gradient fails.
309
+ * @see lib/neatogen/stress.c:sparse_stress_subspace_majorization_kD
310
+ */
311
+ function optimizeLayout(st: SubspaceState, o: SubspaceOpts): number {
312
+ let oldStress = computeStress1(st.coords, st.distances, st.dim, st.n, o.exp);
313
+ let converged = false;
314
+ let iterations = 0;
315
+ for (; iterations < o.nIterations && !converged; iterations++) {
316
+ if (optimizeAxes(st)) return -1;
317
+ if (iterations % 2 === 0) { // check for convergence each two iterations
318
+ const newStress = computeStress1(st.coords, st.distances, st.dim, st.n, o.exp);
319
+ converged = Math.abs(newStress - oldStress) / (newStress + STRESS_GUARD) < o.epsilon;
320
+ oldStress = newStress;
321
+ }
322
+ }
323
+ return iterations;
324
+ }
325
+
326
+ /** The subspace in which we optimize: PCA of the high-dimensional embedding. */
327
+ function computeSubspace(graph: VtxData[], n: number, subspaceDim: number, reweightGraph: boolean): Float64Array[] {
328
+ const subspace = Array.from({ length: subspaceDim }, () => new Float64Array(n));
329
+ const numCentersLocal = Math.min(n, Math.max(2 * subspaceDim, MIN_EMBEDDING_PIVOTS));
330
+ const fullCoords = embedGraph(graph, n, numCentersLocal, reweightGraph);
331
+ centerCoordinate(fullCoords, n, numCentersLocal);
332
+ pcaAlloc(fullCoords, numCentersLocal, n, subspace, subspaceDim);
333
+ return subspace;
334
+ }
335
+
336
+ /**
337
+ * Writes the layout to `coords` and returns the iteration count, or -1 when
338
+ * conjugate gradient fails.
339
+ * @see lib/neatogen/stress.c:sparse_stress_subspace_majorization_kD
340
+ */
341
+ export function sparseStressSubspaceMajorizationKD(
342
+ graph: VtxData[], n: number, coords: readonly Float64Array[], o: SubspaceOpts,
343
+ ): number {
344
+ const { dim, exp, reweightGraph, numCenters } = o;
345
+ const subspaceDim = Math.min(STRESS_PCA_DIM, n);
346
+ const subspace = computeSubspace(graph, n, subspaceDim, reweightGraph);
347
+
348
+ // the sparse-shortest-distances matrix
349
+ const oldWeights = saveWeights(graph, n);
350
+ if (reweightGraph) computeNewWeights(graph, n); // weight graph to separate high-degree nodes
351
+ const pivots = selectPivots(graph, n, numCenters, reweightGraph);
352
+ const distances = buildDistances(n, numCenters, pivots);
353
+ const lap = buildSparseLaplacian(distances, n, exp);
354
+
355
+ // an initial k-D layout
356
+ const directions = initialDirections(subspace, subspaceDim, n, dim);
357
+ for (let k = 0; k < dim; k++) {
358
+ rightMultWithVectorTranspose(subspace, n, subspaceDim, directions[k]!, coords[k]!);
359
+ }
360
+
361
+ // the restriction of the Laplacian to the subspace
362
+ const tmpMat = multSparseDenseMatTranspose(lap, subspace, n, subspaceDim);
363
+ const matrix = multDenseMat(subspace, tmpMat, subspaceDim, n, subspaceDim);
364
+
365
+ const iterations = optimizeLayout({
366
+ n, dim, subspaceDim, subspace, distances, lap, matrix, directions, coords,
367
+ b: new Float64Array(n), bRestricted: new Float64Array(subspaceDim),
368
+ }, o);
369
+ if (reweightGraph) restoreOldWeights(graph, n, oldWeights);
370
+ return iterations;
371
+ }
@@ -56,7 +56,9 @@ export function vpscAdjust(g: Graph): number {
56
56
  };
57
57
  removeoverlaps(nodes.length, coords, opt);
58
58
  nodes.forEach((n, j) => {
59
- n.info.pos = [coords[0]![j]!, coords[1]![j]!];
59
+ /* C stores only the dim=2 coordinates; the others of ND_pos stay. */
60
+ n.info.pos![0] = coords[0]![j]!;
61
+ n.info.pos![1] = coords[1]![j]!;
60
62
  });
61
63
  return 0;
62
64
  }
@@ -0,0 +1,23 @@
1
+ graph G {
2
+ graph [bb="0,0,320,116"];
3
+ node [label="\N"];
4
+ subgraph _cc_0 {
5
+ c [height=0.5,
6
+ pos="77,98",
7
+ width=0.75];
8
+ }
9
+ a [height=0.5,
10
+ pos="27,18",
11
+ width=0.75];
12
+ b [height=0.5,
13
+ pos="153,18",
14
+ width=0.75];
15
+ a -- b [pos="54.34,18 75.475,18 104.59,18 125.71,18"];
16
+ d [height=0.5,
17
+ pos="167,88",
18
+ width=0.75];
19
+ e [height=0.5,
20
+ pos="293,88",
21
+ width=0.75];
22
+ d -- e [pos="194.34,88 215.47,88 244.59,88 265.71,88"];
23
+ }
@@ -0,0 +1 @@
1
+ graph G { a -- b; subgraph _cc_0 { c } d -- e; }
@@ -0,0 +1,38 @@
1
+ graph G {
2
+ graph [_draw_="c 9 -#fffffe00 C 7 -#ffffff P 4 0 0 0 116 320 116 320 0 ",
3
+ bb="0,0,320,116",
4
+ xdotversion=1.7
5
+ ];
6
+ node [label="\N"];
7
+ subgraph _cc_0 {
8
+ c [_draw_="c 7 -#000000 e 77 98 27 18 ",
9
+ _ldraw_="F 14 11 -Times-Roman c 7 -#000000 T 77 93.8 0 6.21 1 -c ",
10
+ height=0.5,
11
+ pos="77,98",
12
+ width=0.75];
13
+ }
14
+ a [_draw_="c 7 -#000000 e 27 18 27 18 ",
15
+ _ldraw_="F 14 11 -Times-Roman c 7 -#000000 T 27 13.8 0 6.21 1 -a ",
16
+ height=0.5,
17
+ pos="27,18",
18
+ width=0.75];
19
+ b [_draw_="c 7 -#000000 e 153 18 27 18 ",
20
+ _ldraw_="F 14 11 -Times-Roman c 7 -#000000 T 153 13.8 0 7 1 -b ",
21
+ height=0.5,
22
+ pos="153,18",
23
+ width=0.75];
24
+ a -- b [_draw_="c 7 -#000000 B 4 54.34 18 75.47 18 104.59 18 125.71 18 ",
25
+ pos="54.34,18 75.475,18 104.59,18 125.71,18"];
26
+ d [_draw_="c 7 -#000000 e 167 88 27 18 ",
27
+ _ldraw_="F 14 11 -Times-Roman c 7 -#000000 T 167 83.8 0 7 1 -d ",
28
+ height=0.5,
29
+ pos="167,88",
30
+ width=0.75];
31
+ e [_draw_="c 7 -#000000 e 293 88 27 18 ",
32
+ _ldraw_="F 14 11 -Times-Roman c 7 -#000000 T 293 83.8 0 6.21 1 -e ",
33
+ height=0.5,
34
+ pos="293,88",
35
+ width=0.75];
36
+ d -- e [_draw_="c 7 -#000000 B 4 194.34 88 215.47 88 244.59 88 265.71 88 ",
37
+ pos="194.34,88 215.47,88 244.59,88 265.71,88"];
38
+ }
@@ -0,0 +1,23 @@
1
+ graph G {
2
+ graph [bb="0,0,224.21,126"];
3
+ node [label="\N"];
4
+ subgraph _cc_0 {
5
+ c [height=0.5,
6
+ pos="36,108",
7
+ width=0.75];
8
+ }
9
+ a [height=0.5,
10
+ pos="27,28.639",
11
+ width=0.75];
12
+ b [height=0.5,
13
+ pos="98.21,18",
14
+ width=0.75];
15
+ a -- b [pos="53.516,24.677 59.368,23.803 65.572,22.876 71.434,22"];
16
+ d [height=0.5,
17
+ pos="126,82.639",
18
+ width=0.75];
19
+ e [height=0.5,
20
+ pos="197.21,72",
21
+ width=0.75];
22
+ d -- e [pos="152.52,78.677 158.37,77.803 164.57,76.876 170.43,76"];
23
+ }
@@ -0,0 +1 @@
1
+ graph G { a -- b; subgraph _cc_0 { c } d -- e; }
@@ -0,0 +1,38 @@
1
+ graph G {
2
+ graph [_draw_="c 9 -#fffffe00 C 7 -#ffffff P 4 0 0 0 126 224.21 126 224.21 0 ",
3
+ bb="0,0,224.21,126",
4
+ xdotversion=1.7
5
+ ];
6
+ node [label="\N"];
7
+ subgraph _cc_0 {
8
+ c [_draw_="c 7 -#000000 e 36 108 27 18 ",
9
+ _ldraw_="F 14 11 -Times-Roman c 7 -#000000 T 36 103.8 0 6.21 1 -c ",
10
+ height=0.5,
11
+ pos="36,108",
12
+ width=0.75];
13
+ }
14
+ a [_draw_="c 7 -#000000 e 27 28.64 27 18 ",
15
+ _ldraw_="F 14 11 -Times-Roman c 7 -#000000 T 27 24.44 0 6.21 1 -a ",
16
+ height=0.5,
17
+ pos="27,28.639",
18
+ width=0.75];
19
+ b [_draw_="c 7 -#000000 e 98.21 18 27 18 ",
20
+ _ldraw_="F 14 11 -Times-Roman c 7 -#000000 T 98.21 13.8 0 7 1 -b ",
21
+ height=0.5,
22
+ pos="98.21,18",
23
+ width=0.75];
24
+ a -- b [_draw_="c 7 -#000000 B 4 53.52 24.68 59.37 23.8 65.57 22.88 71.43 22 ",
25
+ pos="53.516,24.677 59.368,23.803 65.572,22.876 71.434,22"];
26
+ d [_draw_="c 7 -#000000 e 126 82.64 27 18 ",
27
+ _ldraw_="F 14 11 -Times-Roman c 7 -#000000 T 126 78.44 0 7 1 -d ",
28
+ height=0.5,
29
+ pos="126,82.639",
30
+ width=0.75];
31
+ e [_draw_="c 7 -#000000 e 197.21 72 27 18 ",
32
+ _ldraw_="F 14 11 -Times-Roman c 7 -#000000 T 197.21 67.8 0 6.21 1 -e ",
33
+ height=0.5,
34
+ pos="197.21,72",
35
+ width=0.75];
36
+ d -- e [_draw_="c 7 -#000000 B 4 152.52 78.68 158.37 77.8 164.57 76.88 170.43 76 ",
37
+ pos="152.52,78.677 158.37,77.803 164.57,76.876 170.43,76"];
38
+ }
@@ -0,0 +1,23 @@
1
+ graph G {
2
+ graph [bb="0,0,170,76"];
3
+ node [label="\N"];
4
+ subgraph _cc_0 {
5
+ c [height=0.5,
6
+ pos="143,58",
7
+ width=0.75];
8
+ }
9
+ a [height=0.5,
10
+ pos="27,58",
11
+ width=0.75];
12
+ b [height=0.5,
13
+ pos="85,58",
14
+ width=0.75];
15
+ a -- b [pos="54.302,58 55.477,58 56.656,58 57.831,58"];
16
+ d [height=0.5,
17
+ pos="27,18",
18
+ width=0.75];
19
+ e [height=0.5,
20
+ pos="85,18",
21
+ width=0.75];
22
+ d -- e [pos="54.302,18 55.477,18 56.656,18 57.831,18"];
23
+ }
@@ -0,0 +1 @@
1
+ graph G { a -- b; subgraph _cc_0 { c } d -- e; }