def scatter_pymoo(data, name, label=None, **kwargs): """ Plot either a scatter, curve or surface plot. Arguments: data (np.array): Data to plot. name (str): Visualization type. label (str): Variable name for label. Notes: Surface plot not used. """ # Add data to plot plot_args = get_plot_args(data, label) angles = 4 if data.shape[1] == 3 else 1 for angle in range(angles): plot_args["angle"] = (30, -135 + angle * 90) plot = get_visualization("scatter", **plot_args) plot.add(data, plot_type=None, color="k", **kwargs) plot.do() ## plot.apply(lambda ax: ax.set_xlim([0,1])) # Save figure save_figure(name + f"_{angle+1}", plot)
def surface_pymoo(data, iteration): """ A surface plot using Pymoo. Args: data (np.array): Data to plot. iteration (int): Iteration number. """ # Add data to plot plot_args = get_plot_args(data, "x") angles = 4 if data.shape[1] == 3 and iteration else 1 for angle in range(angles): plot_args["angle"] = (30, -135 + angle * 90) plot = get_visualization("scatter", **plot_args) kwargs = { "cmap": get_blackblue_cmap() } if data.shape[1] == 3 else { "color": "k" } plot.add(data, plot_type="surface", **kwargs) plot.do() # Save figure if iteration: save_figure(f"iteration_{iteration}_response_{angle}", plot) else: plot.show()
def heatmap(correlation): """ A heatmap plot. Args: correlation (np.array): Correlation matrix. """ newmap = get_blackblue_cmap() plot = get_visualization("heatmap", labels="x", cmap=newmap, reverse=False) plot.add(correlation, vmin=-1, vmax=1) save_figure("heatmap", plot)
def pcp(data, name): """ A parallel component plot. Args: data (np.array): Data to plot. name (str): Filename. """ plot = get_visualization("pcp", labels="f") plot.set_axis_style(color="C0") plot.add(data, color="k") plot.do() save_figure(name, plot)
from pymoo.algorithms.moead import MOEAD from pymoo.factory import get_problem, get_visualization, get_reference_directions from pymoo.optimize import minimize problem = get_problem("dtlz2") algorithm = MOEAD(get_reference_directions("das-dennis", 3, n_partitions=12), n_neighbors=15, decomposition="pbi", prob_neighbor_mating=0.7) res = minimize(problem, algorithm, termination=('n_gen', 200)) get_visualization("scatter").add(res.F).show()
plt.xlabel("Function Evaluations") plt.ylabel("Hypervolume") # fig.savefig(LATEX_DIR + 'convergence.eps', format='eps') plt.show() from pymoo.factory import get_visualization, get_decomposition F = res.F weights = np.array([0.01, 0.99]) decomp = get_decomposition("asf") # We apply the decomposition and retrieve the best value (here minimum): I = get_decomposition("asf").do(F, weights).argmin() print("Best regarding decomposition: Point %s - %s" % (I, F[I])) plot = get_visualization("scatter") plot.add(F, color="blue", alpha=0.5, s=30) plot.add(F[I], color="red", s=40) plot.do() # plot.apply(lambda ax: ax.arrow(0, 0, F[I][0], F[I][1], color='black', # head_width=0.001, head_length=0.001, alpha=0.4)) plot.show() ## Parallel Coordinate Plots from pymoo.visualization.pcp import PCP plotPCP = PCP().add(res.F).add(res.F[I], color='r').show() print( f'A solução ideal é encontrada para a deformação {res.F[I][0]:.4f}m e massa {res.F[I][0]:.4f}kg com os parametros a {res.X[I][0]:.4f} b {res.X[I][1]:.4f} e h {res.X[I][2]:.4f}' )