Class MetaLearningTaskBase<T, TInput, TOutput>
- Namespace
- AiDotNet.Data.Structures
- Assembly
- AiDotNet.dll
Abstract base class for meta-learning tasks, providing common functionality and validation.
public abstract class MetaLearningTaskBase<T, TInput, TOutput> : IMetaLearningTask<T, TInput, TOutput>
Type Parameters
TThe numeric type used for calculations (e.g., float, double).
TInputThe input data type (e.g., Matrix<T>, Tensor<T>).
TOutputThe output data type (e.g., Vector<T>, Tensor<T>).
- Inheritance
-
MetaLearningTaskBase<T, TInput, TOutput>
- Implements
-
IMetaLearningTask<T, TInput, TOutput>
- Inherited Members
Remarks
This base class implements the IMetaLearningTask<T, TInput, TOutput> interface and provides common functionality for all meta-learning task implementations. It includes validation, default values, and helper methods to reduce code duplication across concrete implementations.
Concrete implementations should inherit from this class and provide any additional functionality specific to their meta-learning scenario (e.g., episode tracking, hierarchical relationships, continual learning).
Constructors
MetaLearningTaskBase(int, int, int, string?, Dictionary<string, object>?)
Initializes a new instance of the MetaLearningTaskBase class.
protected MetaLearningTaskBase(int numWays = 5, int numShots = 1, int numQueryPerClass = 15, string? name = null, Dictionary<string, object>? metadata = null)
Parameters
numWaysintNumber of classes (ways) in this task.
numShotsintNumber of examples per class in the support set.
numQueryPerClassintNumber of query examples per class.
namestringOptional name for the task.
metadataDictionary<string, object>Optional metadata dictionary.
Properties
Metadata
Gets the additional metadata about the task.
public virtual Dictionary<string, object>? Metadata { get; }
Property Value
- Dictionary<string, object>
Dictionary containing task-specific information.
Name
Gets or sets an optional name or identifier for the task.
public virtual string? Name { get; set; }
Property Value
- string
Human-readable task name or null if not specified.
NumQueryPerClass
Gets the number of query examples per class.
public int NumQueryPerClass { get; protected set; }
Property Value
Remarks
The number of examples in the query set for each class.
NumShots
Gets the number of shots (examples per class) in the support set.
public int NumShots { get; protected set; }
Property Value
Remarks
In N-way K-shot learning, this represents the K (number of examples per class).
NumWays
Gets the number of ways (classes) in this task.
public int NumWays { get; protected set; }
Property Value
Remarks
In N-way K-shot learning, this represents the N (number of classes per task).
QueryInput
Gets or sets the input features for the query set.
public virtual TInput QueryInput { get; set; }
Property Value
- TInput
Input data for evaluating adaptation performance.
Exceptions
- ArgumentNullException
Thrown when trying to set null value.
QueryOutput
Gets or sets the target labels for the query set.
public virtual TOutput QueryOutput { get; set; }
Property Value
- TOutput
True labels for evaluating query set performance.
Exceptions
- ArgumentNullException
Thrown when trying to set null value.
QuerySetX
Gets the input features for the query set (alias for QueryInput).
public TInput QuerySetX { get; }
Property Value
- TInput
Remarks
This property provides compatibility with legacy code that uses QuerySetX naming convention.
QuerySetY
Gets the target labels for the query set (alias for QueryOutput).
public TOutput QuerySetY { get; }
Property Value
- TOutput
Remarks
This property provides compatibility with legacy code that uses QuerySetY naming convention.
SupportInput
Gets or sets the input features for the support set.
public virtual TInput SupportInput { get; set; }
Property Value
- TInput
Input data containing examples for task adaptation.
Exceptions
- ArgumentNullException
Thrown when trying to set null value.
SupportOutput
Gets or sets the target labels for the support set.
public virtual TOutput SupportOutput { get; set; }
Property Value
- TOutput
Output data containing labels corresponding to SupportInput.
Exceptions
- ArgumentNullException
Thrown when trying to set null value.
SupportSetX
Gets the input features for the support set (alias for SupportInput).
public TInput SupportSetX { get; }
Property Value
- TInput
Remarks
This property provides compatibility with legacy code that uses SupportSetX naming convention.
SupportSetY
Gets the target labels for the support set (alias for SupportOutput).
public TOutput SupportSetY { get; }
Property Value
- TOutput
Remarks
This property provides compatibility with legacy code that uses SupportSetY naming convention.
TaskId
Gets or sets an optional identifier for the task.
public virtual int? TaskId { get; set; }
Property Value
- int?
Integer identifier for the task or null if not specified.
Methods
SetMetadata(string, object)
Adds or updates a metadata entry.
public void SetMetadata(string key, object value)
Parameters
Exceptions
- ArgumentNullException
Thrown when key is null.
ToString()
Creates a string representation of the task.
public override string ToString()
Returns
- string
String containing task name and type information.
TryGetMetadata<TValue>(string, out TValue?)
Gets a metadata value if it exists.
public bool TryGetMetadata<TValue>(string key, out TValue? value)
Parameters
keystringThe metadata key.
valueTValueOutput for the value if found.
Returns
- bool
True if the value was found and successfully cast to TValue.
Type Parameters
TValueThe type of value to retrieve.
Validate()
Validates that the task has all required data populated.
public virtual void Validate()
Exceptions
- InvalidOperationException
Thrown when required data is missing.