Documentation
¶
Overview ¶
A library to help implement solvers and problems of kurobako.
kurobako is a black-box optimization tool. Please see https://github.com/sile/kurobako for the details.
Index ¶
- Variables
- type Capabilities
- type CategoricalRange
- type ContinuousRange
- type DiscreteRange
- type Distribution
- type EvaluatedTrial
- type Evaluator
- type NextTrial
- type Problem
- type ProblemFactory
- type ProblemRunner
- type ProblemSpec
- type Range
- func (r *Range) AsCategoricalRange() *CategoricalRange
- func (r *Range) AsContinuousRange() *ContinuousRange
- func (r *Range) AsDiscreteRange() *DiscreteRange
- func (r *Range) High() float64
- func (r *Range) Low() float64
- func (r Range) MarshalJSON() ([]byte, error)
- func (r *Range) UnmarshalJSON(data []byte) error
- type Solver
- type SolverFactory
- type SolverRunner
- type SolverSpec
- type Steps
- type TrialIDGenerator
- type Var
Constants ¶
This section is empty.
Variables ¶
var ErrorUnevalableParams = errors.New("unevalable params")
ErrorUnevalableParams is an error that is used when an evaluator encounters an infeasible parameter set.
Functions ¶
This section is empty.
Types ¶
type Capabilities ¶
type Capabilities int64
Capabilities of a solver.
const ( // UniformContinuous indicates that the solver can handle numerical parameters that have uniform continuous range. UniformContinuous Capabilities = 1 << iota // UniformDiscrete indicates that the solver can handle numerical parameters that have uniform discrete range. UniformDiscrete // LogUniformContinuous indicates that the solver can handle numerical parameters that have log-uniform continuous range. LogUniformContinuous // LogUniformDiscrete indicates that the solver can handle numerical parameters that have log-uniform discrete range. LogUniformDiscrete // Categorical indicates that the solver can handle categorical parameters. Categorical // Conditional indicates that the solver can handle conditional parameters. Conditional // MultiObjective indicates that the solver supports multi-objective optimization. MultiObjective // Concurrent indicates that the solver supports concurrent invocations of the ask method. Concurrent // AllCapabilities represents all of the capabilities. AllCapabilities Capabilities = UniformContinuous | UniformDiscrete | LogUniformContinuous | LogUniformDiscrete | Categorical | Conditional | MultiObjective | Concurrent )
func (Capabilities) MarshalJSON ¶
func (r Capabilities) MarshalJSON() ([]byte, error)
MarshalJSON encodes a Capabilities value to JSON bytes.
func (*Capabilities) UnmarshalJSON ¶
func (r *Capabilities) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes a Capabilities value from JSON bytes.
type CategoricalRange ¶
type CategoricalRange struct {
// Choices is the possible values in the range.
Choices []string `json:"choices"`
}
CategoricalRange represents a categorical range (choices).
func (CategoricalRange) ToRange ¶
func (r CategoricalRange) ToRange() Range
ToRange creates a Range object that contains the receiver object.
type ContinuousRange ¶
type ContinuousRange struct {
// Low is the lower bound of the range (inclusive).
Low float64 `json:"low"`
// High is the upper bound of the range (exclusive).
High float64 `json:"high"`
}
ContinuousRange represents a numerical continuous range.
func (ContinuousRange) MarshalJSON ¶
func (r ContinuousRange) MarshalJSON() ([]byte, error)
MarshalJSON encodes a ContinuousRange object to JSON bytes.
func (ContinuousRange) ToRange ¶
func (r ContinuousRange) ToRange() Range
ToRange creates a Range object that contains the receiver object.
func (*ContinuousRange) UnmarshalJSON ¶
func (r *ContinuousRange) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes a ContinuousRange object from JSON bytes.
type DiscreteRange ¶
type DiscreteRange struct {
// Low is the lower bound of the range (inclusive).
Low int64 `json:"low"`
// High is the upper bound of the range (exclusive).
High int64 `json:"high"`
}
DiscreteRange represents a numerical discrete range.
func (DiscreteRange) ToRange ¶
func (r DiscreteRange) ToRange() Range
ToRange create a Range object that contains the receiver object.
type Distribution ¶
type Distribution int
Distribution of the values of a parameter.
const ( // Uniform indicates the values of the parameter are uniformally distributed. Uniform Distribution = iota // LogUniform indicates the values of the parameter are log-uniformally distributed. LogUniform )
func (Distribution) MarshalJSON ¶
func (r Distribution) MarshalJSON() ([]byte, error)
MarshalJSON encodes a Distribution value to JSON bytes.
func (Distribution) String ¶
func (r Distribution) String() string
String returns the string representation of a Distribution value.
func (*Distribution) UnmarshalJSON ¶
func (r *Distribution) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes a Distribution value from JSON bytes.
type EvaluatedTrial ¶
type EvaluatedTrial struct {
// TrialID is the identifier of the trial.
TrialID uint64 `json:"id"`
// Values is the evaluation result of the trial.
//
// Note that if this is an empty slice, it means the trial contained an unevalable parameter set.
Values []float64 `json:"values"`
// CurrentStep is the current step of the evaluation process.
CurrentStep uint64 `json:"current_step"`
}
EvaluatedTrial contains information about an evaluated trial.
type Evaluator ¶
type Evaluator interface {
// evaluate executes an evaluation process, at least, until the given step.
Evaluate(nextStep uint64) (currentStep uint64, values []float64, err error)
}
Evaluator allows to execute an evaluation process.
type NextTrial ¶
type NextTrial struct {
// TrialID is the identifier of the trial.
TrialID uint64 `json:"id"`
// Params are the parameters to be evaluated.
Params []*float64 `json:"params"`
// NextStep is the next evaluable step.
//
// The evaluator must go through the next evaluation process beyond this step.
// Note that if the value is 0, it means the trial was pruned by solver.
NextStep uint64 `json:"next_step"`
}
NextTrial contains information about a trial to be evaluated.
func (NextTrial) MarshalJSON ¶
MarshalJSON encodes a NextTrial object to JSON bytes.
type Problem ¶
type Problem interface {
// CreateEvaluator creates a new evaluator to evaluate the given parameter set.
CreateEvaluator(params []float64) (Evaluator, error)
}
Problem allows to create a new evaluator instance.
type ProblemFactory ¶
type ProblemFactory interface {
// Specification returns the specification of the problem.
Specification() (*ProblemSpec, error)
// CreateProblem creates a new problem instance with the given random seed.
CreateProblem(seed int64) (Problem, error)
}
ProblemFactory allows to create a new problem instance.
type ProblemRunner ¶
type ProblemRunner struct {
// contains filtered or unexported fields
}
ProblemRunner runs a black-box optimization problem.
func NewProblemRunner ¶
func NewProblemRunner(factory ProblemFactory) *ProblemRunner
NewProblemRunner creates a new ProblemRunner that runs the given problem.
type ProblemSpec ¶
type ProblemSpec struct {
// Name is the name of the problem.
Name string `json:"name"`
// Attrs is the attributes of the problem.
Attrs map[string]string `json:"attrs"`
// Params is the definition of the parameters domain of the problem.
Params []Var `json:"params_domain"`
// Values is the definition of the values domain of the problem.
Values []Var `json:"values_domain"`
// Steps is the sequence of the evaluation steps of the problem.
Steps Steps `json:"steps"`
}
ProblemSpec is the specification of a black-box optimization problem.
func NewProblemSpec ¶
func NewProblemSpec(name string) ProblemSpec
NewProblemSpec creates a new ProblemSpec instance.
type Range ¶
type Range struct {
// contains filtered or unexported fields
}
Range represents the range of a parameter.
func (*Range) AsCategoricalRange ¶
func (r *Range) AsCategoricalRange() *CategoricalRange
AsCategoricalRange tries to return the inner object of the range as a CategoricalRange object.
func (*Range) AsContinuousRange ¶
func (r *Range) AsContinuousRange() *ContinuousRange
AsContinuousRange tries to return the inner object of the range as a ContinuousRange object.
func (*Range) AsDiscreteRange ¶
func (r *Range) AsDiscreteRange() *DiscreteRange
AsDiscreteRange tries to return the inner object of the range as a DiscreteRange object.
func (Range) MarshalJSON ¶
MarshalJSON encodes a range object to JSON bytes.
func (*Range) UnmarshalJSON ¶
UnmarshalJSON decodes a Range object from JSON bytes.
type Solver ¶
type Solver interface {
// Ask returns a NextTrial object that contains information about the next trial to be evaluated.
Ask(idg *TrialIDGenerator) (NextTrial, error)
// Tell takes an evaluation result of a trial and updates the state of the solver.
Tell(trial EvaluatedTrial) error
}
Solver interface.
type SolverFactory ¶
type SolverFactory interface {
// Specification returns the specification of the solver.
Specification() (*SolverSpec, error)
// CreateSolver creates a new solver instance with the given random seed.
//
// The created solver will be used to solve a black-box optimization problem defined by the given ProblemSpec.
CreateSolver(seed int64, problem ProblemSpec) (Solver, error)
}
SolverFactory allows to create a new solver instance.
type SolverRunner ¶
type SolverRunner struct {
// contains filtered or unexported fields
}
SolverRunner runs a solver.
func NewSolverRunner ¶
func NewSolverRunner(factory SolverFactory) *SolverRunner
NewSolverRunner creates a new SolverRunner instance that handles the given solver.
type SolverSpec ¶
type SolverSpec struct {
// Name is the name of the solver.
Name string `json:"name"`
// Attrs is the attributes of the solver.
Attrs map[string]string `json:"attrs"`
// Capabilities is the capabilities of the solver.
Capabilities Capabilities `json:"capabilities"`
}
SolverSpec is the specification of a solver.
func NewSolverSpec ¶
func NewSolverSpec(name string) SolverSpec
NewSolverSpec creates a new SolverSpec instance.
type Steps ¶
type Steps struct {
// contains filtered or unexported fields
}
Steps represents a sequence of evaluable steps of a problem.
At each evaluable step, the evaluator of the problem can suspend the evaluation and return intermediate evaluation values at that step.
func (Steps) MarshalJSON ¶
MarshalJSON encodes a Steps object to JSON bytes.
func (*Steps) UnmarshalJSON ¶
UnmarshalJSON decodes a Steps object from JSON bytes.
type TrialIDGenerator ¶
type TrialIDGenerator struct {
NextID uint64
}
TrialIDGenerator generates identifiers of trials.
func (*TrialIDGenerator) Generate ¶
func (r *TrialIDGenerator) Generate() uint64
Generate creates a new trial identifier.
type Var ¶
type Var struct {
// Name is the name of the variable.
Name string `json:"name"`
// Range is the value range of the variable.
Range Range `json:"range"`
// Distribution is the value distribution of the variable.
Distribution Distribution `json:"distribution"`
// Constraint is the constraint of the variable.
//
// A constraint is represented by a Lua script.
// If the script returns true, it means the constraint is satisfied.
//
// If the constraint isn't satisfied, the variable won't be considered during the evaluation process.
Constraint *string `json:"constraint"`
}
Var is a definition of a variable.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
goptuna-solver
command
|
|
|
quadratic-problem
command
|
|
|
random-solver
command
|
|
|
goptuna
|
|
|
solver
This package provides a solver base on Goptuna.
|
This package provides a solver base on Goptuna. |