Sequential
classin packageklyn.math.nn
public class Sequential<T extends AbstractFloat = Float>
Sequential

Ordered composition of typed layers for classification and regression. Classification consumes Int labels; regression consumes targets in T. Input declarations build the network immediately; otherwise dimensions are inferred on the first fit, evaluate or predict call. Layers are not cloned: keep distinct instances per stage and per independent model. A model is not safe for concurrent training/prediction or parameter mutation. CPU training keeps batches ordered. Sufficiently large matrix products and independent optimizer ranges use shared native workers; small operations remain serial to avoid scheduling overhead. Reductions keep their order. Float16 keeps parameter/activation buffers in FP16, with FP32 matrix accumulation and Adam state. Training scales gradients dynamically and skips non-finite updates before reducing the scale. Optimizer state is not included in the parameter memory reported by summary().

Example

model = Sequential<Float>([Dense<Float>(128), Dense<Float>(10)])

Properties
Modifier and Type Member Description
public readonly property device
device as Device
Concrete device most recently resolved, or auto before resolution.
Constructors
Modifier and Type Member Description
public Sequential
Sequential(layers as IList<Layer<T>>)
Snapshots the order of a non-empty list of layers without copying parameters.
Methods
Modifier and Type Member Description
public compile
compile(optimizer as Optimizer<T>, loss as ClassificationLoss<T>, metrics as IList<String> = ["accuracy"]) as Void
Configures the optimizer and mean classification loss without resetting weights.
public compile
compile(optimizer as Optimizer<T>, loss as RegressionLoss<T>, metrics as IList<String> = []) as Void
Configures a typed floating-target regression objective.
public compile
compile(optimizer as String = "adam", loss as String = "sparse_categorical_crossentropy", metrics as IList<String> = null) as Void
Resolves standard optimizer/loss names to actual typed implementations.
public evaluate
evaluate(notnull features as NDArray<T>, notnull labels as NDArray<Int>, batchSize as Long = 64l) as Evaluation
Evaluates fixed parameters, without shuffling or optimizer updates.
public evaluate
evaluate(notnull features as NDArray<T>, notnull targets as NDArray<T>, batchSize as Long = 64l) as Evaluation
Computes sample-weighted regression loss with fixed parameters and no optimizer updates.
public fit
fit(notnull features as NDArray<T>, notnull labels as NDArray<Int>, epochs as Long = 5l, batchSize as Long = 64l, shuffle as Boolean = true, seed as Long = 12345l, verbose as Int = 1, validationData as Tuple<NDArray<T>, NDArray<Int>> = null) as TrainingHistory
Trains with shuffled minibatches and sample-weighted metrics.
public fit
fit(notnull features as NDArray<T>, notnull targets as NDArray<T>, epochs as Long = 5l, batchSize as Long = 64l, shuffle as Boolean = true, seed as Long = 12345l, verbose as Int = 1, validationData as Tuple<NDArray<T>, NDArray<T>> = null) as TrainingHistory
Trains on same-precision floating targets using the configured regression loss.
public static load
load(filename as String, maxBytes as ULong = 2147483648ul) as Sequential<T>
Restores using a filename; identical to the Path overload.
public static load
load(path as Path, maxBytes as ULong = 2147483648ul) as Sequential<T>
Restores an independent model, including all saved training state.
public loadWeights
loadWeights(filename as String, maxBytes as ULong = 2147483648ul) as Void
Loads weights using a filename.
public loadWeights
loadWeights(path as Path, maxBytes as ULong = 2147483648ul) as Void
Loads parameters transactionally into an identically configured built model.
public predict
predict(notnull features as NDArray<T>) as NDArray<T>
Computes model outputs without applying any implicit output activation.
public save
save(filename as String, includeOptimizer as Boolean = true) as Void
Saves using a filename; identical to the Path overload.
public save
save(path as Path, includeOptimizer as Boolean = true) as Void
Saves architecture, exact parameter bits and optional training state to KNN 1.0.
public summary
summary() as Void
Prints layer names, output shapes, trainable scalar counts and parameter bytes.
public to
to(device as Device) as Sequential<T>
Selects execution without resetting parameters, optimizer state or precision.