def main():
    initial = np.array(list(product([0, 1, -1], [0, 1, -1])))[1:]
    initial = normalize(initial)
    initial = np.hstack((initial, np.zeros((initial.shape[0], 1))))
    filename = "smooth_transition.html"
    figure = animate_init_(initial, filename)
    final = shear(initial)
    generation = 1
    figure = animate_next_(final, figure, filename, generation)
    complete = False
    while not complete:
        center = np.average(final, axis=0)
        final, complete = rotate_toward(center, np.array([1, 1, 1]), final)
        figure = animate_next_(final, figure, filename, generation)
        generation = generation + 1
    complete = False
    while not complete:
        center = np.average(final, axis=0)
        final, complete = rotate_toward(center, np.array([1, 0, 1]), final)
        figure = animate_next_(final, figure, filename, generation)
        generation = generation + 1
    complete = False
    while not complete:
        center = np.average(final, axis=0)
        final, complete = rotate_toward(center, np.array([0, 0, 1]), final)
        figure = animate_next_(final, figure, filename, generation)
        generation = generation + 1
    complete = False
    while not complete:
        center = np.average(final, axis=0)
        final, complete = rotate_toward(center, np.array([1, 0, 0]), final)
        figure = animate_next_(final, figure, filename, generation)
        generation = generation + 1
Exemplo n.º 2
0
    def plot_objectives(self, iteration: int = None):
        """Plot the objective values of individuals.

        Parameters
        ----------
        iteration: int
            Iteration count.
        """
        obj = self.objectives
        self.figure = animate_next_(obj, self.figure, self.filename + ".html",
                                    iteration)
Exemplo n.º 3
0
          no_redun_sol = list(dict.fromkeys(K1)) # Remove the redundant solutions (the solutions chosen several times for different weights) from the list K1

          # Select pop_size solutions for next generation
          if len(no_redun_sol) > pop_size:
               no_redun_sol=no_redun_sol[0:pop_size]

          ## Sorting the individuals and original objective functions based on their ASF values
          for i in range(pop_size):
               objectives1 = np.vstack((objectives1, objectives[int(no_redun_sol[i])]))
               individuals1 = np.vstack((individuals1, individuals[int(no_redun_sol[i])]))
     
          if gen==0:
               figure = animate_init_(objectives1, filename + ".html")
               #figure= animate_next_(objectives1, figure, filename + ".html",gen) 
          else:
               figure= animate_next_(objectives1, figure, filename + ".html",gen) 
               # if gen==20
               



     # k-mean cluster Ns solutions

     k_means = KMeans(NS)
     solution_points = objectives1
     k_means.fit(solution_points)

     # Closest solutions to the center of each class are selected
     closest = set(
          pairwise_distances_argmin_min(
          k_means.cluster_centers_, solution_points