mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 01:01:56 +00:00
optimizer: refactor selector config types
This commit is contained in:
parent
4e14df443a
commit
f5d4fa098d
|
@ -10,6 +10,15 @@ import (
|
|||
"github.com/c9s/bbgo/pkg/fixedpoint"
|
||||
)
|
||||
|
||||
const (
|
||||
selectorTypeRange = "range" // deprecated: replaced by selectorTypeRangeFloat
|
||||
selectorTypeRangeFloat = "rangeFloat"
|
||||
selectorTypeRangeInt = "rangeInt"
|
||||
selectorTypeIterate = "iterate" // deprecated: replaced by selectorTypeString
|
||||
selectorTypeString = "string"
|
||||
selectorTypeBool = "bool"
|
||||
)
|
||||
|
||||
type SelectorConfig struct {
|
||||
Type string `json:"type" yaml:"type"`
|
||||
Label string `json:"label,omitempty" yaml:"label,omitempty"`
|
||||
|
|
|
@ -90,7 +90,7 @@ func (o *GridOptimizer) buildOps() []OpFunc {
|
|||
}
|
||||
|
||||
switch selector.Type {
|
||||
case "range":
|
||||
case selectorTypeRange, selectorTypeRangeFloat, selectorTypeRangeInt:
|
||||
min := selector.Min
|
||||
max := selector.Max
|
||||
step := selector.Step
|
||||
|
@ -129,7 +129,7 @@ func (o *GridOptimizer) buildOps() []OpFunc {
|
|||
}
|
||||
ops = append(ops, f)
|
||||
|
||||
case "iterate":
|
||||
case selectorTypeIterate, selectorTypeString:
|
||||
values := selector.Values
|
||||
f := func(configJson []byte, next func(configJson []byte) error) error {
|
||||
for _, val := range values {
|
||||
|
@ -158,7 +158,7 @@ func (o *GridOptimizer) buildOps() []OpFunc {
|
|||
return nil
|
||||
}
|
||||
ops = append(ops, f)
|
||||
case "bool":
|
||||
case selectorTypeBool:
|
||||
values := []bool{true, false}
|
||||
f := func(configJson []byte, next func(configJson []byte) error) error {
|
||||
for _, val := range values {
|
||||
|
|
|
@ -117,7 +117,7 @@ func (o *HyperparameterOptimizer) buildParamDomains() (map[string]string, []para
|
|||
for _, selector := range o.Config.Matrix {
|
||||
var domain paramDomain
|
||||
switch selector.Type {
|
||||
case "range", "rangeFloat":
|
||||
case selectorTypeRange, selectorTypeRangeFloat:
|
||||
domain = &floatRangeDomain{
|
||||
paramDomainBase: paramDomainBase{
|
||||
label: selector.Label,
|
||||
|
@ -126,7 +126,7 @@ func (o *HyperparameterOptimizer) buildParamDomains() (map[string]string, []para
|
|||
min: selector.Min.Float64(),
|
||||
max: selector.Max.Float64(),
|
||||
}
|
||||
case "rangeInt":
|
||||
case selectorTypeRangeInt:
|
||||
domain = &intRangeDomain{
|
||||
paramDomainBase: paramDomainBase{
|
||||
label: selector.Label,
|
||||
|
@ -135,7 +135,7 @@ func (o *HyperparameterOptimizer) buildParamDomains() (map[string]string, []para
|
|||
min: selector.Min.Int(),
|
||||
max: selector.Max.Int(),
|
||||
}
|
||||
case "iterate", "string":
|
||||
case selectorTypeIterate, selectorTypeString:
|
||||
domain = &stringDomain{
|
||||
paramDomainBase: paramDomainBase{
|
||||
label: selector.Label,
|
||||
|
@ -143,7 +143,7 @@ func (o *HyperparameterOptimizer) buildParamDomains() (map[string]string, []para
|
|||
},
|
||||
options: selector.Values,
|
||||
}
|
||||
case "bool":
|
||||
case selectorTypeBool:
|
||||
domain = &boolDomain{
|
||||
paramDomainBase: paramDomainBase{
|
||||
label: selector.Label,
|
||||
|
|
Loading…
Reference in New Issue
Block a user