Table of Contents

Class MetaAdaptationResult<T>

Namespace
AiDotNet.Models.Results
Assembly
AiDotNet.dll

Results from adapting a meta-learner to a single task.

public class MetaAdaptationResult<T>

Type Parameters

T

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

Inheritance
MetaAdaptationResult<T>
Inherited Members

Remarks

This class captures detailed metrics from the inner loop adaptation process for a single task. It tracks both support set performance (where the model adapts) and query set performance (where we measure true generalization), along with adaptation details.

For Beginners: Meta-learning has two phases for each task:

  1. Adaptation (Inner Loop): The model quickly learns from the support set (a few examples)
  2. Evaluation: We test on the query set (held-out examples) to see if it really learned

This result tracks:

  • Support metrics: How well the model fits the training examples (should be very good)
  • Query metrics: How well it generalizes (the real test!)
  • Adaptation details: How many steps, how long it took, etc.

For example, in 5-way 1-shot learning:

  • Support set: 5 examples (1 per class) - model adapts on these
  • Query set: 15 examples (3 per class) - model is evaluated on these
  • Good meta-learning: High query accuracy even with tiny support set

Constructors

MetaAdaptationResult(T, T, T, T, int, double, List<T>?, Dictionary<string, T>?)

Initializes a new instance with adaptation metrics.

public MetaAdaptationResult(T queryAccuracy, T queryLoss, T supportAccuracy, T supportLoss, int adaptationSteps, double adaptationTimeMs, List<T>? perStepLosses = null, Dictionary<string, T>? additionalMetrics = null)

Parameters

queryAccuracy T

Accuracy on query set after adaptation.

queryLoss T

Loss on query set after adaptation.

supportAccuracy T

Accuracy on support set after adaptation.

supportLoss T

Loss on support set after adaptation.

adaptationSteps int

Number of gradient steps taken.

adaptationTimeMs double

Time taken for adaptation in milliseconds.

perStepLosses List<T>

Optional per-step loss values for convergence analysis.

additionalMetrics Dictionary<string, T>

Optional algorithm-specific metrics.

Remarks

This constructor captures a complete snapshot of adaptation performance for a single task. Unlike MetaEvaluationResult which aggregates across tasks, this represents one task's detailed adaptation results.

For Beginners: Call this after adapting to a single task to package all the results together. The most important values are queryAccuracy (how well you generalized) and queryLoss (the error on new examples).

Properties

AdaptationSteps

Gets the number of gradient steps taken during adaptation.

public int AdaptationSteps { get; }

Property Value

int

The count of inner loop optimization steps performed.

Remarks

For Production: This is useful for: - Verifying your inner loop configuration - Debugging convergence issues - Comparing different adaptation strategies

Typical values: 1-10 steps for simple tasks, 5-50 for complex tasks

AdaptationTimeMs

Gets the time taken for adaptation in milliseconds.

public double AdaptationTimeMs { get; }

Property Value

double

The elapsed time for the inner loop adaptation process.

Remarks

For Production: Use this for: - Performance profiling and optimization - Setting realistic timeout values - Comparing algorithm efficiency

Typical values vary widely based on:

  • Model complexity
  • Number of adaptation steps
  • Hardware (GPU vs CPU)

AdditionalMetrics

Gets algorithm-specific metrics for this adaptation.

public Dictionary<string, T> AdditionalMetrics { get; }

Property Value

Dictionary<string, T>

A dictionary of custom metrics with generic T values.

Remarks

For Production: Common additional metrics include: - "initial_loss": Loss before any adaptation - "loss_reduction": How much loss decreased during adaptation - "gradient_norm": Magnitude of gradients during adaptation - "parameter_change": How much parameters moved

PerStepLosses

Gets the loss values recorded at each adaptation step (optional).

public List<T> PerStepLosses { get; }

Property Value

List<T>

A list of loss values, one per adaptation step, showing convergence progress. Empty if not tracked during adaptation.

Remarks

For Production: Use this for: - Visualizing convergence curves - Debugging non-convergent adaptations - Tuning inner loop hyperparameters - Early stopping strategies

QueryAccuracy

Gets the accuracy on the query set after adaptation.

public T QueryAccuracy { get; }

Property Value

T

The proportion of correct predictions on query examples, after adapting on the support set. This is the key metric for meta-learning quality - it measures true generalization.

Remarks

For Beginners: This is the most important number - how well the model performs on new examples after learning from just a few examples (the support set).

Higher query accuracy means better meta-learning. In research papers, this is typically reported as "test accuracy" or "query accuracy" for N-way K-shot tasks.

QueryLoss

Gets the loss on the query set after adaptation.

public T QueryLoss { get; }

Property Value

T

The average loss computed on query examples after inner loop adaptation.

SupportAccuracy

Gets the accuracy on the support set after adaptation.

public T SupportAccuracy { get; }

Property Value

T

The proportion of correct predictions on support examples. This should typically be very high (close to 1.0 or 100%).

Remarks

For Beginners: Support accuracy tells you if the model successfully fit the training examples. It should be very high (often 100%) since these are the examples the model adapted on.

If support accuracy is low, it indicates:

  • The inner loop learning rate might be too small
  • Not enough adaptation steps
  • The task might be too difficult

SupportLoss

Gets the loss on the support set after adaptation.

public T SupportLoss { get; }

Property Value

T

The average loss computed on support examples after inner loop adaptation.

Methods

CalculateOverfittingGap()

public T CalculateOverfittingGap()

Returns

T

DidConverge(double)

Checks if the adaptation converged based on loss reduction.

public bool DidConverge(double convergenceThreshold = 0.01)

Parameters

convergenceThreshold double

Minimum loss reduction to consider converged (default: 0.01).

Returns

bool

True if loss decreased sufficiently, false otherwise.

Remarks

For Production: Use this to: - Detect failed adaptations early - Implement adaptive inner loop step counts - Flag problematic tasks for analysis

Requires PerStepLosses to be populated.

GenerateReport()

Generates a formatted summary of adaptation results.

public string GenerateReport()

Returns

string

A human-readable string with key adaptation metrics.