Class LinearEvaluator<T>
- Namespace
- AiDotNet.SelfSupervisedLearning.Evaluation
- Assembly
- AiDotNet.dll
Linear evaluation protocol for assessing SSL representation quality.
public class LinearEvaluator<T>
Type Parameters
TThe numeric type used for computations.
- Inheritance
-
LinearEvaluator<T>
- Inherited Members
Remarks
For Beginners: Linear evaluation is the standard way to measure how good self-supervised representations are. We freeze the pretrained encoder and train only a simple linear classifier on top. Better representations = higher accuracy.
Why linear evaluation?
- Tests if representations are linearly separable (good sign of quality)
- Simple and fast to train
- Standard benchmark that allows comparing different SSL methods
- Frozen encoder ensures we're testing the representations, not re-training
Typical protocol:
- Freeze pretrained encoder
- Add linear classifier (fc layer)
- Train on labeled data (e.g., ImageNet 1%/10%/100%)
- Report top-1 and top-5 accuracy
Constructors
LinearEvaluator(INeuralNetwork<T>, int, int, double, int)
Initializes a new instance of the LinearEvaluator class.
public LinearEvaluator(INeuralNetwork<T> encoder, int inputDim, int numClasses, double learningRate = 0.1, int epochs = 90)
Parameters
encoderINeuralNetwork<T>The pretrained encoder (will be frozen).
inputDimintOutput dimension of the encoder.
numClassesintNumber of classification classes.
learningRatedoubleLearning rate for training (default: 0.1).
epochsintNumber of training epochs (default: 90).
Properties
InputDimension
Gets the input dimension (encoder output).
public int InputDimension { get; }
Property Value
NumClasses
Gets the number of classes for classification.
public int NumClasses { get; }
Property Value
Methods
Evaluate(Tensor<T>, int[])
Evaluates the linear classifier on a test dataset.
public double Evaluate(Tensor<T> testData, int[] testLabels)
Parameters
testDataTensor<T>Test data [num_samples, features].
testLabelsint[]Test labels [num_samples].
Returns
- double
Top-1 accuracy.
EvaluateTopK(Tensor<T>, int[], int)
Computes top-k accuracy.
public double EvaluateTopK(Tensor<T> testData, int[] testLabels, int k = 5)
Parameters
Returns
- double
Top-k accuracy.
Train(Tensor<T>, int[], Tensor<T>?, int[]?)
Trains the linear classifier on the given dataset.
public LinearEvalResult<T> Train(Tensor<T> trainData, int[] trainLabels, Tensor<T>? validData = null, int[]? validLabels = null)
Parameters
trainDataTensor<T>Training data [num_samples, features].
trainLabelsint[]Training labels [num_samples].
validDataTensor<T>Optional validation data.
validLabelsint[]Optional validation labels.
Returns
- LinearEvalResult<T>
Training result with accuracy metrics.