Table of Contents

Class LinearEvaluator<T>

Namespace
AiDotNet.SelfSupervisedLearning.Evaluation
Assembly
AiDotNet.dll

Linear evaluation protocol for assessing SSL representation quality.

public class LinearEvaluator<T>

Type Parameters

T

The 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:

  1. Freeze pretrained encoder
  2. Add linear classifier (fc layer)
  3. Train on labeled data (e.g., ImageNet 1%/10%/100%)
  4. 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

encoder INeuralNetwork<T>

The pretrained encoder (will be frozen).

inputDim int

Output dimension of the encoder.

numClasses int

Number of classification classes.

learningRate double

Learning rate for training (default: 0.1).

epochs int

Number of training epochs (default: 90).

Properties

InputDimension

Gets the input dimension (encoder output).

public int InputDimension { get; }

Property Value

int

NumClasses

Gets the number of classes for classification.

public int NumClasses { get; }

Property Value

int

Methods

Evaluate(Tensor<T>, int[])

Evaluates the linear classifier on a test dataset.

public double Evaluate(Tensor<T> testData, int[] testLabels)

Parameters

testData Tensor<T>

Test data [num_samples, features].

testLabels int[]

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

testData Tensor<T>

Test data.

testLabels int[]

Test labels.

k int

K value for top-k accuracy.

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

trainData Tensor<T>

Training data [num_samples, features].

trainLabels int[]

Training labels [num_samples].

validData Tensor<T>

Optional validation data.

validLabels int[]

Optional validation labels.

Returns

LinearEvalResult<T>

Training result with accuracy metrics.