Fit skeleton
This commit is contained in:
@@ -76,7 +76,7 @@ func (def *Definition) Grow(statusChan chan<- Status) (*vm.Program, error) {
|
|||||||
|
|
||||||
Mutate(def, prog)
|
Mutate(def, prog)
|
||||||
|
|
||||||
scores, err := def.score(prog)
|
scores, err := def.Score(prog)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Can never get best score
|
// Can never get best score
|
||||||
continue
|
continue
|
||||||
@@ -104,23 +104,7 @@ func (def *Definition) Grow(statusChan chan<- Status) (*vm.Program, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (def *Definition) buildSampleRanks() {
|
func (def *Definition) GetOutputs(prog *vm.Program) ([][]uint64, error) {
|
||||||
for col := 0; col < len(def.Samples[0].Out); col++ {
|
|
||||||
rank := []int{}
|
|
||||||
|
|
||||||
for i := 0; i < len(def.Samples); i++ {
|
|
||||||
rank = append(rank, i)
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.SliceStable(rank, func(i, j int) bool {
|
|
||||||
return def.Samples[i].Out[col] < def.Samples[j].Out[col]
|
|
||||||
})
|
|
||||||
|
|
||||||
def.SampleRanks = append(def.SampleRanks, rank)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (def *Definition) score(prog *vm.Program) ([]*Score, error) {
|
|
||||||
outputs := [][]uint64{}
|
outputs := [][]uint64{}
|
||||||
|
|
||||||
for _, sample := range def.Samples {
|
for _, sample := range def.Samples {
|
||||||
@@ -144,16 +128,25 @@ func (def *Definition) score(prog *vm.Program) ([]*Score, error) {
|
|||||||
outputs = append(outputs, output)
|
outputs = append(outputs, output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return outputs, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (def *Definition) Score(prog *vm.Program) ([]*Score, error) {
|
||||||
|
outputs, err := def.GetOutputs(prog)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Points for proximity to target values?
|
// TODO: Points for proximity to target values?
|
||||||
// TODO: Points for correlation coeficient with target values across samples?
|
// TODO: Points for correlation coeficient with target values across samples?
|
||||||
|
|
||||||
return []*Score{
|
return []*Score{
|
||||||
def.scoreMatching(outputs),
|
def.ScoreMatching(outputs),
|
||||||
def.scoreRank(outputs),
|
def.ScoreRank(outputs),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (def *Definition) scoreMatching(outputs [][]uint64) *Score {
|
func (def *Definition) ScoreMatching(outputs [][]uint64) *Score {
|
||||||
ret := &Score{}
|
ret := &Score{}
|
||||||
|
|
||||||
for s, sample := range def.Samples {
|
for s, sample := range def.Samples {
|
||||||
@@ -169,7 +162,7 @@ func (def *Definition) scoreMatching(outputs [][]uint64) *Score {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (def *Definition) scoreRank(outputs [][]uint64) *Score {
|
func (def *Definition) ScoreRank(outputs [][]uint64) *Score {
|
||||||
ranks := [][]int{}
|
ranks := [][]int{}
|
||||||
|
|
||||||
for col := 0; col < len(outputs[0]); col++ {
|
for col := 0; col < len(outputs[0]); col++ {
|
||||||
@@ -201,6 +194,22 @@ func (def *Definition) scoreRank(outputs [][]uint64) *Score {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (def *Definition) buildSampleRanks() {
|
||||||
|
for col := 0; col < len(def.Samples[0].Out); col++ {
|
||||||
|
rank := []int{}
|
||||||
|
|
||||||
|
for i := 0; i < len(def.Samples); i++ {
|
||||||
|
rank = append(rank, i)
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.SliceStable(rank, func(i, j int) bool {
|
||||||
|
return def.Samples[i].Out[col] < def.Samples[j].Out[col]
|
||||||
|
})
|
||||||
|
|
||||||
|
def.SampleRanks = append(def.SampleRanks, rank)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (def *Definition) scoreIsBetter(old, new []*Score) bool {
|
func (def *Definition) scoreIsBetter(old, new []*Score) bool {
|
||||||
if old == nil {
|
if old == nil {
|
||||||
return true
|
return true
|
||||||
@@ -247,7 +256,7 @@ func (def *Definition) minifyProgram(prog *vm.Program) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (def *Definition) minifyFunction(prog *vm.Program, f int) error {
|
func (def *Definition) minifyFunction(prog *vm.Program, f int) error {
|
||||||
baseScores, err := def.score(prog)
|
baseScores, err := def.Score(prog)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -262,7 +271,7 @@ func (def *Definition) minifyFunction(prog *vm.Program, f int) error {
|
|||||||
copy(tmp, prog.Functions[f].Instructions)
|
copy(tmp, prog.Functions[f].Instructions)
|
||||||
prog.Functions[f].Instructions = append(tmp[:i], tmp[i+1:]...)
|
prog.Functions[f].Instructions = append(tmp[:i], tmp[i+1:]...)
|
||||||
|
|
||||||
newScores, err := def.score(prog)
|
newScores, err := def.Score(prog)
|
||||||
// XXX: Use all scores
|
// XXX: Use all scores
|
||||||
if err == nil && newScores[0].Current >= baseScores[0].Current {
|
if err == nil && newScores[0].Current >= baseScores[0].Current {
|
||||||
loop = true
|
loop = true
|
||||||
|
|||||||
10
grow/fit/config.go
Normal file
10
grow/fit/config.go
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "github.com/firestuff/subcoding/grow"
|
||||||
|
import "github.com/firestuff/subcoding/vm"
|
||||||
|
|
||||||
|
type Config struct {
|
||||||
|
Definition *grow.Definition `yaml:"definition"`
|
||||||
|
|
||||||
|
Programs map[string]*vm.Program `yaml:"programs"`
|
||||||
|
}
|
||||||
13
grow/fit/main.go
Normal file
13
grow/fit/main.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "flag"
|
||||||
|
import "log"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
confPath := flag.String("conf-path", "", "path to config YAML file")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
|
if *confPath == "" {
|
||||||
|
log.Fatal("Please specify --conf-path")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user