Table of Contents

Class NonLinearRegressionBase<T>

Namespace
AiDotNet.Regression
Assembly
AiDotNet.dll

Base class for non-linear regression algorithms that provides common functionality for training and prediction.

public abstract class NonLinearRegressionBase<T> : INonLinearRegression<T>, IRegression<T>, IFullModel<T, Matrix<T>, Vector<T>>, IModel<Matrix<T>, Vector<T>, ModelMetadata<T>>, IModelSerializer, ICheckpointableModel, IParameterizable<T, Matrix<T>, Vector<T>>, IFeatureAware, IFeatureImportance<T>, ICloneable<IFullModel<T, Matrix<T>, Vector<T>>>, IGradientComputable<T, Matrix<T>, Vector<T>>, IJitCompilable<T>

Type Parameters

T

The numeric data type used for calculations (e.g., float, double).

Inheritance
NonLinearRegressionBase<T>
Implements
IFullModel<T, Matrix<T>, Vector<T>>
IModel<Matrix<T>, Vector<T>, ModelMetadata<T>>
IParameterizable<T, Matrix<T>, Vector<T>>
ICloneable<IFullModel<T, Matrix<T>, Vector<T>>>
IGradientComputable<T, Matrix<T>, Vector<T>>
Derived
Inherited Members
Extension Methods

Remarks

This abstract class implements core functionality shared by different non-linear regression algorithms, including kernel functions, regularization, and model serialization/deserialization.

Non-linear regression models can capture complex relationships in data that linear models cannot represent. They typically use kernel functions to transform the input space into a higher-dimensional feature space where the relationship becomes linear.

For Beginners: Non-linear regression is used when your data doesn't follow a straight line pattern. These models can capture curved or complex relationships between your input features and target values. Think of it like having a flexible curve that can bend and shape itself to fit your data points, rather than just a straight line.

Constructors

NonLinearRegressionBase(NonLinearRegressionOptions?, IRegularization<T, Matrix<T>, Vector<T>>?, ILossFunction<T>?)

Initializes a new instance of the NonLinearRegressionBase class with the specified options and regularization.

protected NonLinearRegressionBase(NonLinearRegressionOptions? options = null, IRegularization<T, Matrix<T>, Vector<T>>? regularization = null, ILossFunction<T>? lossFunction = null)

Parameters

options NonLinearRegressionOptions

Configuration options for the non-linear regression model. If null, default options will be used.

regularization IRegularization<T, Matrix<T>, Vector<T>>

Regularization method to prevent overfitting. If null, no regularization will be applied.

lossFunction ILossFunction<T>

Loss function for gradient computation. If null, defaults to Mean Squared Error.

Remarks

The constructor initializes the model with default values and prepares it for training.

For Beginners: This constructor sets up the model with either the options you provide or default settings. It's like setting up a new tool before you start using it - you're configuring how it will work before you actually train it with data. The loss function determines how prediction errors are measured during training.

Properties

Alphas

Gets or sets the alpha coefficients for each support vector.

protected Vector<T> Alphas { get; set; }

Property Value

Vector<T>

A vector of coefficients that determine the influence of each support vector on predictions.

Remarks

For Beginners: Alpha coefficients determine how much influence each support vector has on the final prediction. Larger alpha values mean that support vector has a stronger effect on the prediction.

B

Gets or sets the bias term (intercept) of the model.

protected T B { get; set; }

Property Value

T

A scalar value that represents the offset from the origin.

Remarks

For Beginners: The bias term (sometimes called the intercept) is like a baseline value for predictions. It shifts the entire model up or down to better fit the data. Without a bias term, all predictions would have to pass through the origin (0,0).

DefaultLossFunction

Gets the default loss function used by this model for gradient computation.

public virtual ILossFunction<T> DefaultLossFunction { get; }

Property Value

ILossFunction<T>

Remarks

This loss function is used when calling ComputeGradients(TInput, TOutput, ILossFunction<T>?) without explicitly providing a loss function. It represents the model's primary training objective.

For Beginners: The loss function tells the model "what counts as a mistake". For example: - For regression (predicting numbers): Mean Squared Error measures how far predictions are from actual values - For classification (predicting categories): Cross Entropy measures how confident the model is in the right category

This property provides a sensible default so you don't have to specify the loss function every time, but you can still override it if needed for special cases.

Distributed Training: In distributed training, all workers use the same loss function to ensure consistent gradient computation. The default loss function is automatically used when workers compute local gradients.

Exceptions

InvalidOperationException

Thrown if accessed before the model has been configured with a loss function.

Engine

Gets the global execution engine for vector operations.

protected IEngine Engine { get; }

Property Value

IEngine

FeatureNames

Gets or sets the feature names.

public string[]? FeatureNames { get; set; }

Property Value

string[]

An array of feature names. If not set, feature indices will be used as names.

NumOps

Gets the numeric operations provider for the specified type T.

protected INumericOperations<T> NumOps { get; }

Property Value

INumericOperations<T>

An object that provides mathematical operations for the numeric type T.

Remarks

For Beginners: This property provides a way to perform math operations (like addition, multiplication, etc.) on the generic type T. It allows the algorithm to work with different numeric types (float, double, decimal) without changing the core logic.

Options

Gets the configuration options for the non-linear regression model.

protected NonLinearRegressionOptions Options { get; }

Property Value

NonLinearRegressionOptions

Contains settings like kernel type, regularization parameters, and optimization parameters.

Remarks

For Beginners: These are the settings that control how the model behaves. They include choices like what type of mathematical function (kernel) to use and how to prevent the model from memorizing the training data instead of learning general patterns (regularization).

ParameterCount

Gets the number of parameters in the model.

public virtual int ParameterCount { get; }

Property Value

int

Remarks

This property returns the total count of trainable parameters in the model. It's useful for understanding model complexity and memory requirements.

Regularization

Gets the regularization method used to prevent overfitting.

protected IRegularization<T, Matrix<T>, Vector<T>> Regularization { get; }

Property Value

IRegularization<T, Matrix<T>, Vector<T>>

An implementation of the IRegularization interface that determines how model complexity is penalized.

Remarks

For Beginners: Regularization helps prevent "overfitting," which is when a model learns the training data too well and performs poorly on new data. It's like adding a penalty for complexity, encouraging the model to find simpler solutions that generalize better to new examples.

SupportVectors

Gets or sets the support vectors used by the model.

protected Matrix<T> SupportVectors { get; set; }

Property Value

Matrix<T>

A matrix where each row represents a support vector (a subset of the training examples that define the model).

Remarks

For Beginners: Support vectors are the key training examples that define the model's decision boundary. Instead of using all training data points, many non-linear models only need to remember a subset of them (the "support vectors") to make predictions. This makes the model more efficient and often helps it generalize better to new data.

SupportsJitCompilation

Gets whether this model currently supports JIT compilation.

public virtual bool SupportsJitCompilation { get; }

Property Value

bool

True if the model can be JIT compiled, false otherwise.

Remarks

Some models may not support JIT compilation due to: - Dynamic graph structure (changes based on input) - Lack of computation graph representation - Use of operations not yet supported by the JIT compiler

For Beginners: This tells you whether this specific model can benefit from JIT compilation.

Models return false if they:

  • Use layer-based architecture without graph export (e.g., current neural networks)
  • Have control flow that changes based on input data
  • Use operations the JIT compiler doesn't understand yet

In these cases, the model will still work normally, just without JIT acceleration.

Methods

ApplyGradients(Vector<T>, T)

Applies pre-computed gradients to update the model parameters.

public virtual void ApplyGradients(Vector<T> gradients, T learningRate)

Parameters

gradients Vector<T>

The gradient vector to apply.

learningRate T

The learning rate for the update.

Remarks

Updates parameters using: θ = θ - learningRate * gradients

For Beginners: After computing gradients (seeing which direction to move), this method actually moves the model in that direction. The learning rate controls how big of a step to take.

Distributed Training: In DDP/ZeRO-2, this applies the synchronized (averaged) gradients after communication across workers. Each worker applies the same averaged gradients to keep parameters consistent.

Clip(T, T, T)

Clips a value to be within the specified range.

protected T Clip(T value, T low, T high)

Parameters

value T

The value to clip.

low T

The lower bound of the range.

high T

The upper bound of the range.

Returns

T

The clipped value.

Remarks

This method ensures that a value is within the specified range by returning the lower bound if the value is less than the lower bound, the upper bound if the value is greater than the upper bound, or the value itself if it is within the range.

For Beginners: Clipping is a simple way to ensure a value stays within a certain range. It's like setting minimum and maximum limits. If the value is below the minimum, it's raised to the minimum. If it's above the maximum, it's lowered to the maximum. Otherwise, it stays as is. This is often used during optimization to keep parameters within valid bounds.

Clone()

Creates a shallow copy of the model.

public virtual IFullModel<T, Matrix<T>, Vector<T>> Clone()

Returns

IFullModel<T, Matrix<T>, Vector<T>>

A new model instance that is a shallow copy of the current model.

Remarks

This method creates a new instance of the model that shares references to the same internal data structures as the original model. This is primarily used internally by other methods that need to create modified copies of the model.

For Beginners: This method creates a lightweight copy of your model. Unlike DeepCopy, which creates completely independent copies of everything, this method creates a new model object but may share some internal data with the original. This makes it faster to create copies, but changes to one copy might affect others in some cases. This is primarily used internally by other methods rather than directly by users.

ComputeGradients(Matrix<T>, Vector<T>, ILossFunction<T>?)

Computes gradients of the loss function with respect to model parameters for the given data, WITHOUT updating the model parameters.

public virtual Vector<T> ComputeGradients(Matrix<T> input, Vector<T> target, ILossFunction<T>? lossFunction = null)

Parameters

input Matrix<T>

The input data.

target Vector<T>

The target/expected output.

lossFunction ILossFunction<T>

The loss function to use for gradient computation. If null, uses the model's default loss function.

Returns

Vector<T>

A vector containing gradients with respect to all model parameters.

Remarks

This method performs a forward pass, computes the loss, and back-propagates to compute gradients, but does NOT update the model's parameters. The parameters remain unchanged after this call.

Distributed Training: In DDP/ZeRO-2, each worker calls this to compute local gradients on its data batch. These gradients are then synchronized (averaged) across workers before applying updates. This ensures all workers compute the same parameter updates despite having different data.

For Meta-Learning: After adapting a model on a support set, you can use this method to compute gradients on the query set. These gradients become the meta-gradients for updating the meta-parameters.

For Beginners: Think of this as "dry run" training: - The model sees what direction it should move (the gradients) - But it doesn't actually move (parameters stay the same) - You get to decide what to do with this information (average with others, inspect, modify, etc.)

Exceptions

InvalidOperationException

If lossFunction is null and the model has no default loss function.

CreateInstance()

Creates a new instance of the derived model class.

protected abstract IFullModel<T, Matrix<T>, Vector<T>> CreateInstance()

Returns

IFullModel<T, Matrix<T>, Vector<T>>

A new instance of the same model type.

Remarks

This abstract factory method must be implemented by derived classes to create a new instance of their specific type. It's used by Clone and DeepCopy to ensure that the correct derived type is instantiated.

For Beginners: This method creates a new, empty instance of the specific model type. It's used during cloning and deep copying to ensure that the copy is of the same specific type as the original. This is more efficient than using reflection to create instances and gives derived classes explicit control over how new instances are created.

DeepCopy()

Creates a deep copy of the model.

public virtual IFullModel<T, Matrix<T>, Vector<T>> DeepCopy()

Returns

IFullModel<T, Matrix<T>, Vector<T>>

A new model instance that is a deep copy of the current model.

Remarks

This method creates a completely independent copy of the model, including all parameters, support vectors, and configuration options. Modifications to the returned model will not affect the original model, and vice versa.

For Beginners: This method creates a complete, independent copy of your model. It's like making a photocopy of a document - the copy looks exactly the same but is a separate object that can be modified without affecting the original. This is useful when you want to experiment with changes to a model without risking the original or when you need multiple independent instances of the same model (e.g., for ensemble learning).

Deserialize(byte[])

Deserializes the model from a byte array.

public virtual void Deserialize(byte[] modelData)

Parameters

modelData byte[]

The byte array containing the serialized model data.

Remarks

This method reconstructs the model's parameters from a serialized byte array, including options, support vectors, alpha coefficients, bias term, and regularization options.

For Beginners: Deserialization is the opposite of serialization - it takes the saved model data and reconstructs the model's internal state. This allows you to load a previously trained model and use it to make predictions without having to retrain it. It's like loading a saved game to continue where you left off.

ExportComputationGraph(List<ComputationNode<T>>)

Exports the model's computation graph for JIT compilation.

public virtual ComputationNode<T> ExportComputationGraph(List<ComputationNode<T>> inputNodes)

Parameters

inputNodes List<ComputationNode<T>>

List to populate with input computation nodes (parameters).

Returns

ComputationNode<T>

The output computation node representing the model's prediction.

Remarks

This method should construct a computation graph representing the model's forward pass. The graph should use placeholder input nodes that will be filled with actual data during execution.

For Beginners: This method creates a "recipe" of your model's calculations that the JIT compiler can optimize.

The method should:

  1. Create placeholder nodes for inputs (features, parameters)
  2. Build the computation graph using TensorOperations
  3. Return the final output node
  4. Add all input nodes to the inputNodes list (in order)

Example for a simple linear model (y = Wx + b):

public ComputationNode<T> ExportComputationGraph(List<ComputationNode<T>> inputNodes)
{
    // Create placeholder inputs
    var x = TensorOperations<T>.Variable(new Tensor<T>(InputShape), "x");
    var W = TensorOperations<T>.Variable(Weights, "W");
    var b = TensorOperations<T>.Variable(Bias, "b");

    // Add inputs in order
    inputNodes.Add(x);
    inputNodes.Add(W);
    inputNodes.Add(b);

    // Build graph: y = Wx + b
    var matmul = TensorOperations<T>.MatMul(x, W);
    var output = TensorOperations<T>.Add(matmul, b);

    return output;
}

The JIT compiler will then:

  • Optimize the graph (fuse operations, eliminate dead code)
  • Compile it to fast native code
  • Cache the compiled version for reuse

ExtractModelParameters()

Extracts the support vectors and their coefficients after optimization.

protected virtual void ExtractModelParameters()

Remarks

This method identifies the support vectors (training examples with non-zero alpha coefficients) and extracts them along with their corresponding alpha values.

For Beginners: After training, not all examples are equally important for making predictions. This method identifies which examples are most important (the "support vectors") and keeps only those for making future predictions. This makes the model more efficient and often improves its performance on new data.

GetActiveFeatureIndices()

Gets the indices of features that are actively used by the model.

public virtual IEnumerable<int> GetActiveFeatureIndices()

Returns

IEnumerable<int>

A collection of feature indices that have non-zero weight in the model.

Remarks

This method identifies which features have a significant impact on the model's predictions by analyzing the support vectors and their coefficients. A feature is considered active if it has a non-zero weight in at least one support vector with a non-zero alpha coefficient.

For Beginners: This method tells you which features (input variables) your model is actually using to make predictions. Some models may effectively ignore certain features if they don't help with predictions. Knowing which features are actually being used can help you understand what information the model considers important and potentially simplify your model by removing unused features.

GetFeatureImportance()

Gets the feature importance scores as a dictionary.

public virtual Dictionary<string, T> GetFeatureImportance()

Returns

Dictionary<string, T>

A dictionary mapping feature names to their importance scores.

GetModelMetadata()

Gets metadata about the model.

public virtual ModelMetadata<T> GetModelMetadata()

Returns

ModelMetadata<T>

A ModelMetadata object containing information about the model.

Remarks

This method returns metadata about the model, including its type and additional information such as the kernel type, kernel parameters, and the number of support vectors.

For Beginners: Model metadata is information about the model itself, rather than the predictions it makes. This includes details about how the model is configured (like what type of kernel it uses) and some statistics about its structure (like how many support vectors it has). This information can be useful for understanding the model's complexity and for debugging purposes.

GetModelType()

Gets the type of the model.

protected abstract ModelType GetModelType()

Returns

ModelType

The model type identifier.

Remarks

This abstract method must be implemented by derived classes to return the specific model type.

For Beginners: This method simply returns an identifier that indicates what specific type of non-linear regression model this is (e.g., Support Vector Regression, Neural Network Regression, etc.). It's used internally by the library to keep track of different types of models.

GetParameters()

Gets the model parameters as a single vector.

public virtual Vector<T> GetParameters()

Returns

Vector<T>

A vector containing all model parameters (alpha coefficients and bias term).

Remarks

This method combines all model parameters into a single vector, with the bias term as the first element followed by all alpha coefficients. This representation is useful for optimization algorithms and for operations that need to treat all parameters uniformly.

For Beginners: This method collects all the model's internal values (parameters) into a single list. Think of it like getting a complete list of ingredients and measurements for a recipe. This allows you to see all the parameters at once or pass them to other algorithms that work with the model's parameters as a group.

InitializeModel(Matrix<T>, Vector<T>)

Initializes the model parameters before optimization.

protected virtual void InitializeModel(Matrix<T> x, Vector<T> y)

Parameters

x Matrix<T>

The input features matrix.

y Vector<T>

The target values vector.

Remarks

This method initializes the model parameters (Alphas and B) based on the input data.

For Beginners: Before the model can start learning, it needs to set up its internal values (parameters). This method creates those initial values, which will be adjusted during the training process. It's like setting up the starting position before beginning a journey.

IsFeatureUsed(int)

Determines whether a specific feature is used by the model.

public virtual bool IsFeatureUsed(int featureIndex)

Parameters

featureIndex int

The index of the feature to check.

Returns

bool

True if the feature is used by the model; otherwise, false.

Remarks

This method checks whether a specific feature has a significant impact on the model's predictions by determining if it has a non-zero weight in at least one support vector with a non-zero alpha coefficient.

For Beginners: This method checks if a specific feature (input variable) is actually being used by your model to make predictions. It's like checking if a particular ingredient in a recipe is actually affecting the final dish or if it could be left out without changing the result. This can help you understand what information your model considers important and potentially simplify your model by removing unused features.

Exceptions

ArgumentOutOfRangeException

Thrown when featureIndex is negative or greater than the number of features.

KernelFunction(Vector<T>, Vector<T>)

Computes the kernel function between two vectors.

protected T KernelFunction(Vector<T> x1, Vector<T> x2)

Parameters

x1 Vector<T>

The first vector.

x2 Vector<T>

The second vector.

Returns

T

The kernel function value.

Remarks

This method computes the kernel function value between two vectors based on the kernel type specified in the options. The kernel function measures the similarity between two vectors in a potentially higher-dimensional space.

For Beginners: The kernel function is a mathematical way to measure how similar two examples are to each other. Different kernel functions capture different types of similarities. For example: - Linear kernel: Measures similarity based on the dot product (like a straight-line relationship) - RBF (Radial Basis Function) kernel: Measures similarity based on distance (examples close to each other are more similar) - Polynomial kernel: Can capture more complex curved relationships

The kernel function is what gives non-linear regression models their power to model complex patterns.

LoadModel(string)

Loads the model from a file.

public virtual void LoadModel(string filePath)

Parameters

filePath string

The path to the file containing the saved model.

Remarks

This method provides a convenient way to load a model directly from disk. It combines file I/O operations with deserialization.

For Beginners: This is like clicking "Open" in a document editor. Instead of manually reading from a file and then calling Deserialize(), this method does both steps for you.

Exceptions

FileNotFoundException

Thrown when the specified file does not exist.

IOException

Thrown when an I/O error occurs while reading from the file or when the file contains corrupted or invalid model data.

LoadState(Stream)

Loads the model's state from a stream.

public virtual void LoadState(Stream stream)

Parameters

stream Stream

OptimizeModel(Matrix<T>, Vector<T>)

Optimizes the model parameters using the training data.

protected abstract void OptimizeModel(Matrix<T> x, Vector<T> y)

Parameters

x Matrix<T>

The input features matrix.

y Vector<T>

The target values vector.

Remarks

This abstract method must be implemented by derived classes to perform the actual optimization of the model parameters.

For Beginners: This is where the actual learning happens. Different algorithms will implement this method differently, but they all have the same goal: to adjust the model's parameters to make predictions that match the training data as closely as possible, while still generalizing well to new data.

Predict(Matrix<T>)

Makes predictions for the given input data.

public virtual Vector<T> Predict(Matrix<T> input)

Parameters

input Matrix<T>

The input features matrix where each row is an example and each column is a feature.

Returns

Vector<T>

A vector of predicted values for each input example.

Remarks

This method applies the trained model to each input example and returns the predicted values.

For Beginners: After training, this method is used to make predictions on new data. It takes your input features and runs them through the trained model to estimate what the target values should be. This is the main purpose of building a regression model - to predict values for new examples.

PredictSingle(Vector<T>)

Makes a prediction for a single input example.

protected virtual T PredictSingle(Vector<T> input)

Parameters

input Vector<T>

The input feature vector.

Returns

T

The predicted value.

Remarks

This method computes the prediction for a single input example by applying the kernel function to the input and each support vector, multiplying by the corresponding alpha coefficient, and adding the bias term.

For Beginners: This method calculates the prediction for a single example. It uses the support vectors (important training examples) and their weights (alpha coefficients) to compute how similar the new example is to each support vector. These similarity scores are combined to produce the final prediction. The mathematical function used to measure similarity is called the "kernel function."

SaveModel(string)

Saves the model to a file.

public virtual void SaveModel(string filePath)

Parameters

filePath string

The path where the model should be saved.

Remarks

This method provides a convenient way to save the model directly to disk. It combines serialization with file I/O operations.

For Beginners: This is like clicking "Save As" in a document editor. Instead of manually calling Serialize() and then writing to a file, this method does both steps for you.

Exceptions

IOException

Thrown when an I/O error occurs while writing to the file.

UnauthorizedAccessException

Thrown when the caller does not have the required permission to write to the specified file path.

SaveState(Stream)

Saves the model's current state to a stream.

public virtual void SaveState(Stream stream)

Parameters

stream Stream

Serialize()

Serializes the model to a byte array.

public virtual byte[] Serialize()

Returns

byte[]

A byte array containing the serialized model data.

Remarks

This method serializes the model's parameters, including options, support vectors, alpha coefficients, bias term, and regularization options, to a byte array that can be stored or transmitted.

For Beginners: Serialization converts the model's internal state into a format that can be saved to disk or transmitted over a network. This allows you to save a trained model and load it later without having to retrain it. Think of it like saving your progress in a video game.

SetActiveFeatureIndices(IEnumerable<int>)

Sets the active feature indices for this model.

public virtual void SetActiveFeatureIndices(IEnumerable<int> featureIndices)

Parameters

featureIndices IEnumerable<int>

The indices of features to activate.

SetParameters(Vector<T>)

Sets the parameters for this model.

public virtual void SetParameters(Vector<T> parameters)

Parameters

parameters Vector<T>

A vector containing the model parameters.

Train(Matrix<T>, Vector<T>)

Trains the non-linear regression model on the provided data.

public virtual void Train(Matrix<T> x, Vector<T> y)

Parameters

x Matrix<T>

The input features matrix where each row is a training example and each column is a feature.

y Vector<T>

The target values vector corresponding to each training example.

Remarks

This method performs the following steps: 1. Validates the input data 2. Initializes the model parameters 3. Optimizes the model parameters using the training data 4. Extracts the support vectors and their coefficients

For Beginners: Training is the process where the model learns from your data. It looks at the examples you provide (input features and their corresponding target values) and adjusts its internal parameters to make predictions that match the target values as closely as possible. After training, the model will be ready to make predictions on new data.

ValidateInputs(Matrix<T>, Vector<T>)

Validates the input data before training.

protected virtual void ValidateInputs(Matrix<T> x, Vector<T> y)

Parameters

x Matrix<T>

The input features matrix.

y Vector<T>

The target values vector.

Remarks

This method checks that the input data is valid before proceeding with training.

For Beginners: This method makes sure your data is in the correct format before training begins. It checks that you have the same number of target values as you have examples in your input data. If not, it will raise an error to let you know there's a mismatch.

Exceptions

ArgumentException

Thrown when the number of rows in x doesn't match the length of y.

WithParameters(Vector<T>)

Creates a new model with the specified parameters.

public virtual IFullModel<T, Matrix<T>, Vector<T>> WithParameters(Vector<T> parameters)

Parameters

parameters Vector<T>

A vector containing all model parameters (bias term followed by alpha coefficients).

Returns

IFullModel<T, Matrix<T>, Vector<T>>

A new model instance with the specified parameters.

Remarks

This method creates a new model instance with the same structure as the current model but with different parameter values. The first element of the parameters vector is interpreted as the bias term, and the remaining elements are interpreted as alpha coefficients.

For Beginners: This method creates a new model with specific parameter values you provide. It's like following a recipe but changing the amounts of certain ingredients. This is useful when you want to experiment with different parameter settings or when an optimization algorithm suggests better parameter values.

Exceptions

ArgumentException

Thrown when the parameters vector doesn't match the expected length.