示例#1
0
from opytimizer.utils.history import History

# File name to be loaded
file_name = ''

# Creating an empty History object
h = History()

# Loading history from pickle file
h.load(file_name)

# Displaying content
print(h)
    # Gathering variables from arguments
    dataset = args.dataset
    descriptor = args.descriptor
    fold = args.fold
    type = args.type
    meta = args.mh

    # Defining an input file
    input_file = f'output/{meta}_{type}_{dataset}_val_{fold}.pkl'

    # Creating a History object
    h = History()

    # Loading the input file
    h.load(input_file)

    # Loading the predictions and labels
    preds, y = l.load_candidates(dataset, 'test', fold)

    # If descriptor is global-based
    if descriptor == 'global':
        # Gets the global predictors
        preds = preds[:, :35]

    # If descriptor is cnn-based
    elif descriptor == 'cnn':
        # Gets the CNN predictors
        preds = preds[:, 35:]

    # Gathering the best weights
示例#3
0
import numpy as np

import opytimizer.visualization.convergence as c
from opytimizer.utils.history import History

# Creating the history object
history = History()

# Loading saved optimization task
history.load('')

# Gathering desired keys from the object
# In this case, we will the first agent's position and fitness
agent_pos = history.get(key='agents', index=(0, 0))
agent_fit = history.get(key='agents', index=(0, 1))

# We will also gather the best agent's position and fitness
best_agent_pos = history.get(key='best_agent', index=(0,))
best_agent_fit = history.get(key='best_agent', index=(1,))

# Plotting convergence graphs
# Plotting the convergence of agent's positions
c.plot(agent_pos[0], agent_pos[1], labels=['$x_0$', '$x_1$'],
       title='Sphere Function: $x^2 \mid x \in [-10, 10]$', subtitle='Agent: 0 | Algorithm: Particle Swarm Optimization')

# Plotting the convergence of best agent's positions
c.plot(best_agent_pos[0], best_agent_pos[1], labels=['$x^*_0$', '$x^*_1$'],
       title='Sphere Function: $x^2 \mid x \in [-10, 10]$', subtitle="Agent: Best | Algorithm: Particle Swarm Optimization")

# Plotting the convergence of agent's and best agent's fitness
c.plot(agent_fit, best_agent_fit, labels=[