Table of Contents

Class GenericModel<TInputData, TPrediction>

Namespace
NeuralNetworks.Models
Assembly
NeuralNetworks.dll

Represents a generic machine learning model that operates on input data of type TInputData and produces predictions of type TPrediction.

public class GenericModel<TInputData, TPrediction> : Model<TInputData, TPrediction> where TInputData : notnull where TPrediction : notnull

Type Parameters

TInputData

The type of input data processed by the model. Must not be null.

TPrediction

The type of prediction output produced by the model. Must not be null.

Inheritance
Model<TInputData, TPrediction>
GenericModel<TInputData, TPrediction>
Inherited Members

Remarks

This class provides a flexible base for building models with customizable input and prediction types. It is typically used in scenarios where the data and prediction formats are determined by the application domain. The layer list builder and loss function are provided during construction to define the model's architecture. This class is generally not intended to be subclassed. Example of creating a generic model for float[,] input and output:

model = new GenericModel<float[,], float[,]>(
       layerListBuilder: LayerListBuilder<float[,], float[,]>
                .AddLayer(new DenseLayer(4, new Sigmoid(), new GlorotInitializer(commonRandom)))
                .AddLayer(new DenseLayer(1, new Linear(), new GlorotInitializer(commonRandom))),
       lossFunction: new MeanSquaredError(),
       random: commonRandom);

Constructors

GenericModel(LayerListBuilder<TInputData, TPrediction>, Loss<TPrediction>, SeededRandom?)

Initializes a new instance of the GenericModel class with the specified layer configuration, loss function, and optional random seed.

public GenericModel(LayerListBuilder<TInputData, TPrediction> layerListBuilder, Loss<TPrediction> lossFunction, SeededRandom? random)

Parameters

layerListBuilder LayerListBuilder<TInputData, TPrediction>

The builder that defines the sequence and configuration of layers for the model. Must not be null.

lossFunction Loss<TPrediction>

The loss function used to evaluate prediction accuracy during training. Must not be null.

random SeededRandom

An optional seeded random number generator used for reproducible initialization. If null, a default random generator is used.

Remarks

Example of creating a generic model for float[,] input and output:
model = new GenericModel<float[,], float[,]>(
       layerListBuilder: LayerListBuilder<float[,], float[,]>
                .AddLayer(new DenseLayer(4, new Sigmoid(), new GlorotInitializer(commonRandom)))
                .AddLayer(new DenseLayer(1, new Linear(), new GlorotInitializer(commonRandom))),
       lossFunction: new MeanSquaredError(),
       random: commonRandom);

Methods

CreateLayerListBuilderInternal()

protected override LayerListBuilder<TInputData, TPrediction> CreateLayerListBuilderInternal()

Returns

LayerListBuilder<TInputData, TPrediction>