Browse documentation
aner.data · Reference

AdaptiveFrame

Native immutable typed observations with stable row identities, declared groups, field roles, exact populations and bounded model input packing.

Implemented

AdaptiveFrame is a native immutable view over a collected typed table. It preserves observation identity, declared groups, field roles, ordered feature meaning and fitted preprocessing dependencies through the supported transformations. Import aner.data. The frame adapter provides explicit conversion and population contracts over the table engine’s memory or disk storage.

The practical starting point is building energy regression: several rows represent each building, preprocessing learns only from training buildings, and predictions retain the original observation IDs. A plain numerical matrix cannot express those population and field contracts by itself.

Return to the aner.data module guide for strict CSV schemas, DataTable access and materialization budgets. This page documents observation aware values exposed by the same first level aner.data import. Fitted preprocessing and regression APIs belong to aner.ml.

Run the complete basic frame example

After installation, run from the bundle folder containing examples. The program uses the included synthetic energy fixture; keep the same relative fixture path if downloading the source.

sh
aner check examples/data_frames.aner
aner run examples/data_frames.aner
aner
// Synthetic building observations: keep group membership and observation identity.
// Run from the directory containing examples/fixtures/contextual/energy.csv.
import aner.data
import aner.tensor

var schema = data.schema()
schema = data.column(schema, "row_id", "Int64", false)
schema = data.column(schema, "building_id", "String", false)
schema = data.column(schema, "temperature", "Float64", false)
schema = data.column(schema, "occupancy", "Float64", false)
schema = data.column(schema, "energy", "Float64", false)
let table = data.collect(data.scan_csv("examples/fixtures/contextual/energy.csv", schema, "NA"),
    max_rows: 16, max_bytes: 1048576, batch_rows: 4)
let observations = data.frame(table, "row_id", "building_id", "energy",
    List("", "", "degC", "1", "kWh"))
let populations = observations.partition_groups(
    List("B0", "B1", "B2", "B3"), List("B4", "B5"), List("B6", "B7"))
print("Training, validation and test rows")
print(populations.train().rows())
print(populations.validation().rows())
print(populations.test().rows())
print("Training population role")
print(populations.train().role())
print("Numerical features exclude identity, grouping and target")
print(populations.train().features().cols())
let validation = populations.validation().batch(max_output_bytes: 1048576, copy: "allow")
print("First validation observation ID and target unit")
print(validation.row_id(0))
print(validation.targets().unit())
print("First validation temperature")
print(validation.inputs().value(0, 0))

Expected output:

text
Training, validation and test rows
8
4
4
Training population role
training
Numerical features exclude identity, grouping and target
2
First validation observation ID and target unit
401
kWh
First validation temperature
18.0

Each building's two observations remain in one population. Identity, grouping and target columns stay outside the two numerical input features; the packed validation batch retains observation ID 401 and the declared energy target unit. The full regression application extends this preparation through fitting, evaluation and checkpoint restoration.

Construction and field roles

data.frame(table, row_id, group, target, units) adopts an existing immutable DataTable. The identity column is a unique nonmissing Int64, the optional grouping column is a nonmissing String, and the target is a numeric column. Empty identity or grouping names select the documented generated identity or no grouping behavior. Units are explicit declarations in table column order; they do not validate how the observations were measured.

The four argument overload adopts native physical units from a typed table; primitive table columns have no physical unit. Explicit declarations cannot conflict with a native unit. a nonempty units List in the five argument overload requires one unit String for every source column in order. An empty row_id generates zero based Int64 observation IDs; an empty group omits grouping and cannot be used with partition_groups. A nonempty target must name an Int64 or Float64 field and cannot also be the identity/group field. An empty target declares unlabeled observations with no target storage. Frame construction permits missing numeric values, while packing a batch rejects missing required inputs or observed targets explicitly. Independent prediction requires explicit inference alignment; alignment cannot grant a training role. Unlabeled batch target readout, fitting and RMSE reject.

Identity, grouping and target fields are excluded from numerical input features automatically. Rename preserves a field's identity and role. Selecting a target under a new name does not turn it into a training feature. A heterogeneous feature matrix retains an ordered feature schema; its original columns are not assigned one shared physical unit.

Selection and declared populations

Projection, slicing and gathering apply one selection to the values and their row identities. Native snapshots and their context are immutable; copies share retained state. Array position and stable source observation identity remain different concepts.

data.partition_groups accepts exact training, validation and test group lists. The manifest must cover the eligible groups once: missing, duplicated or multiply assigned groups fail. Training must be nonempty and at least one held out population must be declared. Validation or test can be empty; its view reports zero rows, and fitting or numerical packing of an empty view fails. Each partition creates its own trusted experiment scope. Matching group names or identical numeric values do not authorize reuse across a separately created scope.

Training only fitting is enforced at supported model and fitted preprocessing boundaries. Transformation preserves the input population role and retains the learned artifact's fit dependencies. These checks apply to declared, tracked observations; manually reconstructed scalar values cannot recover the original fit authorization.

Explicit numerical batches

data.batch(frame, max_output_bytes, copy) creates a packed native model batch with ordered inputs, target, original row IDs and preserved fit dependencies. Separate table columns require allocation for row major packing. copy: "forbid" therefore fails before packing instead of silently copying. The copy report identifies the packed numerical allocation and preserved context.

Missing required inputs or targets fail in this first adapter. No imputation, row dropping or masked loss rule is inferred. Batch reports distinguish copied_bytes, new_numeric_bytes, shared_row_selection_bytes and budgeted_payload_bytes; descriptor and allocator overhead and process RSS are excluded. Batch shuffle applies one permutation to inputs, targets and IDs together. Raw numerical export is an explicit boundary requiring acknowledgement of context loss; ordinary model input should keep the contextual batch.

Selection, batch and identity accessor details

select(fields) takes a nonempty List of unique existing field name Strings and preserves their specified order. features() returns numeric input fields, excluding identity, grouping and target roles; it requires at least one eligible field. rename(from, to) preserves the field's native identity and role and rejects a conflicting existing name. filter(condition) resolves the same reusable column conditions as scans and tables against the current visible field names. Renamed fields use their new names, unselected fields are unavailable, and transformed fields use their current values. Filtering retains the current row order and exact observation IDs, including repeated identities in a gathered view. It shares immutable source and override storage; an all matching filter also shares the existing selection. An empty result remains inspectable, while numerical packing and fitting still reject an empty population.

slice(start, stop) uses a nonempty zero based half open interval; gather_rows(indices) uses a nonempty List of in range Int64 row positions. Repeating a position repeats that observation rather than inventing a new ID.

A filtered frame preserves field identity, field roles, units, population role, the trusted experiment scope, learned dependencies, applied preprocessing and scientific operation history. Filtering a validation view cannot turn it into training data or authorize a new fit scope. Standardized fields have unit "1" and accept primitive numeric conditions. Condition evaluation uses the contextual runtime’s existing 64 MiB scratch limit; frame construction still limits a root to 1,000,000 rows and 64 fields. Primitive Int64 filters remain exact across the full Int64 range. Existing nontrivial physical unit declarations on primitive Int64 frame fields require an exact Float64 magnitude within ±2^53; larger physical magnitudes fail with E_NUMERIC. Native physical table columns already use Float64 storage. Physical annotations on nonnumeric fields cannot be used as valid physical filter fields. These frame limits are separate from the flexible streaming table engine. See condition types, exact comparisons and missing semantics.

rows, cols, column_name, column_unit and row_id inspect the selected view. Column and row indices are zero based; row_id(index) returns the exact retained Int64 observation ID. row_ids() exports a managed List and can fail its independent bounded export budget; use indexed row_id for larger views. role() reports the native population role. summary()/explain() return bounded descriptive Strings for frames, partitions and batches rather than printing those opaque values directly.

batch(max_output_bytes) defaults to allowing a copy; the explicit copy argument is exactly "allow" or "forbid". inputs() and targets() return SemanticTensor facades, not plain Tensor values. Inputs retain the ordered heterogeneous feature schema; targets retain their declared target unit. shuffle(seed: Int64) returns a newly permuted ContextBatch with inputs, targets and row IDs aligned; it does not mutate the original batch or source frame.

Contextual runtime failures use R3501 with codes such as E_ROW_DOMAIN for invalid row identity/selection, E_FEATURE_SCHEMA for incompatible field declarations, E_MISSING_POLICY for required missing observations, E_FIT_SCOPE for invalid group/population authorization, E_CONTEXT_LOSS for unsupported context changes, or E_RESOURCE_BUDGET/E_MATERIALIZATION_BUDGET for bounded allocations and List exports. The full application includes intentional fitting on test and copy forbidden failures. Wrong static types and missing imports are caught by aner check.

Native API signatures

Qualified functions and the corresponding recognized receiver methods use the same native contracts. self denotes the receiver in the qualified signature. Lists of names or units contain Strings; index lists contain Int64 values. Wrong List element types fail instead of coercing values.

Native signatureResult
data.frame(table: DataTable, row_id: String, group: String, target: String, units: List)AdaptiveFrame
data.frame(table: DataTable, row_id: String, group: String, target: String)AdaptiveFrame
data.filter(self: AdaptiveFrame, condition: DataCondition)AdaptiveFrame
data.select(self: AdaptiveFrame, columns: List)AdaptiveFrame
data.features(self: AdaptiveFrame)AdaptiveFrame
data.rename(self: AdaptiveFrame, from: String, to: String)AdaptiveFrame
data.gather_rows(self: AdaptiveFrame, indices: List)AdaptiveFrame
data.slice(self: AdaptiveFrame, start: Int64, stop: Int64)AdaptiveFrame
data.rows(self: AdaptiveFrame)Int64
data.cols(self: AdaptiveFrame)Int64
data.column_name(self: AdaptiveFrame, column: Int64)String
data.column_unit(self: AdaptiveFrame, column: Int64)String
data.role(self: AdaptiveFrame)String
data.partition_groups(self: AdaptiveFrame, train: List, validation: List, test: List)FramePartition
data.train(self: FramePartition)AdaptiveFrame
data.validation(self: FramePartition)AdaptiveFrame
data.test(self: FramePartition)AdaptiveFrame
data.batch(self: AdaptiveFrame, max_output_bytes: Int64)ContextBatch
data.batch(self: AdaptiveFrame, max_output_bytes: Int64, copy: String)ContextBatch
data.shuffle(self: ContextBatch, seed: Int64)ContextBatch
data.inputs(self: ContextBatch)SemanticTensor
data.targets(self: ContextBatch)SemanticTensor
data.row_ids(self: AdaptiveFrame)List
data.row_id(self: AdaptiveFrame, index: Int64)Int64
data.row_ids(self: ContextBatch)List
data.row_id(self: ContextBatch, index: Int64)Int64
data.summary(self: AdaptiveFrame)String
data.explain(self: AdaptiveFrame)String
data.summary(self: FramePartition)String
data.explain(self: FramePartition)String
data.summary(self: ContextBatch)String
data.explain(self: ContextBatch)String
data.column_type(self: DataTable, column: Int64)String
data.column_nullable(self: DataTable, column: Int64)Bool

Time and space complexity

Let N be source rows, n selected rows, p input features, c source columns, k selected columns and g distinct declared groups. Let h represent the retained dependency descriptors and m gathered rows. String and identifier byte lengths add their own scan or copy cost.

OperationTimeAdditional space
Adopt a table and validate identity/schemaExpected O(N + c)O(N + c) identity and schema descriptors; retained table storage is shared
Project fieldsO(c + kc + k log(k + 1) + h)O(c + k + h) descriptors; row selection and table storage are shared
Slice/gather selected rowsO(m + c + h)O(m + c + h) selected row indices and descriptors; source storage is shared
Exact group manifestO(n log n + n log(g + 1) + g log(g + 1) + h)O(n + g + h) membership and selection metadata
Pack one numerical batchO(np)O(np + n) inputs, target and exported row IDs, plus descriptors
Shuffle a packed batchO(np)O(np + n) aligned outputs and permutation

The current frame admits at most 1,000,000 source rows and 64 fields. Numerical packing admits at most 1,000,000 cells and a checked 64 MiB managed payload. Semantic model input facades additionally admit at most 65,536 row coordinates; a large underlying batch does not bypass that semantic limit. Exact Int64 IDs are available through row_id(index) or a bounded managed List export.

The numerical payload budget is not a global process RSS quota. It does not release the source table, fitted artifacts or other live values. Resource bounds and conversion reports must be considered with the existing typed CSV and Tensor limits.

Dependencies, backends and limitations

The implementation is native C++ and needs no external service. CSV loading follows the existing strict schema and missing token rules. The complete example uses CPU Float64 batch preparation and regression; a compatible development engine and VS Code helper 0.1.38 or newer are required. A normal CPU build does not require accelerator libraries.

Automatic dense/sparse layout selection, joins, sparse storage, out of core spilling, streaming windows and graph views remain future functionality. Existing accelerator and parallel APIs do not make this frame's transformations distributed automatically. See FeatureLedger for fitting, artifact persistence and guarantee boundaries.

Aner documentation · Reference and guides