-
Notifications
You must be signed in to change notification settings - Fork 203
/
Copy pathsettings.go
64 lines (55 loc) · 1.6 KB
/
settings.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package pso
const pso_max_size int = 100
const pso_inertia float64 = 0.7298 // default value of w (see clerc02)
type SwarmSettings struct {
FunctionName string
function ObjectiveFunction // lower case to avoid data converter export
// swarm size (number of particles)
Size int
// ... N steps (set to 0 for no output)
PrintEvery int
// Steps after issuing a ContinueAsNew, to reduce history size
ContinueAsNewEvery int
// maximum number of iterations
Steps int
// cognitive coefficient
C1 float64
// social coefficient
C2 float64
// max inertia weight value
InertiaMax float64
// min inertia weight value
InertiaMin float64
// whether to keep particle position within defined bounds (TRUE)
// or apply periodic boundary conditions (FALSE)
ClampPosition bool
Inertia float64 // current inertia weight value
}
func FunctionFactory(functionName string) ObjectiveFunction {
var function ObjectiveFunction
switch functionName {
case "sphere":
function = Sphere
case "rosenbrock":
function = Rosenbrock
case "griewank":
function = Griewank
}
return function
}
func PSODefaultSettings(functionName string) *SwarmSettings {
settings := new(SwarmSettings)
settings.FunctionName = functionName
settings.function = FunctionFactory(functionName)
settings.Size = CalculateSwarmSize(settings.function.dim, pso_max_size)
settings.PrintEvery = 10
settings.ContinueAsNewEvery = 10
settings.Steps = 100000
settings.C1 = 1.496
settings.C2 = 1.496
settings.InertiaMax = pso_inertia
settings.InertiaMin = 0.3
settings.Inertia = settings.InertiaMax
settings.ClampPosition = true
return settings
}