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.

ResultTable

A table of results: a title, one row per parameter value (a display name and a numeric value), named numeric columns, optional per-cell standard deviations, and a footnote of fixed settings. Renders as aligned text, Markdown, CSV and JSON, and reads CSV and JSON back.

Numbers render with a fixed number of decimals per column (4 by default), so the output is byte-stable; CSV and JSON carry up to 10 decimals with trailing zeros trimmed, so a value survives a round trip to within 1e-10.

Example

t := ResultTable->New("Random forest: trees", "n_estimators");
t->AddColumn("test_accuracy");
t->AddColumn("fit_ms", 1);
t->AddRow("10", 10.0, [0.9412, 12.5]);
t->SetFootnote("max_depth=8; seed=42");
t->ToMarkdown()->PrintLine();
t->Save("rf_trees.csv");

Operations

AddColumn #

Adds a numeric column rendered with 4 decimals. Columns must be added before rows.

method : public : AddColumn(name:String) ~ Nil

Parameters

NameTypeDescription
nameStringcolumn heading

AddColumn #

Adds a numeric column.

method : public : AddColumn(name:String, precision:Int) ~ Nil

Parameters

NameTypeDescription
nameStringcolumn heading
precisionIntdecimals when rendered as text or Markdown

AddColumn #

Adds a numeric column with a number format. The format changes only how ToText and ToMarkdown spell a cell; CSV and JSON values are unchanged. "fixed" is the default (precision decimals); "sci" is scientific notation with precision decimals in the mantissa (1.23e-05); "p" is fixed, but a value from 0 up to 10^-precision is written "<0.0001" (precision 4), so a tiny p-value does not read as 0.0000; "int" rounds to a whole number and writes no decimals (a count), whatever the precision. ToCsv writes a "sci" or "p" column's value below 1e-4 in exponent form with its full digits (1.23e-12) instead of the 10 decimals that would write a tiny p-value as 0; FromCsv reads it back. ToJson keeps its 10 decimals.

method : public : AddColumn(name:String, precision:Int, format:String) ~ Nil

Parameters

NameTypeDescription
nameStringcolumn heading
precisionIntdecimals (mantissa decimals for "sci", the "<" threshold for "p")
formatString"fixed", "sci", "p" or "int"; raises LabError for another name

AddIntegerColumn #

Adds a column of whole numbers (counts), written without decimals.

method : public : AddIntegerColumn(name:String) ~ Nil

Parameters

NameTypeDescription
nameStringcolumn heading

AddPValueColumn #

Adds a column of p-values: 4 decimals, and "<0.0001" below that.

method : public : AddPValueColumn(name:String) ~ Nil

Parameters

NameTypeDescription
nameStringcolumn heading

AddRow #

Adds a row without deviations.

method : public : AddRow(name:String, value:Float, cells:Float[]) ~ Nil

Parameters

NameTypeDescription
nameStringthe parameter value's display name
valueFloatthe parameter's numeric value
cellsFloatone value per column

AddRow #

Adds a row with a standard deviation per cell, from repeated runs.

method : public : AddRow(name:String, value:Float, cells:Float[], stds:Float[]) ~ Nil

Parameters

NameTypeDescription
nameStringthe parameter value's display name
valueFloatthe parameter's numeric value
cellsFloatone mean per column
stdsFloatone standard deviation per column, or Nil for none

AddScientificColumn #

Adds a column in scientific notation.

method : public : AddScientificColumn(name:String, precision:Int) ~ Nil

Parameters

NameTypeDescription
nameStringcolumn heading
precisionIntdecimals of the mantissa

ColumnIndex #

The index of a column by name.

method : public : ColumnIndex(name:String) ~ Int

Parameters

NameTypeDescription
nameStringcolumn heading

Return

TypeDescription
Intthe index, or -1

FormatNumber # function

A number for CSV and JSON: up to 10 decimals, trailing zeros and a trailing point trimmed, never "-0".

function : FormatNumber(value:Float) ~ String

Parameters

NameTypeDescription
valueFloatthe number

Return

TypeDescription
Stringits text

FormatValue # function

A number as ToText and ToMarkdown spell it in a column of the given format (see AddColumn). A value that is not finite is "n/a".

function : FormatValue(value:Float, precision:Int, format:String) ~ String

Parameters

NameTypeDescription
valueFloatthe number
precisionIntdecimals
formatString"fixed", "sci", "p" or "int"; anything else is "fixed"

Return

TypeDescription
Stringthe text

FromCsv # function

Reads a table written by ToCsv. The title and footnote come back empty.

function : FromCsv(text:String) ~ ResultTable

Parameters

NameTypeDescription
textStringCSV text

Return

TypeDescription
ResultTablethe table; raises LabError when the text is not a ToCsv table

FromJson # function

Reads a table written by ToJson.

function : FromJson(text:String) ~ ResultTable

Parameters

NameTypeDescription
textStringJSON text

Return

TypeDescription
ResultTablethe table; raises LabError when the text is not a ToJson table

Get #

A cell.

method : public : Get(row:Int, col:Int) ~ Float

Parameters

NameTypeDescription
rowIntrow index
colIntcolumn index

Return

TypeDescription
Floatthe value (the mean, for repeated runs)

GetColumn #

One column's values, in row order.

method : public : GetColumn(name:String) ~ Float[]

Parameters

NameTypeDescription
nameStringcolumn heading

Return

TypeDescription
Floatone value per row; raises LabError for an unknown column

GetColumnFormat #

The number format of a column.

method : public : GetColumnFormat(name:String) ~ String

Parameters

NameTypeDescription
nameStringcolumn heading

Return

TypeDescription
String"fixed", "sci", "p" or "int"; "" for an unknown column

GetColumnNames #

Column headings, in order.

method : public : GetColumnNames() ~ String[]

Return

TypeDescription
Stringthe numeric columns' names

GetColumnPrecision #

The decimals a column is rendered with.

method : public : GetColumnPrecision(name:String) ~ Int

Parameters

NameTypeDescription
nameStringcolumn heading

Return

TypeDescription
Intthe precision (see AddColumn), -1 for an unknown column

GetColumnStds #

One column's standard deviations, in row order.

method : public : GetColumnStds(name:String) ~ Float[]

Parameters

NameTypeDescription
nameStringcolumn heading

Return

TypeDescription
Floatone deviation per row (zeros when the table holds none); raises LabError for an unknown column

GetFootnote #

The footnote.

method : public : GetFootnote() ~ String

Return

TypeDescription
Stringfootnote text, empty when unset

GetParameter #

The swept parameter's name.

method : public : GetParameter() ~ String

Return

TypeDescription
Stringthe first column's heading

GetRowName #

A row's display name.

method : public : GetRowName(row:Int) ~ String

Parameters

NameTypeDescription
rowIntrow index

Return

TypeDescription
Stringthe name

GetRowNames #

The row names, in row order.

method : public : GetRowNames() ~ String[]

Return

TypeDescription
Stringone name per row

GetRowValue #

A row's numeric parameter value.

method : public : GetRowValue(row:Int) ~ Float

Parameters

NameTypeDescription
rowIntrow index

Return

TypeDescription
Floatthe value

GetRowValues #

The parameter values, in row order: the x axis of a chart.

method : public : GetRowValues() ~ Float[]

Return

TypeDescription
Floatone value per row

GetStd #

A cell's standard deviation.

method : public : GetStd(row:Int, col:Int) ~ Float

Parameters

NameTypeDescription
rowIntrow index
colIntcolumn index

Return

TypeDescription
Floatthe deviation, 0.0 when the table holds none

GetTitle #

The title.

method : public : GetTitle() ~ String

Return

TypeDescription
Stringtitle text

HasStds #

Whether any row carries standard deviations.

method : public : HasStds() ~ Bool

Return

TypeDescription
Booltrue after an AddRow with deviations

IsFinite # function

True when a value is a finite number: neither NaN nor positive or negative infinity. A table cell, a deviation or a chart point that is not finite is "missing": ToText and ToMarkdown write n/a, ToCsv an empty field, ToJson null, and a Chart skips the point.

function : IsFinite(value:Float) ~ Bool

Parameters

NameTypeDescription
valueFloatthe number

Return

TypeDescription
Booltrue for a finite number

New # constructor

Constructor

New(title:String, parameter:String)

Parameters

NameTypeDescription
titleStringshown above the table
parameterStringthe swept parameter's name, the first column's heading

Save #

Writes the table in the form the file extension names: .md Markdown, .csv CSV, .json JSON, anything else the aligned text.

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

Parameters

NameTypeDescription
pathStringfile to write

Return

TypeDescription
Booltrue when written

SetFootnote #

Sets the footnote of fixed settings printed under the table.

method : public : SetFootnote(text:String) ~ Nil

Parameters

NameTypeDescription
textStringthe footnote

Size #

Rows in the table.

method : public : Size() ~ Int

Return

TypeDescription
Introw count

ToChart #

A line chart of named columns against the parameter: x is the parameter value (or the row names as categories when a row name is not its number), one series per metric, error bars from the deviations when the table holds them.

method : public : ToChart(metrics:String[]) ~ Chart

Parameters

NameTypeDescription
metricsStringcolumn names to draw; an empty array draws every column

Return

TypeDescription
Chartthe chart; raises LabError for an unknown column or an empty table

ToChart #

A line chart of named columns, optionally on a log x axis (for C, gamma or a learning rate).

method : public : ToChart(metrics:String[], log_x:Bool) ~ Chart

Parameters

NameTypeDescription
metricsStringcolumn names to draw; an empty array draws every column
log_xBooltrue for a base-10 log x axis

Return

TypeDescription
Chartthe chart; raises LabError for an unknown column or an empty table

ToCsv #

RFC 4180 CSV: a header of the parameter name, "_value", the columns and, when the table holds deviations, "_std" for each; then one record per row. Fields are quoted only when they must be. The title and footnote are not written: a CSV is data, the Markdown and JSON forms carry the prose.

method : public : ToCsv() ~ String

Return

TypeDescription
Stringthe CSV, records ending in LF

ToJson #

JSON, built with Data.JSON: {"title","parameter","footnote","columns":[], "precision":[],"rows":[{"name","value","cells":{column: value}, "stds":{column: deviation}}]}; "stds" is present only when the table holds deviations.

method : public : ToJson() ~ String

Return

TypeDescription
Stringthe JSON text

ToMarkdown #

A GitHub-flavoured Markdown table under a "###" title, the footnote in italics. Deviations render as "mean ± std"; a pipe in a name is escaped.

method : public : ToMarkdown() ~ String

Return

TypeDescription
Stringthe Markdown, lines ending in LF

ToText #

An aligned plain-text table: the title, a header, one line per row, the footnote. Deviations render as "mean +/- std".

method : public : ToText() ~ String

Return

TypeDescription
Stringthe text, lines ending in LF