feat(linalg): L5 examples, public feature pages, and skill docs
Ship SVD / least-squares examples, heatmap-hinton draw paths, coerce dense factors into MatExpr ops, and document ext/linalg in skill/README. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
70fb2fbfb2
commit
01287d9e7e
15 files changed
+238
-26
No files matched your search
@@ -0,0 +1,12 @@
|
||||
# linalg-least-squares
|
||||
|
||||
Overdetermined least squares via `ext/linalg`: `factorize kind=qr`, `Qᵀb`, solve `R`, plus a heatmap SVG of `A`.
|
||||
|
||||
```bash
|
||||
cargo build --release -p marqdo_plugin_linalg
|
||||
marqdo ext add linalg # once (re-run after rebuilding the plugin)
|
||||
marqdo run examples/linalg-least-squares/index.mq.md
|
||||
# optional: marqdo view examples/linalg-least-squares/
|
||||
```
|
||||
|
||||
Design: [ext-linalg.md](../../doc/design/ext-linalg.md) · sibling: [linalg-svd](../linalg-svd/).
|
||||
@@ -0,0 +1,45 @@
|
||||
---
|
||||
title: Least squares via QR
|
||||
description: Overdetermined Ax≈b with ext/linalg QR + heatmap.
|
||||
import la:ext/linalg/linalg.mq.md
|
||||
import math:lib/math.mq.md
|
||||
---
|
||||
|
||||
# Least squares from a runnable document
|
||||
|
||||
Fit a line through three points with an overdetermined `A x ≈ b`. Factor `A = QR`, form `Qᵀ b`, then solve the square upper-triangular `R`. A heatmap makes the design matrix visible in `view`.
|
||||
|
||||
# main
|
||||
|
||||
`A` =
|
||||
$$
|
||||
\begin{bmatrix}1&0\\1&1\\1&2\end{bmatrix}
|
||||
$$
|
||||
|
||||
`b` =
|
||||
$$
|
||||
\begin{pmatrix}1\\2\\2\end{pmatrix}
|
||||
$$
|
||||
|
||||
*`A` = > la.from_formula formula=`A`*
|
||||
*`b` = > la.from_formula formula=`b`*
|
||||
|
||||
*`_` = > la.draw factor=`A` kind="heatmap" path="ls-heatmap.svg"*
|
||||
|
||||
*`qr` = > la.factorize matrix=`A` kind="qr"*
|
||||
*`Q` = qr[^Q]*
|
||||
*`R` = qr[^R]*
|
||||
*`Qt` = > la.transpose expr=`Q`*
|
||||
*`Qtb` = > la.matmul a=`Qt` b=`b`*
|
||||
*`sol` = > la.solve a=`R` b=`Qtb`*
|
||||
*`x` = sol[^x]*
|
||||
|
||||
*`Ax` = > la.matmul a=`A` b=`x`*
|
||||
*`r0` = > at value=Ax[^data] index=0*
|
||||
*`ax0` = > at value=`r0` index=0*
|
||||
*`diff` = > math.sub a=`ax0` b=1*
|
||||
*`diff` = > math.abs value=`diff`*
|
||||
|
||||
> print text=`x`
|
||||
> print text=`diff`
|
||||
> print text=ls-ok
|
||||
@@ -0,0 +1,12 @@
|
||||
# linalg-svd
|
||||
|
||||
Dense SVD via `ext/linalg`: singular values + structure / hinton SVG.
|
||||
|
||||
```bash
|
||||
cargo build --release -p marqdo_plugin_linalg
|
||||
marqdo ext add linalg
|
||||
marqdo run examples/linalg-svd/index.mq.md
|
||||
# optional: marqdo view examples/linalg-svd/
|
||||
```
|
||||
|
||||
Design: [ext-linalg.md](../../doc/design/ext-linalg.md) · sibling: [linalg-least-squares](../linalg-least-squares/).
|
||||
@@ -0,0 +1,25 @@
|
||||
---
|
||||
title: SVD structure demo
|
||||
description: Diagonal SVD + structure SVG via ext/linalg.
|
||||
import la:ext/linalg/linalg.mq.md
|
||||
---
|
||||
|
||||
# SVD from a runnable document
|
||||
|
||||
A diagonal matrix has singular values on the diagonal. `factorize kind=svd` returns `U`, `S`, `Vt`; `draw kind=svd` writes a teaching structure SVG for `view`.
|
||||
|
||||
# main
|
||||
|
||||
`M` =
|
||||
$$
|
||||
\begin{bmatrix}4&0\\0&2\end{bmatrix}
|
||||
$$
|
||||
|
||||
*`M` = > la.from_formula formula=`M`*
|
||||
*`f` = > la.factorize matrix=`M` kind="svd"*
|
||||
*`S` = f[^S]*
|
||||
*`_` = > la.draw factor=`f` kind="svd" path="svd-structure.svg"*
|
||||
*`hm` = > la.draw factor=`M` kind="hinton" path="svd-hinton.svg"*
|
||||
|
||||
> print text=`S`
|
||||
> print text=svd-ok
|
||||
Reference in new issue
Block a user