LinearVectorModel

Models & Types ยท AiDotNet.MetaLearning.Models

A simple linear model mapping Matrix input to Vector output, useful for meta-learning examples and testing.

Inheritance: ModelBase<double, Matrix<double>, Vector<double>> โ†’ LinearVectorModel

Implements: ICloneable, IGeneratedParameterRegistrar<double>

For Beginners

This is a simple linear model used mainly for testing and demonstrating meta-learning algorithms. It takes a matrix of inputs and produces predictions using a straightforward linear formula (y = inputs * weights + bias). Its simplicity makes it ideal for verifying that meta-learning algorithms like MAML work correctly before scaling up to more complex models.

How It Works

Computes y = X * w + b where w is a weight vector and b is a bias scalar. Provides gradient computation via MSE loss for use with gradient-based meta-learners.

Example

using AiDotNet.MetaLearning.Models;
// Create a simple linear model for meta-learning testing
var input = new Matrix<double>(10, 5);  // 10 samples, 5 features
var labels = new Vector<double>(10);
var result = new AiModelBuilder<double, Matrix<double>, Vector<double>>()
    .ConfigureModel(new LinearVectorModel(inputDim: 5, learningRate: 0.01))
    .Build(input, labels);
Vector<double> predictions = result.Predict(input);

Constructors

Constructor Summary
LinearVectorModel(int inputDim, double learningRate) Creates a new linear model with the given input dimension.

Properties

Property Summary
ILossFunction<double> DefaultLossFunction { get; }

Methods

Method Summary
Dictionary<string, double> GetFeatureImportance()
IEnumerable<int> GetActiveFeatureIndices()
IFullModel<double, Matrix<double>, Vector<double>> WithParameters(Vector<double> parameters)
ModelMetadata<double> GetModelMetadata()
Vector<double> ComputeGradients(Matrix<double> input, Vector<double> target, ILossFunction<double> lossFunction)
Vector<double> Predict(Matrix<double> input)
bool IsFeatureUsed(int featureIndex)
void ApplyGradients(Vector<double> gradients, double learningRate)
void LoadModel(string filePath)
void LoadState(Stream stream)
void SaveModel(string filePath)
void SaveState(Stream stream)
void SetActiveFeatureIndices(IEnumerable<int> featureIndices)
void Train(Matrix<double> input, Vector<double> expectedOutput)