Class PostprocessorBase<T, TInput, TOutput>
- Namespace
- AiDotNet.Postprocessing
- Assembly
- AiDotNet.dll
Abstract base class for all postprocessors providing common functionality.
public abstract class PostprocessorBase<T, TInput, TOutput> : IPostprocessor<T, TInput, TOutput>
Type Parameters
TThe numeric type for calculations (e.g., float, double).
TInputThe input data type (model output).
TOutputThe output data type after postprocessing.
- Inheritance
-
PostprocessorBase<T, TInput, TOutput>
- Implements
-
IPostprocessor<T, TInput, TOutput>
- Derived
- Inherited Members
Remarks
This class provides the template method pattern for postprocessing. Derived classes implement the core processing logic while this base class handles validation, configuration, and common operations.
For Beginners: This is the foundation that all postprocessors build on. It provides common features like: - Configuration management - Batch processing support - Error handling
When creating a new postprocessor, you extend this class and implement the abstract methods.
Constructors
PostprocessorBase()
Creates a new instance of the postprocessor.
protected PostprocessorBase()
Properties
IsConfigured
Gets whether this postprocessor is configured and ready to use.
public bool IsConfigured { get; protected set; }
Property Value
NumOps
Gets the numeric operations helper for type T.
protected INumericOperations<T> NumOps { get; }
Property Value
- INumericOperations<T>
Settings
Gets the configuration settings for this postprocessor.
protected Dictionary<string, object> Settings { get; }
Property Value
SupportsInverse
Gets whether this postprocessor supports inverse transformation.
public abstract bool SupportsInverse { get; }
Property Value
Methods
Configure(Dictionary<string, object>?)
Configures the postprocessor with optional settings.
public virtual void Configure(Dictionary<string, object>? settings = null)
Parameters
settingsDictionary<string, object>Optional configuration dictionary.
ConfigureCore(Dictionary<string, object>?)
Core configuration implementation. Override to handle specific settings.
protected virtual void ConfigureCore(Dictionary<string, object>? settings)
Parameters
settingsDictionary<string, object>The configuration settings.
EnsureConfigured()
Ensures the postprocessor is configured before use.
protected void EnsureConfigured()
Exceptions
- InvalidOperationException
Thrown if not configured.
GetSetting<TSetting>(string, TSetting)
Gets a setting value with type conversion.
protected TSetting GetSetting<TSetting>(string key, TSetting defaultValue)
Parameters
keystringThe setting key.
defaultValueTSettingDefault value if not found.
Returns
- TSetting
The setting value or default.
Type Parameters
TSettingThe expected setting type.
Inverse(TOutput)
Reverses the postprocessing (if supported).
public TInput Inverse(TOutput output)
Parameters
outputTOutputThe postprocessed result.
Returns
- TInput
The original model output format.
Exceptions
- NotSupportedException
Thrown if inverse is not supported.
InverseCore(TOutput)
Core inverse transformation implementation. Override this in derived classes.
protected virtual TInput InverseCore(TOutput output)
Parameters
outputTOutputThe output to invert.
Returns
- TInput
The inverted input.
Process(TInput)
Transforms model output into the final result format.
public TOutput Process(TInput input)
Parameters
inputTInputThe model output to process.
Returns
- TOutput
The postprocessed result.
Exceptions
- InvalidOperationException
Thrown if not configured.
ProcessBatch(IEnumerable<TInput>)
Transforms a batch of model outputs.
public virtual IList<TOutput> ProcessBatch(IEnumerable<TInput> inputs)
Parameters
inputsIEnumerable<TInput>The model outputs to process.
Returns
- IList<TOutput>
The postprocessed results.
ProcessCore(TInput)
Core processing implementation. Override this in derived classes.
protected abstract TOutput ProcessCore(TInput input)
Parameters
inputTInputThe input to process.
Returns
- TOutput
The processed output.
ValidateInput(TInput)
Validates input before processing.
protected virtual void ValidateInput(TInput input)
Parameters
inputTInputThe input to validate.
Exceptions
- ArgumentNullException
Thrown if input is null.