ModelBase<T, TInput, TOutput>
Base Classes · AiDotNet.Models
Abstract base class for standalone models that directly implement IFullModel.
Implements: IFeatureAware, IFullModel<T, TInput, TOutput>, IGradientComputable<T, TInput, TOutput>, IParameterChunkSource<T>, IParameterManifestProvider
Known derived types: AnomalyDetectorBase<T>, AutoMLEnsembleModel<T>, CenteringMechanism<T>, ConstantQTransform<T>, DocumentReader<T>, ExperienceReplayBuffer<T, TInput, TOutput>, ExpressionTree<T, TInput, TOutput>, FeatureDistillationStrategy<T>, GaussianProcessBase<T>, HistGradientBoostingRegression<T>, InstanceSegmenterBase<T>, KNNEvaluator<T>, LinearEmbeddingModel, LinearVectorModel, MetaLearnerBase<T, TInput, TOutput>, NeckBase<T>, PolicyBase<T>, RelationModule<T>, SafetyModuleBase<T>, SceneTextReader<T>, SelfSupervisedLearningMethodBase<T>, SuperNet<T>, SymbolicPhysicsLearner<T>, VectorModel<T>, VisionTaskModelBase<T>
For Beginners
This is the foundation for building standalone machine learning models. Models like linear regression, expression trees, gradient boosting, and ensembles all inherit from this class. It handles boilerplate like serialization and feature tracking so each model only needs to implement its core prediction and training logic.
How It Works
Provides common infrastructure and sensible defaults for standalone model implementations that are not wrappers around other models. Subclasses must implement core model behavior: prediction, training, parameter management, loss function, and cloning.
Properties
| Property | Summary |
|---|---|
ILossFunction<T> DefaultLossFunction { get; } |
|
ParameterLayoutSnapshot ParameterLayout { get; } |
|
bool SupportsParameterInitialization { get; } |
|
long ParameterCount { get; } |
|
long TrainableParameterCount { get; } |
Gets the number of values the optimizer trains: ParameterCount without buffers and frozen state. |
Methods
| Method | Summary |
|---|---|
Dictionary<string, T> GetFeatureImportance() |
|
IEnumerable<ParameterChunk<T>> GetParameterStateChunks() |
|
IEnumerable<Tensor<T>> GetParameterChunks() |
|
IEnumerable<int> GetActiveFeatureIndices() |
|
IFullModel<T, TInput, TOutput> Clone() |
|
IFullModel<T, TInput, TOutput> DeepCopy() |
|
IFullModel<T, TInput, TOutput> WithParameters(Vector<T> parameters) |
|
ModelMetadata<T> GetModelMetadata() |
|
TOutput Predict(TInput input) |
|
Vector<T> ComputeGradients(TInput input, TOutput target, ILossFunction<T> lossFunction) |
|
Vector<T> GetParameters() |
|
Vector<T> SanitizeParameters(Vector<T> parameters) |
|
bool IsFeatureUsed(int featureIndex) |
|
byte[] Serialize() |
|
void ApplyGradients(Vector<T> gradients, T learningRate) |
|
void Deserialize(byte[] data) |
|
void Dispose() |
|
void LoadModel(string filePath) |
|
void LoadState(Stream stream) |
|
void SaveModel(string filePath) |
|
void SaveState(Stream stream) |
|
void SetActiveFeatureIndices(IEnumerable<int> featureIndices) |
|
void SetParameterChunks(IEnumerable<Tensor<T>> chunks) |
Restores tensor-backed chunks on their device and retains custom-setter semantics. |
void SetParameters(Vector<T> parameters) |
|
void Train(TInput input, TOutput expectedOutput) |
|
void UpdateParameters(Vector<T> parameters) |