Ejemplo n.º 1
0
Archivo: kh.py Proyecto: sisco0/NiaPy
    def funX(self, x, y):
        r"""Get x values.

		Args:
			x (numpy.ndarray): First krill/individual.
			y (numpy.ndarray): Second krill/individual.

		Returns:
			numpy.ndarray: --
		"""
        return ((y - x) + self.epsilon) / (euclidean(y, x) + self.epsilon)
Ejemplo n.º 2
0
Archivo: kh.py Proyecto: sisco0/NiaPy
    def sensRange(self, ki, KH):
        r"""Calculate sense range for selected individual.

		Args:
			ki (int): Selected individual.
			KH (numpy.ndarray): Krill heard population.

		Returns:
			float: Sense range for krill.
		"""
        return np.sum([euclidean(KH[ki], KH[i])
                       for i in range(self.NP)]) / (self.nn * self.NP)
Ejemplo n.º 3
0
Archivo: kh.py Proyecto: sisco0/NiaPy
    def getNeighbours(self, i, ids, KH):
        r"""Get neighbours.

		Args:
			i (int): Individual looking for neighbours.
			ids (float): Maximal distance for being a neighbour.
			KH (numpy.ndarray): Current population.

		Returns:
			numpy.ndarray: Neighbours of krill heard.
		"""
        N = list()
        for j in range(self.NP):
            if j != i and ids > euclidean(KH[i], KH[j]): N.append(j)
        if not N: N.append(self.integers(self.NP))
        return np.asarray(N)
Ejemplo n.º 4
0
Archivo: gso.py Proyecto: sisco0/NiaPy
    def initPopulation(self, task):
        r"""Initialize population.

		Args:
			task (Task): Optimization task.

		Returns:
			Tuple[numpy.ndarray, numpy.ndarray[float], Dict[str, Any]]:
				1. Initialized population of glowwarms.
				2. Initialized populations function/fitness values.
				3. Additional arguments:
					* L (numpy.ndarray): TODO.
					* R (numpy.ndarray): TODO.
					* rs (numpy.ndarray): TODO.
		"""
        GS, GS_f, d = Algorithm.initPopulation(self, task)
        rs = euclidean(np.zeros(task.D), task.bRange)
        L, R = np.full(self.NP, self.l0), np.full(self.NP, rs)
        d.update({'L': L, 'R': R, 'rs': rs})
        return GS, GS_f, d
Ejemplo n.º 5
0
Archivo: de.py Proyecto: sisco0/NiaPy
    def selection(self, pop, npop, xb, fxb, task, **kwargs):
        r"""Operator for selection of individuals.

		Args:
			pop (numpy.ndarray): Current population.
			npop (numpy.ndarray): New population.
			xb (numpy.ndarray): Current global best solution.
			fxb (float): Current global best solutions fitness/objective value.
			task (Task): Optimization task.
			kwargs (Dict[str, Any]): Additional arguments.

		Returns:
			Tuple[numpy.ndarray, numpy.ndarray, float]:
				1. New population.
				2. New global best solution.
				3. New global best solutions fitness/objective value.
		"""
        P = []
        for e in npop:
            i = np.argmin([euclidean(e, f) for f in pop])
            P.append(pop[i] if pop[i].f < e.f else e)
        return np.asarray(P), xb, fxb