-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
49 lines (42 loc) · 1.25 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"encoding/json"
"io"
"os"
)
// Config is a container for all configurations of microbial Genetic
// Algorithm (mGA) and DPPN. It is initialized via importing a JSON file.
type Configuration struct {
// Random Seed
Seed int64
// mGA configurations
NumInputs int // number of inputs
NumOutputs int // number of outputs
NumInitHidden int // number of initial hidden nodes
PopulationSize int // population size
NumTournaments int // number of tournaments
MutAddNodeRate float64 // mutation rate for adding an node
MutAddEdgeRate float64 // mutation rate for adding an edge
CrossoverRate float64 // crossover rate
// DPPN configurations
NumEpochs int // number of training epochs
BatchSize int // size of each training batch
LearningRate float64 // learning rate (alpha)
}
// NewConfiguration creates a new configuration struct given a JSON filename.
func NewConfiguration(filename string) (*Configuration, error) {
// import configuration
f, err := os.Open(filename)
if err != nil {
return nil, err
}
defer f.Close()
dec := json.NewDecoder(f)
var config Configuration
if err := dec.Decode(&config); err != nil {
if err != io.EOF {
return nil, err
}
}
return &config, nil
}