Table of Contents

Class WeightFunctionHelper<T>

Namespace
AiDotNet.Helpers
Assembly
AiDotNet.dll

Provides methods for calculating weights used in robust regression techniques.

public static class WeightFunctionHelper<T>

Type Parameters

T

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

Inheritance
WeightFunctionHelper<T>
Inherited Members

Remarks

For Beginners: In standard regression, all data points are treated equally. However, in real-world data, some points may be outliers (unusual values that don't follow the general pattern). Robust regression techniques handle these outliers by assigning different "weights" to different data points.

Think of weights like importance scores:

  • Normal data points get high weights (close to 1), meaning they have full influence on the model
  • Outliers get low weights (close to 0), reducing their influence on the model

This helper class calculates these weights using different mathematical formulas (Huber, Bisquare, Andrews) that determine how aggressively to downweight outliers.

Methods

CalculateWeights(Vector<T>, WeightFunction, double)

Calculates weights for data points based on their residuals using the specified weight function.

public static Vector<T> CalculateWeights(Vector<T> residuals, WeightFunction weightFunction, double tuningConstant)

Parameters

residuals Vector<T>

The vector of residuals (differences between predicted and actual values).

weightFunction WeightFunction

The weight function to use (Huber, Bisquare, or Andrews).

tuningConstant double

A parameter that controls how aggressively to downweight outliers.

Returns

Vector<T>

A vector of weights for each data point.

Remarks

For Beginners: This method takes the errors in your model's predictions (residuals) and calculates how much each data point should influence your model.

The residual for a data point is the difference between what your model predicted and the actual value. Large residuals often indicate outliers.

The weight function determines the mathematical formula used to convert residuals to weights:

  • Huber: Moderately reduces the influence of outliers
  • Bisquare: More aggressively reduces the influence of outliers
  • Andrews: Similar to Bisquare but uses a different mathematical approach

The tuning constant controls the threshold for what's considered an outlier - smaller values will treat more points as outliers.