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[]) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| name | String | legend entry |
| ys | Float | one height per category |
AddBars #
Adds a bar series with error bars.
method : public : AddBars(name:String, ys:Float[], errs:Float[]) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| name | String | legend entry |
| ys | Float | one height per category |
| errs | Float | half-height of each error bar, one per category |
AddLine #
Adds a line with markers.
method : public : AddLine(name:String, xs:Float[], ys:Float[]) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| name | String | legend entry |
| xs | Float | x values (category indexes when categories are set) |
| ys | Float | y 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[]) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| name | String | legend entry |
| xs | Float | x values |
| ys | Float | y values, one per x |
| errs | Float | half-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) ~ StringParameters
| Name | Type | Description |
|---|---|---|
| text | String | raw text |
Return
| Type | Description |
|---|---|
| String | text 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[,]) ~ ChartParameters
| Name | Type | Description |
|---|---|---|
| title | String | title above the plot |
| names | String | one legend entry per row of losses |
| losses | Float | rows are series, columns are epochs |
Return
| Type | Description |
|---|---|
| Chart | the chart |
New # constructor
Constructor; the default size is 800 x 480.
New(title:String, x_label:String, y_label:String)Parameters
| Name | Type | Description |
|---|---|---|
| title | String | title above the plot |
| x_label | String | x-axis title |
| y_label | String | y-axis title |
NiceStep # function
A 1-2-5 tick step for a range.
function : NiceStep(range:Float, target:Int) ~ FloatParameters
| Name | Type | Description |
|---|---|---|
| range | Float | the axis extent |
| target | Int | roughly how many steps |
Return
| Type | Description |
|---|---|
| Float | the step |
Save #
Writes the SVG to a file.
method : public : Save(path:String) ~ BoolParameters
| Name | Type | Description |
|---|---|---|
| path | String | file to write |
Return
| Type | Description |
|---|---|
| Bool | true 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[]) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| names | String | one 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) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| on | Bool | true for a log axis |
SetSize #
Sets the image size in pixels.
method : public : SetSize(width:Int, height:Int) ~ NilParameters
| Name | Type | Description |
|---|---|---|
| width | Int | width, at least 200 |
| height | Int | height, at least 150 |