automl

package
v1.25.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package automl provides automated machine learning utilities including Bayesian hyperparameter optimization.

Package automl implements Bayesian hyperparameter optimization and population-based training.

Stability: alpha

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoML added in v1.8.0

func AutoML(data [][]float64, labels []int, config AutoMLConfig) (*BestModel, *SearchReport, error)

AutoML searches the tabular and time-series architecture space for the best model on the given dataset. data is [n_samples, n_features], labels are class indices in [0, 3) corresponding to tabular.Long, Short, Flat.

Types

type Agent

type Agent struct {
	ID      int
	Params  map[string]float64
	Weights []float64
	Score   float64
}

Agent represents a single member of the PBT population. Each agent maintains its own hyperparameter configuration, model weights (opaque to PBT), and current performance score.

type ArchKind added in v1.8.0

type ArchKind string

ArchKind identifies an architecture in the tabular/time-series search space.

const (
	// Tabular architectures.
	ArchMLP           ArchKind = "MLP"
	ArchFTTransformer ArchKind = "FTTransformer"
	ArchTabNet        ArchKind = "TabNet"
	ArchSAINT         ArchKind = "SAINT"
	ArchTabResNet     ArchKind = "TabResNet"

	// Time-series architectures.
	ArchTFT      ArchKind = "TFT"
	ArchNBEATS   ArchKind = "NBEATS"
	ArchPatchTST ArchKind = "PatchTST"
)

func AllArchitectures added in v1.8.0

func AllArchitectures() []ArchKind

AllArchitectures returns the full set of searchable architectures.

type ArchResult added in v1.8.0

type ArchResult struct {
	Architecture ArchKind
	HyperParams  map[string]float64
	Score        float64 // validation accuracy in [0, 1]
	TrailID      int
}

ArchResult records the outcome of evaluating one (architecture, hyperparameter) trial.

type AutoMLConfig added in v1.8.0

type AutoMLConfig struct {
	// Architectures to include in the search. Defaults to all 8 if empty.
	Architectures []ArchKind

	// MaxTrials is the maximum number of (architecture, hyperparameter) trials.
	MaxTrials int

	// TrialsPerArch is the number of hyperparameter trials per architecture.
	// If zero, MaxTrials/len(Architectures) is used.
	TrialsPerArch int

	// Seed for reproducible search.
	Seed int64

	// TrainEpochs is the number of training epochs per trial.
	TrainEpochs int

	// ValidationSplit is the fraction of data to use for validation [0, 1).
	ValidationSplit float64
}

AutoMLConfig configures the AutoML search.

type BayesianOptimizer

type BayesianOptimizer struct {
	// contains filtered or unexported fields
}

BayesianOptimizer performs Bayesian hyperparameter optimization using random exploration followed by Expected Improvement over a surrogate.

func NewBayesianOptimizer

func NewBayesianOptimizer(params []HParam, seed int64) *BayesianOptimizer

NewBayesianOptimizer creates a new optimizer for the given hyperparameters.

func (*BayesianOptimizer) BestTrial

func (bo *BayesianOptimizer) BestTrial() (Trial, bool)

BestTrial returns the completed trial with the highest score. If no trials have been completed, ok is false.

func (*BayesianOptimizer) Report

func (bo *BayesianOptimizer) Report(trialID int, score float64) error

Report records the score for a completed trial.

func (*BayesianOptimizer) Suggest

func (bo *BayesianOptimizer) Suggest() (int, map[string]float64)

Suggest returns the next trial ID and a suggested parameter configuration. The first few trials use random sampling; subsequent trials use Expected Improvement approximation over random candidates.

func (*BayesianOptimizer) Trials

func (bo *BayesianOptimizer) Trials() []Trial

Trials returns all trials in creation order.

type BestModel added in v1.8.0

type BestModel struct {
	Architecture ArchKind
	Params       map[string]float64
	// Predictor wraps the underlying model's Predict method.
	Predictor func(features []float64) (tabular.Direction, float64, error)
}

BestModel wraps the winning model with its configuration.

func (*BestModel) Predict added in v1.8.0

func (b *BestModel) Predict(features []float64) (tabular.Direction, float64, error)

Predict delegates to the underlying model.

type Config

type Config struct {
	Params map[string]float64
}

Config holds a hyperparameter configuration for a single trial.

type Coordinator

type Coordinator struct {
	// contains filtered or unexported fields
}

Coordinator orchestrates the AutoML search loop, dispatching trials to a Worker and collecting results.

func NewCoordinator

func NewCoordinator(config CoordinatorConfig, worker Worker) (*Coordinator, error)

NewCoordinator creates a coordinator with the given configuration and worker.

func (*Coordinator) Best

func (c *Coordinator) Best() (TrialResult, bool)

Best returns the best trial result, or false if none succeeded.

func (*Coordinator) Results

func (c *Coordinator) Results() []TrialResult

Results returns all trial results collected so far.

func (*Coordinator) Run

func (c *Coordinator) Run() (TrialResult, error)

Run executes the AutoML loop, running up to MaxTrials trials. It returns the best trial result found, or an error if no trials succeeded.

func (*Coordinator) String

func (c *Coordinator) String() string

String returns a summary of the coordinator state.

type CoordinatorConfig

type CoordinatorConfig struct {
	// Space defines the hyperparameter search space.
	Space SearchSpace

	// Strategy is the search strategy (Bayesian, random, etc.).
	Strategy Strategy

	// MaxTrials is the maximum number of trials to run.
	MaxTrials int

	// EarlyStopPatience is the number of trials without improvement
	// before stopping early. Zero disables early stopping.
	EarlyStopPatience int
}

CoordinatorConfig configures the AutoML loop coordinator.

type HParam

type HParam struct {
	Name  string
	Min   float64
	Max   float64
	IsLog bool // if true, optimize in log space
}

HParam describes a single hyperparameter to optimize.

type Metric

type Metric struct {
	Score float64
}

Metric holds the result of evaluating a trial configuration.

type PBT

type PBT struct {
	// contains filtered or unexported fields
}

PBT implements Population-Based Training (Jaderberg et al. 2017).

func NewPBT

func NewPBT(config PBTConfig) *PBT

NewPBT creates a PBT runner with the given configuration.

func (*PBT) Run

func (pbt *PBT) Run() PBTResult

Run executes the PBT loop and returns the result.

type PBTConfig

type PBTConfig struct {
	// Params defines the hyperparameter search space.
	Params []HParam

	// PopulationSize is the number of agents (default 8).
	PopulationSize int

	// Generations is the number of exploit-explore cycles (default 10).
	Generations int

	// Objective evaluates a hyperparameter config and optional model weights,
	// returning (score, updated_weights). Higher scores are better.
	// Weights may be nil on first call; the function should initialize them.
	Objective func(params map[string]float64, weights []float64) (float64, []float64)

	// Seed for the random number generator.
	Seed int64

	// ExploitFrac is the fraction of the population considered top/bottom
	// for exploit (default 0.2, meaning top 20% replaces bottom 20%).
	ExploitFrac float64

	// PerturbFactors defines the multiplicative perturbation range [low, high]
	// applied during exploration (default [0.8, 1.2]).
	PerturbFactors [2]float64
}

PBTConfig configures population-based training.

type PBTResult

type PBTResult struct {
	BestAgent       Agent
	FinalPopulation []Agent
	Generations     int
}

PBTResult contains the outcome of a PBT run.

type RandomStrategy

type RandomStrategy struct {
	// contains filtered or unexported fields
}

RandomStrategy implements a simple random search strategy.

func NewRandomStrategy

func NewRandomStrategy(params []HParam, seed int64) *RandomStrategy

NewRandomStrategy creates a random search strategy (uses BayesianOptimizer with forced exploration by never exceeding the exploration threshold).

func (*RandomStrategy) BestTrial

func (rs *RandomStrategy) BestTrial() (Trial, bool)

BestTrial returns the best completed trial.

func (*RandomStrategy) Report

func (rs *RandomStrategy) Report(trialID int, score float64) error

Report records a trial score.

func (*RandomStrategy) Suggest

func (rs *RandomStrategy) Suggest() (int, map[string]float64)

Suggest returns the next random parameter configuration.

type SearchReport added in v1.8.0

type SearchReport struct {
	Trials     []ArchResult
	BestArch   ArchKind
	BestParams map[string]float64
	BestScore  float64
}

SearchReport contains all evaluated trials and the best result.

type SearchSpace

type SearchSpace struct {
	Params []HParam
}

SearchSpace defines the hyperparameter ranges to explore.

type Strategy

type Strategy interface {
	Suggest() (int, map[string]float64)
	Report(trialID int, score float64) error
	BestTrial() (Trial, bool)
}

Strategy suggests and reports trials. Both BayesianOptimizer and random search implement this interface.

type Trial

type Trial struct {
	ID     int
	Params map[string]float64
	Score  float64
	Done   bool
}

Trial records one evaluation of a hyperparameter configuration.

type TrialResult

type TrialResult struct {
	TrialID int
	Config  Config
	Metric  Metric
	Err     error
}

TrialResult records the outcome of a single trial.

type Worker

type Worker interface {
	RunTrial(config Config) (Metric, error)
}

Worker executes a trial with a given configuration and returns the metric.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL