v2026.11.2
All Bundles
Bundle

Experiment support for a parameter sweep: a deterministic stratified hold-out split, class-ratio resampling of the training half against a fixed test set, a wall-clock stopwatch and label helpers. Compile with -lib ml,ml_lab,csv,json, or with the ai alias group. Design: docs/ML_LAB_SUPPORT_DESIGN.md.

Chart

A chart written as standalone SVG 1.1: a line chart (x numeric, linear or log, or categorical) with markers and error bars, or a grouped bar chart, with a title, axis titles, a 1-2-5 tick grid and a legend. No script, no external font, no dependency: it opens in a browser, pastes into Word, and converts with any SVG tool. Coordinates are written with one decimal, so the same data gives the same bytes on every platform.

Example

c := Chart->New("Recall vs C", "C", "recall");
c->SetLogX(true);
c->AddLine("rbf", cs, recall_rbf, recall_rbf_std);
c->AddLine("linear", cs, recall_lin);
c->Save("recall_vs_c.svg");

Operations

AddBars #

Adds a bar series over the categories: one bar per category, grouped with the other bar series. SetCategories must have been called.

method : public : AddBars(name:String, ys:Float[]) ~ Nil

Parameters

NameTypeDescription
nameStringlegend entry
ysFloatone height per category

AddBars #

Adds a bar series with error bars.

method : public : AddBars(name:String, ys:Float[], errs:Float[]) ~ Nil

Parameters

NameTypeDescription
nameStringlegend entry
ysFloatone height per category
errsFloathalf-height of each error bar, one per category

AddLine #

Adds a line with markers.

method : public : AddLine(name:String, xs:Float[], ys:Float[]) ~ Nil

Parameters

NameTypeDescription
nameStringlegend entry
xsFloatx values (category indexes when categories are set)
ysFloaty values, one per x

AddLine #

Adds a line with markers and symmetric error bars.

method : public : AddLine(name:String, xs:Float[], ys:Float[], errs:Float[]) ~ Nil

Parameters

NameTypeDescription
nameStringlegend entry
xsFloatx values
ysFloaty values, one per x
errsFloathalf-height of each error bar, one per point; 0 draws none

Escape # function

XML-escapes text for an SVG element or attribute.

function : Escape(text:String) ~ String

Parameters

NameTypeDescription
textStringraw text

Return

TypeDescription
Stringtext with the five XML special characters escaped

LossCurve # function

A training-loss chart: one line per series (one per learning rate, say), x is the epoch starting at 1.

function : LossCurve(title:String, names:String[], losses:Float[,]) ~ Chart

Parameters

NameTypeDescription
titleStringtitle above the plot
namesStringone legend entry per row of losses
lossesFloatrows are series, columns are epochs

Return

TypeDescription
Chartthe chart

New # constructor

Constructor; the default size is 800 x 480.

New(title:String, x_label:String, y_label:String)

Parameters

NameTypeDescription
titleStringtitle above the plot
x_labelStringx-axis title
y_labelStringy-axis title

NiceStep # function

A 1-2-5 tick step for a range.

function : NiceStep(range:Float, target:Int) ~ Float

Parameters

NameTypeDescription
rangeFloatthe axis extent
targetIntroughly how many steps

Return

TypeDescription
Floatthe step

Save #

Writes the SVG to a file.

method : public : Save(path:String) ~ Bool

Parameters

NameTypeDescription
pathStringfile to write

Return

TypeDescription
Booltrue when written

SetCategories #

Makes x categorical: ticks are these names at positions 0, 1, 2, ..., and bar series are grouped by them.

method : public : SetCategories(names:String[]) ~ Nil

Parameters

NameTypeDescription
namesStringone per category

SetLogX #

Draws x on a base-10 log scale, for C, gamma or a learning rate. Every x must then be positive.

method : public : SetLogX(on:Bool) ~ Nil

Parameters

NameTypeDescription
onBooltrue for a log axis

SetSize #

Sets the image size in pixels.

method : public : SetSize(width:Int, height:Int) ~ Nil

Parameters

NameTypeDescription
widthIntwidth, at least 200
heightIntheight, at least 150

SetYRange #

Fixes the y range instead of deriving it from the data.

method : public : SetYRange(min:Float, max:Float) ~ Nil

Parameters

NameTypeDescription
minFloatbottom of the axis
maxFloattop of the axis, above min

Size #

Series added so far.

method : public : Size() ~ Int

Return

TypeDescription
Intseries count

ToSvg #

Renders the chart.

method : public : ToSvg() ~ String

Return

TypeDescription
StringSVG 1.1 text; raises LabError when there is nothing to draw or a log axis meets a non-positive x