def _eval_sfun(self, ngen=1): """Run DE for a function that takes a single pv as an input and retuns a single value.""" popc, fitc = self._population, self._fitness popt, fitt = self._trial_pop, self._trial_fit for ipop in xrange(self.n_pop): fitc[ipop] = self.m * self.minfun(popc[ipop,:]) for igen in xrange(ngen): popt[:,:] = de_f.evolve_population(popc, self.F, self.C) for ipop in xrange(self.n_pop): fitt[ipop] = self.m * self.minfun(popt[ipop,:]) msk = fitt < fitc popc[msk,:] = popt[msk,:] fitc[msk] = fitt[msk] self._minidx = np.argmin(fitc) yield popc[self._minidx,:], fitc[self._minidx]
def _eval_sfun(self, ngen=1): """Run DE for a function that takes a single pv as an input and retuns a single value.""" popc, fitc = self._population, self._fitness popt, fitt = self._trial_pop, self._trial_fit for ipop in xrange(self.n_pop): fitc[ipop] = self.m * self.minfun(popc[ipop, :]) for igen in xrange(ngen): popt[:, :] = de_f.evolve_population(popc, self.F, self.C) for ipop in xrange(self.n_pop): fitt[ipop] = self.m * self.minfun(popt[ipop, :]) msk = fitt < fitc popc[msk, :] = popt[msk, :] fitc[msk] = fitt[msk] self._minidx = np.argmin(fitc) yield popc[self._minidx, :], fitc[self._minidx]
def _eval_vfun(self, ngen=1): """Run DE for a function that takes the whole population as an input and retuns a value for each pv.""" popc, fitc = self._population, self._fitness popt, fitt = self._trial_pop, self._trial_fit fitc[:] = self.m * self.minfun(self._population) for igen in xrange(ngen): x = float(ngen - igen) / float(ngen) self.F = np.random.uniform(0.25, 0.75) self.C = x * self.cmax + (1 - x) * self.cmin popt[:, :] = de_f.evolve_population(popc, self.F, self.C) fitt[:] = self.m * self.minfun(popt) msk = fitt < fitc popc[msk, :] = popt[msk, :] fitc[msk] = fitt[msk] self._minidx = np.argmin(fitc) yield popc[self._minidx, :], fitc[self._minidx]
def _eval_vfun(self, ngen=1): """Run DE for a function that takes the whole population as an input and retuns a value for each pv.""" popc, fitc = self._population, self._fitness popt, fitt = self._trial_pop, self._trial_fit fitc[:] = self.m * self.minfun(self._population) for igen in xrange(ngen): x = float(ngen-igen)/float(ngen) self.F = np.random.uniform(0.25,0.75) self.C = x*self.cmax + (1-x)*self.cmin popt[:,:] = de_f.evolve_population(popc, self.F, self.C) fitt[:] = self.m * self.minfun(popt) msk = fitt < fitc popc[msk,:] = popt[msk,:] fitc[msk] = fitt[msk] self._minidx = np.argmin(fitc) yield popc[self._minidx,:], fitc[self._minidx]