Beispiel #1
0
func swarmsolver(fn bench.Func, db *sql.DB, n int) optim.Method {
	low, up := fn.Bounds()

	if n < 0 {
		n = 30 + 1*len(low)
		if n > maxeval/500 {
			n = maxeval / 500
		}
	}

	return swarm.New(
		swarm.NewPopulationRand(n, low, up),
		swarm.VmaxBounds(fn.Bounds()),
		swarm.DB(db),
	)
}
Beispiel #2
0
func buildIter(lb, ub []float64) optim.Method {
	mask := make([]bool, len(ub))
	for i := range mask {
		mask[i] = lb[i] < ub[i]
	}

	n := 30 + 1*len(lb)
	if *npar != 0 {
		n = *npar
	} else if n < 30 {
		n = 30
	}

	fmt.Printf("swarming with %v particles\n", n)

	ev := optim.ParallelEvaler{}
	if *addr == "" {
		ev.NConcurrent = *ncpu
	}

	pop := swarm.NewPopulationRand(n, lb, ub)
	swarm := swarm.New(
		pop,
		swarm.Evaler(ev),
		swarm.VmaxBounds(lb, ub),
		swarm.DB(db),
	)

	if *swarmonly {
		return swarm
	} else {
		return pattern.New(pop[0].Point,
			pattern.ResetStep(.01, 1.0),
			pattern.NsuccessGrow(4),
			pattern.Evaler(ev),
			pattern.PollRandNMask(n, mask),
			pattern.SearchMethod(swarm, pattern.Share),
			pattern.DB(db),
		)
	}
}