@algorisys/tinyfly 0.118.0 → 0.119.1

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.
@@ -84,6 +84,8 @@ export interface TexPlacement {
84
84
  opacity?: number;
85
85
  /** Prefixed to every piece's id, so several equations in one figure stay apart */
86
86
  idPrefix: string;
87
+ /** Colour names TeX's \\color{…} may use (a theme's palette), mapped to CSS colours */
88
+ palette?: Record<string, string>;
87
89
  }
88
90
  /** The origin (left edge, baseline) of a layout placed by `place`, in px. */
89
91
  export declare function texOrigin(layout: TexLayout, place: Pick<TexPlacement, 'x' | 'y' | 'size' | 'align' | 'baseline'>): Vec2;
@@ -1,5 +1,7 @@
1
1
  import type { Vec2 } from '../linear/vec2';
2
2
  import type { SearchKind } from '../discrete/graph-search';
3
+ import type { Activation } from '../ml/network';
4
+ import type { Colormap } from '../ml/colormap';
3
5
  /**
4
6
  * A maths figure as plain JSON: a coordinate plane and the items drawn on it.
5
7
  *
@@ -395,7 +397,105 @@ export interface ClockItem extends ItemBase {
395
397
  /** World units (default 2) */
396
398
  radius?: number;
397
399
  }
398
- export type MathItem = GridItem | AxesItem | VectorItem | BasisItem | PointItem | FunctionItem | ParametricItem | PolygonItem | LineItem | LabelItem | EquationItem | TangentItem | RiemannItem | AreaItem | TaylorItem | HistogramItem | DistributionItem | GaltonItem | ScatterItem | BayesItem | GraphItem | VennItem | ClockItem;
400
+ /** A fully connected neural network; activations flow layer by layer as `flow` grows. */
401
+ export interface NetworkItem extends ItemBase {
402
+ kind: 'network';
403
+ /** Nodes per layer, input first: [3, 4, 4, 2] */
404
+ layers: number[];
405
+ /** Seed for the weights (default the item id) */
406
+ seed?: number | string;
407
+ activation?: Activation;
408
+ /** Input values (numbers or value names; default 0.5 each) */
409
+ inputs?: NumRef[];
410
+ /** How far activations have flowed: 0 the inputs only, 1 the first hidden layer … (default all) */
411
+ flow?: NumRef;
412
+ /** Centre and size, world units (default most of the view) */
413
+ at?: Vec2;
414
+ size?: Vec2;
415
+ /** TeX labels beside the input and output nodes */
416
+ labels?: {
417
+ inputs?: string[];
418
+ outputs?: string[];
419
+ };
420
+ /** Node radius, px at a 600 px figure (default 16) */
421
+ radius?: number;
422
+ }
423
+ /** A grid of coloured cells: given values (attention weights) or a function of x and y. */
424
+ export interface HeatmapItem extends ItemBase {
425
+ kind: 'heatmap';
426
+ /** Rows of values, top row first */
427
+ cells?: number[][];
428
+ /** Or a function of x and y, sampled over `region` */
429
+ expr?: string;
430
+ region?: [[number, number], [number, number]];
431
+ /** Samples per side for `expr` (default 48) */
432
+ resolution?: number;
433
+ /** Normalise each row with softmax first, as attention does */
434
+ softmax?: boolean;
435
+ /** World bottom-left corner and size, for `cells` (default most of the view) */
436
+ at?: Vec2;
437
+ size?: Vec2;
438
+ /** Value range for the colours (default the cells' min and max) */
439
+ range?: [number, number];
440
+ colormap?: Colormap;
441
+ rowLabels?: string[];
442
+ colLabels?: string[];
443
+ /** Write each value in its cell (default false) */
444
+ values?: boolean;
445
+ }
446
+ /** Level curves of f(x, y). */
447
+ export interface ContoursItem extends ItemBase {
448
+ kind: 'contours';
449
+ expr: string;
450
+ /** How many levels between the sampled min and max (default 10), or the levels themselves */
451
+ levels?: number | number[];
452
+ region?: [[number, number], [number, number]];
453
+ resolution?: number;
454
+ colormap?: Colormap;
455
+ width?: number;
456
+ }
457
+ /** Gradient descent on f(x, y) from `start`: `steps` taken so far (fractional: the next one under way). */
458
+ export interface DescentItem extends ItemBase {
459
+ kind: 'descent';
460
+ expr: string;
461
+ start: VecRef;
462
+ rate: NumRef;
463
+ steps: NumRef;
464
+ momentum?: NumRef;
465
+ width?: number;
466
+ }
467
+ /** Logistic regression on two seeded clusters, trained epoch by epoch: the decision boundary moves into place. */
468
+ export interface ClassifierItem extends ItemBase {
469
+ kind: 'classifier';
470
+ /** Cluster centres (default [[-1.5, -1], [1.5, 1]]) */
471
+ centres?: [Vec2, Vec2];
472
+ /** Points per cluster (default 40) */
473
+ count?: number;
474
+ spread?: number;
475
+ seed?: number | string;
476
+ /** Epochs trained (fractional: part way to the next) */
477
+ epochs: NumRef;
478
+ /** Learning rate (default 0.5) */
479
+ rate?: number;
480
+ /** The model before training, [w₁, w₂, b] (default a deliberately wrong guess, so the boundary visibly turns into place) */
481
+ start?: [number, number, number];
482
+ /** Shade P(class) behind the points (default true) */
483
+ probability?: boolean;
484
+ }
485
+ /** k-means on seeded clusters: points coloured by their nearest centroid, centroids moving each iteration. */
486
+ export interface KMeansItem extends ItemBase {
487
+ kind: 'kmeans';
488
+ /** Where the true clusters are */
489
+ centres: Vec2[];
490
+ count?: number;
491
+ spread?: number;
492
+ seed?: number | string;
493
+ /** How many centroids (default one per centre) */
494
+ k?: number;
495
+ /** Iterations done (fractional: centroids part way to the next) */
496
+ iteration: NumRef;
497
+ }
498
+ export type MathItem = GridItem | AxesItem | VectorItem | BasisItem | PointItem | FunctionItem | ParametricItem | PolygonItem | LineItem | LabelItem | EquationItem | TangentItem | RiemannItem | AreaItem | TaylorItem | HistogramItem | DistributionItem | GaltonItem | ScatterItem | BayesItem | GraphItem | VennItem | ClockItem | NetworkItem | HeatmapItem | ContoursItem | DescentItem | ClassifierItem | KMeansItem;
399
499
  export type MathItemKind = MathItem['kind'];
400
500
  export declare const ITEM_KINDS: readonly MathItemKind[];
401
501
  export type MathThemeName = 'dark' | 'light' | 'chalk';
@@ -0,0 +1,47 @@
1
+ import { type LogisticModel } from '../../ml/classify';
2
+ import { type Vec2 } from '../../linear/vec2';
3
+ import type { ClassifierItem, ContoursItem, DescentItem, HeatmapItem, KMeansItem, NetworkItem } from '../figure-spec';
4
+ import { type Shape } from '../display-list';
5
+ import { type ItemContext, type Values } from '../item-context';
6
+ /** Every layer's activations, and how far they have flowed. */
7
+ export declare function networkState(item: NetworkItem, values: Values): {
8
+ network: import("../..").Network;
9
+ activations: number[][];
10
+ flow: number;
11
+ };
12
+ export declare function layoutNetwork(item: NetworkItem, ctx: ItemContext): Shape[];
13
+ /** The cells a heatmap shows: given (optionally softmaxed by row) or sampled from its expression. */
14
+ export declare function heatmapCells(item: HeatmapItem, ctx: Pick<ItemContext, 'plane' | 'scope'>): {
15
+ cells: number[][];
16
+ box: [Vec2, Vec2];
17
+ };
18
+ export declare function layoutHeatmap(item: HeatmapItem, ctx: ItemContext): Shape[];
19
+ export declare function layoutContours(item: ContoursItem, ctx: ItemContext): Shape[];
20
+ /** The descent path so far: whole steps plus the fraction of the next. */
21
+ export declare function descentState(item: DescentItem, values: Values, scope: Record<string, number>): {
22
+ path: Vec2[];
23
+ here: Vec2;
24
+ step: number;
25
+ diverged: boolean;
26
+ };
27
+ export declare function layoutDescent(item: DescentItem, ctx: ItemContext): Shape[];
28
+ export declare function classifierState(item: ClassifierItem, values: Values): {
29
+ data: {
30
+ point: Vec2;
31
+ label: number;
32
+ }[];
33
+ model: LogisticModel;
34
+ epochs: number;
35
+ };
36
+ export declare function layoutClassifier(item: ClassifierItem, ctx: ItemContext): Shape[];
37
+ export declare function kmeansState(item: KMeansItem, values: Values): {
38
+ points: Vec2[];
39
+ history: Vec2[][];
40
+ centroids: Vec2[];
41
+ owners: number[];
42
+ iteration: number;
43
+ iterations: number;
44
+ };
45
+ export declare function layoutKMeans(item: KMeansItem, ctx: ItemContext): Shape[];
46
+ /** Derived numbers for the ML items, for TeX readouts. */
47
+ export declare function mlDerived(item: NetworkItem | DescentItem | ClassifierItem | KMeansItem, values: Values, scope: Record<string, number>): Record<string, number>;
@@ -23,6 +23,12 @@ export { ballPath, ballAt, binOf } from './prob/galton';
23
23
  export { bayesAreas, type BayesAreas } from './prob/bayes';
24
24
  export { searchEvents, treeLayout, adjacency, SEARCH_KINDS, type SearchKind, type SearchEvent, type GraphEdge } from './discrete/graph-search';
25
25
  export { parseSetExpression, inRegion, regionCells, setNames, type SetExpression } from './discrete/set-expression';
26
+ export { seededNetwork, forward, activate, ACTIVATIONS, type Network, type Activation } from './ml/network';
27
+ export { contourLines, sampleGrid } from './ml/contours';
28
+ export { descentPath, surface } from './ml/descent';
29
+ export { blobs, trainLogistic, predict, accuracy, logLoss, type LogisticModel } from './ml/classify';
30
+ export { kmeansHistory, assign, inertia } from './ml/kmeans';
31
+ export { colorAt, blendOver, COLORMAPS, type Colormap } from './ml/colormap';
26
32
  export { parseTex, TexError, TEX_COMMANDS, SYMBOLS, type TexNode, type TexClass } from './tex/tex-parser';
27
33
  export { layoutTex, type TexLayout, type TexPiece, type TexGlyph, type TexRule, type TexStroke, type TexLayoutOptions } from './tex/tex-layout';
28
34
  export { morphEquation, type MorphPiece, type PlacedLayout } from './tex/equation-morph';
@@ -42,6 +48,7 @@ export { linearMapFigure, determinantFigure, eigenFigure, vectorSumFigure, spanF
42
48
  export { tangentFigure, secantFigure, riemannFigure, areaFigure, taylorFigure, limitFigure, type CalculusOptions } from './presets/calculus';
43
49
  export { normalFigure, binomialFigure, cltFigure, galtonFigure, monteCarloPiFigure, regressionFigure, bayesFigure, type ProbabilityOptions } from './presets/probability';
44
50
  export { graphSearchFigure, shortestPathFigure, recursionTreeFigure, vennFigure, clockFigure, SAMPLE_GRAPH, type DiscreteOptions } from './presets/discrete';
51
+ export { neuralNetworkFigure, gradientDescentFigure, attentionFigure, decisionBoundaryFigure, kmeansFigure, activationFigure, type MlOptions } from './presets/ml';
45
52
  import type { MathFigureSpec } from './figure/figure-spec';
46
53
  import { type MathProps } from './figure/layout-figure';
47
54
  /** A figure checked up front: returns it unchanged, or throws a message that says how to fix it. */
@@ -0,0 +1,30 @@
1
+ import type { Vec2 } from '../linear/vec2';
2
+ /** Points in clusters round `centres`, `count` per cluster, `spread` apart: [point, cluster] pairs. Seeded. */
3
+ export declare function blobs(centres: Vec2[], count: number, spread: number, seed: number | string): {
4
+ point: Vec2;
5
+ label: number;
6
+ }[];
7
+ export interface LogisticModel {
8
+ w: Vec2;
9
+ b: number;
10
+ }
11
+ /** P(class 1) for a point. */
12
+ export declare const predict: (model: LogisticModel, [x, y]: Vec2) => number;
13
+ /**
14
+ * Logistic regression trained by full-batch gradient descent from `start`
15
+ * (default zero weights): the model after each epoch, the start first.
16
+ */
17
+ export declare function trainLogistic(data: {
18
+ point: Vec2;
19
+ label: number;
20
+ }[], epochs: number, rate: number, start?: LogisticModel): LogisticModel[];
21
+ /** Share of points the model puts on the right side of 0.5. */
22
+ export declare function accuracy(model: LogisticModel, data: {
23
+ point: Vec2;
24
+ label: number;
25
+ }[]): number;
26
+ /** Mean cross-entropy loss. */
27
+ export declare function logLoss(model: LogisticModel, data: {
28
+ point: Vec2;
29
+ label: number;
30
+ }[]): number;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Colour scales for heatmaps, as plain functions of 0..1 (clamped):
3
+ * `viridis` (dark blue to yellow, readable in grey), `heat` (dark to orange
4
+ * to pale yellow), `diverging` (blue, white, red; for signed values).
5
+ */
6
+ export type Colormap = 'viridis' | 'heat' | 'diverging';
7
+ export declare const COLORMAPS: readonly Colormap[];
8
+ export declare function colorAt(map: Colormap, t: number): string;
9
+ /**
10
+ * `color` laid over `background` at `amount` (0..1), as one opaque colour.
11
+ * Neighbouring cells drawn this way can overlap without the darker seams
12
+ * that overlapping translucent fills leave.
13
+ */
14
+ export declare function blendOver(color: string, background: string, amount: number): string;
@@ -0,0 +1,15 @@
1
+ import type { Vec2 } from '../linear/vec2';
2
+ /**
3
+ * Level curves of a sampled function by marching squares: for each level,
4
+ * the line segments where the grid crosses it, joined into polylines.
5
+ * `values[j][i]` is f at x = x0 + i·dx, y = y0 + j·dy. Pure.
6
+ */
7
+ export declare function contourLines(values: number[][], x0: number, y0: number, dx: number, dy: number, level: number): Vec2[][];
8
+ /** f sampled on a grid over [x0, x1] × [y0, y1] with `n` + 1 points each way. */
9
+ export declare function sampleGrid(f: (x: number, y: number) => number, [x0, x1]: [number, number], [y0, y1]: [number, number], n: number): {
10
+ values: number[][];
11
+ x0: number;
12
+ y0: number;
13
+ dx: number;
14
+ dy: number;
15
+ };
@@ -0,0 +1,11 @@
1
+ import { type Scope } from '../expr/evaluate';
2
+ import type { Vec2 } from '../linear/vec2';
3
+ /**
4
+ * Gradient descent on f(x, y), with the gradient worked out symbolically:
5
+ * each step moves against the gradient by `rate`, plus `momentum` times the
6
+ * last step. Returns every point visited, the start first. Stops early if a
7
+ * step leaves the real numbers (a rate too large can diverge).
8
+ */
9
+ export declare function descentPath(expr: string, start: Vec2, rate: number, steps: number, momentum?: number, scope?: Scope): Vec2[];
10
+ /** A parsed f(x, y) to evaluate many times. */
11
+ export declare function surface(expr: string): (x: number, y: number, scope?: Scope) => number;
@@ -0,0 +1,11 @@
1
+ import type { Vec2 } from '../linear/vec2';
2
+ /** The centroid each point is nearest to (ties go to the lower index). */
3
+ export declare function assign(points: Vec2[], centroids: Vec2[]): number[];
4
+ /**
5
+ * Lloyd's algorithm from `start` (default the first `k` points), so it is
6
+ * deterministic: the centroids after each iteration, the start first,
7
+ * until they stop moving or `maxIterations` is reached.
8
+ */
9
+ export declare function kmeansHistory(points: Vec2[], k: number, maxIterations?: number, start?: Vec2[]): Vec2[][];
10
+ /** Sum of squared distances from each point to its centroid. */
11
+ export declare function inertia(points: Vec2[], centroids: Vec2[]): number;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * A small fully connected network, for drawing: layer sizes, seeded weights
3
+ * and a forward pass. Pure: the same layers, seed and inputs always give the
4
+ * same weights and activations.
5
+ */
6
+ export type Activation = 'sigmoid' | 'tanh' | 'relu';
7
+ export declare const ACTIVATIONS: readonly Activation[];
8
+ export declare const activate: (kind: Activation, x: number) => number;
9
+ export interface Network {
10
+ layers: number[];
11
+ /** weights[l][j][i]: from node i of layer l to node j of layer l + 1 */
12
+ weights: number[][][];
13
+ /** biases[l][j]: of node j of layer l + 1 */
14
+ biases: number[][];
15
+ }
16
+ /** A network with weights drawn from a seed (normal, scaled by 1/√fan-in). */
17
+ export declare function seededNetwork(layers: number[], seed: number | string): Network;
18
+ /** Every layer's activations for `inputs` (layer 0 is the inputs themselves). */
19
+ export declare function forward(network: Network, inputs: number[], activation: Activation): number[][];
@@ -0,0 +1,50 @@
1
+ import type { MathFigureSpec, MathThemeName } from '../figure/figure-spec';
2
+ import type { Activation } from '../ml/network';
3
+ /**
4
+ * Ready-made AI/ML figures. Each returns a plain MathFigureSpec whose moving
5
+ * part is a number value:
6
+ *
7
+ * - neuralNetworkFigure: `flow` (how far activations have travelled) and inputs `in0`, `in1` …
8
+ * - gradientDescentFigure: `steps`, with `rate` and `momentum`
9
+ * - attentionFigure: no values; animate the heatmap's draw
10
+ * - decisionBoundaryFigure: `epochs`
11
+ * - kmeansFigure: `iteration`
12
+ * - activationFigure: no values
13
+ */
14
+ export interface MlOptions {
15
+ width?: number;
16
+ height?: number;
17
+ theme?: MathThemeName;
18
+ }
19
+ /** A small network; activations flow from the inputs to the outputs as `flow` goes 0 → layers − 1. */
20
+ export declare function neuralNetworkFigure(options?: MlOptions & {
21
+ layers?: number[];
22
+ activation?: Activation;
23
+ inputs?: number[];
24
+ seed?: string;
25
+ }): MathFigureSpec;
26
+ /** Gradient descent on a long, narrow bowl: a small rate crawls, a large one zigzags, momentum speeds it up. */
27
+ export declare function gradientDescentFigure(options?: MlOptions & {
28
+ expr?: string;
29
+ start?: [number, number];
30
+ rate?: number;
31
+ momentum?: number;
32
+ }): MathFigureSpec;
33
+ /** Attention weights between tokens: each row (a query) softmaxed over the columns (the keys). */
34
+ export declare function attentionFigure(options?: MlOptions & {
35
+ tokens?: string[];
36
+ scores?: number[][];
37
+ seed?: string;
38
+ }): MathFigureSpec;
39
+ /** Logistic regression finding the line between two clusters, epoch by epoch. */
40
+ export declare function decisionBoundaryFigure(options?: MlOptions & {
41
+ rate?: number;
42
+ spread?: number;
43
+ }): MathFigureSpec;
44
+ /** k-means finding clusters: points recolour as the centroids move. */
45
+ export declare function kmeansFigure(options?: MlOptions & {
46
+ centres?: [number, number][];
47
+ k?: number;
48
+ }): MathFigureSpec;
49
+ /** The usual activation functions side by side. */
50
+ export declare function activationFigure(options?: MlOptions): MathFigureSpec;
package/llms-full.txt CHANGED
@@ -591,7 +591,7 @@ with a GSAP-style call (durations are in seconds here):
591
591
  ```html
592
592
  <div class="box" style="width:60px;height:60px;background:#4a9eff"></div>
593
593
 
594
- <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.118.0/cdn/tinyfly.iife.js"></script>
594
+ <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.119.1/cdn/tinyfly.iife.js"></script>
595
595
  <script>
596
596
  tinyfly.to('.box', { x: 200, duration: 1 })
597
597
  </script>
@@ -799,7 +799,7 @@ Without a build step, the all-in-one bundle exposes the same functions on a
799
799
  global — `tinyfly.to()`, `tinyfly.timeline()` and so on:
800
800
 
801
801
  ```html
802
- <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.118.0/cdn/tinyfly.iife.js"></script>
802
+ <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.119.1/cdn/tinyfly.iife.js"></script>
803
803
  <script>
804
804
  tinyfly.to('.box', { x: 200, duration: 1 })
805
805
  </script>
@@ -2714,7 +2714,7 @@ For simple website embedding without a build system.
2714
2714
  </html>
2715
2715
  ```
2716
2716
 
2717
- Build the player with `npm run build:player` to generate `lib/player/tinyfly-player.iife.js`, or load it from the CDN: `https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.118.0/cdn/tinyfly-player.iife.js`.
2717
+ Build the player with `npm run build:player` to generate `lib/player/tinyfly-player.iife.js`, or load it from the CDN: `https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.119.1/cdn/tinyfly-player.iife.js`.
2718
2718
 
2719
2719
  ---
2720
2720
 
@@ -7068,7 +7068,7 @@ The dialog shows the generated HTML/JavaScript code with a **Copy Code** button.
7068
7068
  **Steps to embed:**
7069
7069
  1. Build the player: `npm run build:player`
7070
7070
  2. Copy `lib/player/tinyfly-player.iife.js` to your project (or load
7071
- `https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.118.0/cdn/tinyfly-player.iife.js`
7071
+ `https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.119.1/cdn/tinyfly-player.iife.js`
7072
7072
  instead; see [Deployment](DEPLOYMENT.md))
7073
7073
  3. Copy the generated code into your HTML
7074
7074
  4. Adjust the script `src` path if needed
@@ -8497,7 +8497,9 @@ lesson page (`<figure data-tinyfly-math>`), an explorable and a video
8497
8497
  (`histogram`, `distribution`, `galton`, `scatter`, `bayes`) take a distribution as data
8498
8498
  (`{ kind: 'normal', mean: 'mu', sd: 1 }`) and draw seeded samples, never `Math.random`. Discrete:
8499
8499
  `graph` (nodes with `at`, or `tree: { root }`; `search` stepped by `step`), `venn` (`highlight: "(A | B)'"`),
8500
- `clock` (`modulus`, `value`). See `docs/math.md`.
8500
+ `clock` (`modulus`, `value`). AI/ML: `network` (`flow`), `descent` (`steps`, exact gradient),
8501
+ `contours`, `heatmap` (`softmax: true` for attention), `classifier` (`epochs`), `kmeans`
8502
+ (`iteration`); all seeded. See `docs/math.md`.
8501
8503
 
8502
8504
  ## Your own behaviours
8503
8505
 
@@ -8684,7 +8686,7 @@ path for all of that:
8684
8686
  </figure>
8685
8687
 
8686
8688
  <!-- once, anywhere on the page (a site-wide footer is fine) -->
8687
- <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.118.0/cdn/tinyfly-embed.iife.js" data-tinyfly-auto></script>
8689
+ <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.119.1/cdn/tinyfly-embed.iife.js" data-tinyfly-auto></script>
8688
8690
  ```
8689
8691
 
8690
8692
  Every `[data-tinyfly-embed]` mounts when the page is ready, with no per-post
@@ -9098,6 +9100,12 @@ Some names are reserved, because a track on them would move the whole figure:
9098
9100
  | `graph` | `nodes: [{ id, at?, label? }]`, `edges` (`[from, to, weight?]` or objects), `directed?`, `tree?: { root, spacing?, at? }`, `search?: { kind: 'bfs' \| 'dfs' \| 'dijkstra', start }`, `step?`, `frontier?` (screen px), `weights?`, `radius?` |
9099
9101
  | `venn` | `sets` (two or three `{ id, label?, color? }`), `highlight?` (a set expression), `highlightColor?`, `at?`, `radius?`, `universe?` |
9100
9102
  | `clock` | `modulus`, `value`, `at?`, `radius?` |
9103
+ | `network` | `layers` (`[3, 5, 4, 2]`), `activation?: 'sigmoid' \| 'tanh' \| 'relu'`, `inputs?`, `flow?`, `seed?`, `at?`, `size?`, `labels?: { inputs?, outputs? }`, `radius?` |
9104
+ | `heatmap` | `cells` (rows, top first; `softmax?` per row) or `expr` in x and y with `region?`, `resolution?`; `range?`, `colormap?: 'viridis' \| 'heat' \| 'diverging'`, `rowLabels?`, `colLabels?`, `values?`, `at?`, `size?` |
9105
+ | `contours` | `expr` in x and y, `levels?` (a count or the levels), `region?`, `resolution?`, `colormap?` |
9106
+ | `descent` | `expr` in x and y, `start`, `rate`, `steps`, `momentum?` |
9107
+ | `classifier` | `epochs`, `centres?`, `count?`, `spread?`, `rate?`, `start?: [w₁, w₂, b]`, `probability?`, `seed?` |
9108
+ | `kmeans` | `centres` (the true clusters), `iteration`, `k?`, `count?`, `spread?`, `seed?` |
9101
9109
 
9102
9110
  `point` also rides a curve: `{ on: 'sin(x)', x: 'p' }` is the point (p, sin p), and
9103
9111
  `hollow: true` draws an open circle for a hole or a limit. `function` takes
@@ -9125,6 +9133,31 @@ Items work out numbers that TeX can show with `\val{…}`:
9125
9133
  | `bayes` | `ID.prior`, `ID.posterior`, `ID.positive`, `ID.truePositive`, `ID.falsePositive` |
9126
9134
  | `graph` with a search | `ID.visited`, `ID.steps`, and for Dijkstra `ID.d.NODE` (∞ until known) |
9127
9135
  | `clock` | `ID.hour` (value mod modulus), `ID.turns` |
9136
+ | `network` | `ID.out0`, `ID.out1` … (the outputs) |
9137
+ | `descent` | `ID.x`, `ID.y`, `ID.loss`, `ID.step` |
9138
+ | `classifier` | `ID.accuracy`, `ID.loss`, `ID.epoch` |
9139
+ | `kmeans` | `ID.inertia`, `ID.iteration`, `ID.iterations` |
9140
+
9141
+ ### Machine learning
9142
+
9143
+ Everything is seeded and worked out exactly, so a figure trains the same way
9144
+ every time:
9145
+
9146
+ - **Networks** draw seeded weights: blue edges add, red ones subtract, and
9147
+ thicker edges count more. `flow` moves activations layer by layer, with
9148
+ pulses on the edges being fed.
9149
+ - **Descent** takes exact partial derivatives of its expression, so the path
9150
+ follows the true gradient. A step size that diverges stops cleanly.
9151
+ - **Classifiers** train logistic regression by full-batch gradient descent,
9152
+ starting from a deliberately wrong line that visibly turns into place.
9153
+ - **k-means** runs Lloyd's algorithm from the points nearest the middle of the
9154
+ data, so the centroids travel; a fractional `iteration` glides them.
9155
+ - **Heatmaps and contours** colour through a colormap. Dimmed cells are
9156
+ pre-mixed with the background, so neighbours never leave seams. Contours are
9157
+ traced by marching squares and joined into whole curves.
9158
+
9159
+ The pieces are also available on their own: `seededNetwork`, `forward`,
9160
+ `descentPath`, `trainLogistic`, `kmeansHistory`, `contourLines`, `colorAt`.
9128
9161
 
9129
9162
  ### Graphs, searches and sets
9130
9163
 
@@ -9219,7 +9252,7 @@ lesson's step options (`duration`, `easing`, `delay`).
9219
9252
  <figcaption>The determinant is the area of the unit square after the map.</figcaption>
9220
9253
  </figure>
9221
9254
 
9222
- <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.118.0/cdn/tinyfly-math.iife.js" data-tinyfly-auto></script>
9255
+ <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.119.1/cdn/tinyfly-math.iife.js" data-tinyfly-auto></script>
9223
9256
  ```
9224
9257
 
9225
9258
  The figure draws itself into an SVG and redraws from the timeline whenever the
@@ -9330,6 +9363,12 @@ their own.
9330
9363
  | `recursionTreeFigure({ n })` | The call tree of naive recursive Fibonacci, in call order (`step`) |
9331
9364
  | `vennFigure({ sets, highlight, label })` | Two or three sets with a region shaded |
9332
9365
  | `clockFigure({ modulus, value })` | Clock arithmetic (`value`) |
9366
+ | `neuralNetworkFigure({ layers, activation, inputs })` | A forward pass (`flow`, inputs `in0` …) |
9367
+ | `gradientDescentFigure({ expr, start, rate, momentum })` | Descent on a narrow valley over its contours (`steps`, `rate`, `momentum`) |
9368
+ | `attentionFigure({ tokens, scores })` | Attention weights, softmaxed per row, with token labels |
9369
+ | `decisionBoundaryFigure({ rate, spread })` | Logistic regression finding the line between two clusters (`epochs`) |
9370
+ | `kmeansFigure({ centres, k })` | k-means finding clusters (`iteration`) |
9371
+ | `activationFigure()` | Sigmoid, tanh and ReLU |
9333
9372
 
9334
9373
  Each returns a plain figure to change or extend. In each, `M` starts at the
9335
9374
  identity unless `matrix` is given.
@@ -9339,15 +9378,17 @@ identity unless `matrix` is given.
9339
9378
  - Gallery: **Linear Map**, **Eigenvectors**, **Equation Steps**, **Matrix Lesson**,
9340
9379
  **Derivative**, **Riemann Sums**, **Taylor Series**, **Galton Board**, **Central Limit
9341
9380
  Theorem**, **Monte Carlo π**, **Bayes: a Positive Test**, **Graph Search**, **Recursion
9342
- Tree**, **Set Operations** and **Clock Arithmetic**.
9343
- - Videos: `linear-map-short.mjs`, `riemann-short.mjs`, `galton-short.mjs` and
9344
- `graph-search-short.mjs` (9:16); `eigen-explainer.mjs`, `taylor-explainer.mjs`,
9345
- `clt-explainer.mjs` and `de-morgan-explainer.mjs` (16:9), in `examples/headless-video/`.
9381
+ Tree**, **Set Operations**, **Clock Arithmetic**, **Neural Network**, **Gradient Descent**,
9382
+ **Decision Boundary**, **K-Means** and **Attention Weights**.
9383
+ - Videos: `linear-map-short.mjs`, `riemann-short.mjs`, `galton-short.mjs`,
9384
+ `graph-search-short.mjs` and `gradient-descent-short.mjs` (9:16); `eigen-explainer.mjs`,
9385
+ `taylor-explainer.mjs`, `clt-explainer.mjs`, `de-morgan-explainer.mjs` and
9386
+ `neural-network-explainer.mjs` (16:9), in `examples/headless-video/`.
9346
9387
 
9347
9388
  ## Next
9348
9389
 
9349
- AI/ML (networks with flowing activations, gradient descent on a loss surface,
9350
- decision boundaries) builds on the same figure model.
9390
+ Characters can already stand beside a figure in a video; letting them point at
9391
+ named parts of it (a vector's tip, an equation term) is planned. See `todo.md`.
9351
9392
  See `todo.md` for their status.
9352
9393
 
9353
9394
  ---
@@ -10300,8 +10341,8 @@ On a page with no build step, load the maps add-on after the browser bundle; it
10300
10341
  adds to the same `tinyfly` global:
10301
10342
 
10302
10343
  ```html
10303
- <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.118.0/cdn/tinyfly.iife.js"></script>
10304
- <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.118.0/cdn/tinyfly-maps.iife.js"></script>
10344
+ <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.119.1/cdn/tinyfly.iife.js"></script>
10345
+ <script src="https://cdn.jsdelivr.net/gh/algorisys-oss/tinyfly@v0.119.1/cdn/tinyfly-maps.iife.js"></script>
10305
10346
  ```
10306
10347
 
10307
10348
  It is a separate script because the offline world map it carries adds about
@@ -15530,7 +15571,7 @@ magnet.addEventListener('pointerleave', () => {
15530
15571
 
15531
15572
  <!-- capabilities: generated from the library -->
15532
15573
 
15533
- # tinyfly capabilities (v0.118.0)
15574
+ # tinyfly capabilities (v0.119.1)
15534
15575
 
15535
15576
  Generated from the library itself: every name below is accepted, and names not listed are rejected (beat scripts, code panels and `checkTracks` say which name was probably meant).
15536
15577
 
@@ -16020,6 +16061,7 @@ A figure is JSON: a plane and items. Tracks on its target animate values by name
16020
16061
  - `normalFigure, binomialFigure, cltFigure, galtonFigure, monteCarloPiFigure, regressionFigure, bayesFigure`: ready probability and statistics figures
16021
16062
  - `graphSearchFigure, shortestPathFigure, recursionTreeFigure, vennFigure, clockFigure`: ready discrete maths figures; searches move with the value step
16022
16063
  - `searchEvents / parseSetExpression / regionCells`: graph searches as data; set expressions and their Venn cells
16064
+ - `neuralNetworkFigure, gradientDescentFigure, attentionFigure, decisionBoundaryFigure, kmeansFigure, activationFigure`: ready AI/ML figures
16023
16065
  - `distributions`: { kind: normal | uniform | exponential | binomial | poisson | dice | mean, …numbers or value names }; density, meanOf, sdOf, samples (seeded)
16024
16066
  - `layoutTex(tex) / morphEquation(a, b, t)`: the built-in TeX subset, and term-by-term transitions
16025
16067
  - `vec2, mat2`: 2D vectors and 2×2 matrices (apply, multiply, determinant, inverse, eigen)
@@ -16049,6 +16091,12 @@ Items (each has `id`, `kind`, and optional `color`, `draw`, `opacity`):
16049
16091
  - `graph` { nodes, edges, directed?, tree?, search?: { kind: bfs | dfs | dijkstra, start }, step?, frontier? }: searches step by step
16050
16092
  - `venn` { sets (2 or 3), highlight?: set expression like (A | B)' }: shaded by clipping
16051
16093
  - `clock` { modulus, value }: clock arithmetic; \val{ID.hour}
16094
+ - `network` { layers, activation?, inputs?, flow?, seed?, labels? }: a forward pass, layer by layer
16095
+ - `heatmap` { cells (softmax? per row) or expr in x, y; colormap?, rowLabels?, colLabels?, values? }: attention maps, loss fields
16096
+ - `contours` { expr in x, y, levels? }: level curves (marching squares)
16097
+ - `descent` { expr in x, y, start, rate, steps, momentum? }: gradient descent with an exact gradient
16098
+ - `classifier` { epochs, centres?, rate?, start? }: logistic regression training; \val{ID.accuracy}
16099
+ - `kmeans` { centres, iteration, k? }: Lloyd iterations; \val{ID.inertia}
16052
16100
 
16053
16101
  Props a timeline animates:
16054
16102