Skip to content

Commit 9dd4931

Browse files
committed
latest
1 parent d0c2793 commit 9dd4931

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

mep.go

+14-9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ import (
1212
"time"
1313
)
1414

15+
// see: http://blog.loadimpact.com/random-thoughts-about-go
16+
func intn(max int) int {
17+
return int((rand.Float64() * float64(max)) + 0.5)
18+
}
19+
1520
// FitnessFunction -
1621
type FitnessFunction func(signal, target []float64) float64
1722

@@ -483,7 +488,7 @@ func (m *Mep) Best() (float64, string) {
483488
// PrintBest - print the best member of the population
484489
func (m *Mep) PrintBest() {
485490
exp := m.parse("", m.pop[m.bestPop][0], m.pop[m.bestPop][0].bestIndex)
486-
fmt.Printf("fitness = %f, expr='%s'\n", m.pop[m.bestPop][0].fitness, exp)
491+
fmt.Printf("expr='%s' # fitness = %f\n", exp, m.pop[m.bestPop][0].fitness)
487492
}
488493

489494
// PrintTestData - print the testdata
@@ -616,31 +621,31 @@ func (m *Mep) eval(results [][]float64, c *chromosome) {
616621
if results[c.program[i].adr1][k] > results[c.program[i].adr2][k] {
617622
results[i][k] = 1.0
618623
} else {
619-
results[i][k] = -1.0
624+
results[i][k] = 0.0
620625
}
621626
}
622627
case -19: // ifblt
623628
for k := 0; k < m.numTraining; k++ {
624629
if results[c.program[i].adr1][k] < results[c.program[i].adr2][k] {
625630
results[i][k] = 1.0
626631
} else {
627-
results[i][k] = -1.0
632+
results[i][k] = 0.0
628633
}
629634
}
630635
case -20: // and
631636
for k := 0; k < m.numTraining; k++ {
632637
if results[c.program[i].adr1][k] > 0.0 && results[c.program[i].adr2][k] > 0.0 {
633638
results[i][k] = 1.0
634639
} else {
635-
results[i][k] = -1.0
640+
results[i][k] = 0.0
636641
}
637642
}
638643
case -21: // or
639644
for k := 0; k < m.numTraining; k++ {
640645
if results[c.program[i].adr1][k] > 0.0 || results[c.program[i].adr2][k] > 0.0 {
641646
results[i][k] = 1.0
642647
} else {
643-
results[i][k] = -1.0
648+
results[i][k] = 0.0
644649
}
645650
}
646651
case -22: // pow
@@ -835,28 +840,28 @@ func (m *Mep) parse(exp string, individual chromosome, poz int) string {
835840
exp = m.parse(exp, individual, adr1)
836841
exp += ">"
837842
exp = m.parse(exp, individual, adr2)
838-
exp += "1,-1)"
843+
exp += ",1,0)"
839844

840845
} else if op == -19 { // ifblt
841846
exp += "iif("
842847
exp = m.parse(exp, individual, adr1)
843848
exp += "<"
844849
exp = m.parse(exp, individual, adr2)
845-
exp += "1,-1)"
850+
exp += ",1,0)"
846851

847852
} else if op == -20 { // and
848853
exp += "iif("
849854
exp = m.parse(exp, individual, adr1)
850855
exp += ">0 &&"
851856
exp = m.parse(exp, individual, adr2)
852-
exp += ">0,1,-1)"
857+
exp += ">0,1,0)"
853858

854859
} else if op == -21 { // or
855860
exp += "iif("
856861
exp = m.parse(exp, individual, adr1)
857862
exp += ">0 ||"
858863
exp = m.parse(exp, individual, adr2)
859-
exp += ">0,1,-1)"
864+
exp += ">0,1,0)"
860865

861866
} else if op == -22 { // pow
862867
exp += "pow("

mep/main.go

+6
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ import (
3434
"flag"
3535
"fmt"
3636
"github.com/markcheno/go-mep"
37+
"log"
3738
"math"
3839
"math/rand"
40+
"net/http"
41+
_ "net/http/pprof"
3942
"os"
4043
"strconv"
4144
"strings"
@@ -67,6 +70,9 @@ type mepFlags struct {
6770

6871
func main() {
6972

73+
go func() {
74+
log.Println(http.ListenAndServe("localhost:6060", nil))
75+
}()
7076
var flags mepFlags
7177

7278
flag.IntVar(&flags.subPopSize, "popsize", 100, "sets sub-population size (default=100)")

0 commit comments

Comments
 (0)