mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-14 02:53:50 +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"
|
"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 SelectorConfig struct {
|
||||||
Type string `json:"type" yaml:"type"`
|
Type string `json:"type" yaml:"type"`
|
||||||
Label string `json:"label,omitempty" yaml:"label,omitempty"`
|
Label string `json:"label,omitempty" yaml:"label,omitempty"`
|
||||||
|
|
|
@ -90,7 +90,7 @@ func (o *GridOptimizer) buildOps() []OpFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch selector.Type {
|
switch selector.Type {
|
||||||
case "range":
|
case selectorTypeRange, selectorTypeRangeFloat, selectorTypeRangeInt:
|
||||||
min := selector.Min
|
min := selector.Min
|
||||||
max := selector.Max
|
max := selector.Max
|
||||||
step := selector.Step
|
step := selector.Step
|
||||||
|
@ -129,7 +129,7 @@ func (o *GridOptimizer) buildOps() []OpFunc {
|
||||||
}
|
}
|
||||||
ops = append(ops, f)
|
ops = append(ops, f)
|
||||||
|
|
||||||
case "iterate":
|
case selectorTypeIterate, selectorTypeString:
|
||||||
values := selector.Values
|
values := selector.Values
|
||||||
f := func(configJson []byte, next func(configJson []byte) error) error {
|
f := func(configJson []byte, next func(configJson []byte) error) error {
|
||||||
for _, val := range values {
|
for _, val := range values {
|
||||||
|
@ -158,7 +158,7 @@ func (o *GridOptimizer) buildOps() []OpFunc {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
ops = append(ops, f)
|
ops = append(ops, f)
|
||||||
case "bool":
|
case selectorTypeBool:
|
||||||
values := []bool{true, false}
|
values := []bool{true, false}
|
||||||
f := func(configJson []byte, next func(configJson []byte) error) error {
|
f := func(configJson []byte, next func(configJson []byte) error) error {
|
||||||
for _, val := range values {
|
for _, val := range values {
|
||||||
|
|
|
@ -117,7 +117,7 @@ func (o *HyperparameterOptimizer) buildParamDomains() (map[string]string, []para
|
||||||
for _, selector := range o.Config.Matrix {
|
for _, selector := range o.Config.Matrix {
|
||||||
var domain paramDomain
|
var domain paramDomain
|
||||||
switch selector.Type {
|
switch selector.Type {
|
||||||
case "range", "rangeFloat":
|
case selectorTypeRange, selectorTypeRangeFloat:
|
||||||
domain = &floatRangeDomain{
|
domain = &floatRangeDomain{
|
||||||
paramDomainBase: paramDomainBase{
|
paramDomainBase: paramDomainBase{
|
||||||
label: selector.Label,
|
label: selector.Label,
|
||||||
|
@ -126,7 +126,7 @@ func (o *HyperparameterOptimizer) buildParamDomains() (map[string]string, []para
|
||||||
min: selector.Min.Float64(),
|
min: selector.Min.Float64(),
|
||||||
max: selector.Max.Float64(),
|
max: selector.Max.Float64(),
|
||||||
}
|
}
|
||||||
case "rangeInt":
|
case selectorTypeRangeInt:
|
||||||
domain = &intRangeDomain{
|
domain = &intRangeDomain{
|
||||||
paramDomainBase: paramDomainBase{
|
paramDomainBase: paramDomainBase{
|
||||||
label: selector.Label,
|
label: selector.Label,
|
||||||
|
@ -135,7 +135,7 @@ func (o *HyperparameterOptimizer) buildParamDomains() (map[string]string, []para
|
||||||
min: selector.Min.Int(),
|
min: selector.Min.Int(),
|
||||||
max: selector.Max.Int(),
|
max: selector.Max.Int(),
|
||||||
}
|
}
|
||||||
case "iterate", "string":
|
case selectorTypeIterate, selectorTypeString:
|
||||||
domain = &stringDomain{
|
domain = &stringDomain{
|
||||||
paramDomainBase: paramDomainBase{
|
paramDomainBase: paramDomainBase{
|
||||||
label: selector.Label,
|
label: selector.Label,
|
||||||
|
@ -143,7 +143,7 @@ func (o *HyperparameterOptimizer) buildParamDomains() (map[string]string, []para
|
||||||
},
|
},
|
||||||
options: selector.Values,
|
options: selector.Values,
|
||||||
}
|
}
|
||||||
case "bool":
|
case selectorTypeBool:
|
||||||
domain = &boolDomain{
|
domain = &boolDomain{
|
||||||
paramDomainBase: paramDomainBase{
|
paramDomainBase: paramDomainBase{
|
||||||
label: selector.Label,
|
label: selector.Label,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user