IHyperparameterOptimizer<T, TInput, TOutput>
Interfaces · AiDotNet.Interfaces
Defines the contract for hyperparameter optimization algorithms.
Known implementations: HyperparameterOptimizerBase<T, TInput, TOutput>
How It Works
A hyperparameter optimizer automatically searches for the best hyperparameters for a machine learning model by trying different combinations and evaluating their performance.
For Beginners: Think of hyperparameters as the “settings” for your machine learning algorithm (like learning rate, number of layers, etc.). A hyperparameter optimizer is like an automatic tuner that tries different settings to find the combination that works best for your data.
Common optimization strategies include:
- Grid Search: Tries every possible combination in a predefined grid
- Random Search: Randomly samples combinations
- Bayesian Optimization: Uses past results to intelligently choose what to try next
- Hyperband: Efficiently allocates resources to promising configurations
Why hyperparameter optimization matters:
- Manual tuning is time-consuming and error-prone
- Good hyperparameters can dramatically improve model performance
- Systematic search ensures you don’t miss good configurations
- Enables reproducible model selection
Methods
| Method | Summary |
|---|---|
Dictionary<string, object> SuggestNext(HyperparameterTrial<T> trial) |
Suggests the next hyperparameter configuration to try based on past trials. |
HyperparameterOptimizationResult<T> Optimize(Func<Dictionary<string, object>, T> objectiveFunction, HyperparameterSearchSpace searchSpace, int nTrials) |
Searches for the best hyperparameter configuration. |
HyperparameterOptimizationResult<T> OptimizeModel(IModel<TInput, TOutput, TMetadata> model, ValueTuple<TInput, TOutput> trainingData, ValueTuple<TInput, TOutput> validationData, HyperparameterSearchSpace searchSpace, int nTrials) |
Searches for the best hyperparameters for a specific model. |
HyperparameterTrial<T> GetBestTrial() |
Gets the best trial from the optimization. |
List<HyperparameterTrial<T>> GetAllTrials() |
Gets all trials performed during optimization. |
List<HyperparameterTrial<T>> GetTrials(Func<HyperparameterTrial<T>, bool> filter) |
Gets trials that meet a certain criteria. |
bool ShouldPrune(HyperparameterTrial<T> trial, int step, T intermediateValue) |
Determines if a trial should be pruned (stopped early) to save resources. |
void ReportTrial(HyperparameterTrial<T> trial, T objectiveValue) |
Reports the result of a trial. |