Code Monkey home page Code Monkey logo

Comments (2)

gugarosa avatar gugarosa commented on May 18, 2024

Hello amir1m! I hope everything is going well with you!

Sorry for not having a script that depicts on how to use the actual optimization problem to make the convergence plot. We ran into some issues where people used to say that there was not file to be loaded and opted to remove such an example.

Nevertheless, here is a draft that might help you:

import numpy as np
from opytimark.markers.n_dimensional import Sphere

from opytimizer import Opytimizer
from opytimizer.core import Function
from opytimizer.optimizers.swarm import PSO
from opytimizer.spaces import SearchSpace

import opytimizer.visualization.convergence as c

# Random seed for experimental consistency
np.random.seed(0)

# Number of agents and decision variables
n_agents = 20
n_variables = 2

# Lower and upper bounds (has to be the same size as `n_variables`)
lower_bound = [-10, -10]
upper_bound = [10, 10]

# Creates the space, optimizer and function
space = SearchSpace(n_agents, n_variables, lower_bound, upper_bound)
optimizer = PSO()
function = Function(Sphere())

# Bundles every piece into Opytimizer class
opt = Opytimizer(space, optimizer, function, save_agents=False)

# Runs the optimization task
opt.start(n_iterations=1000)

# Retrieves the best agent's position and fitness
best_agent_pos, best_agent_fit = opt.history.get_convergence('best_agent')

# Plots the convergence of x0 and x1
c.plot(best_agent_pos[0], best_agent_pos[1])

Note that the idea is to retrieve a list of positions/fitness through the get_convergence() method of the History class. With these lists, it is possible to feed them to the convergence.plot() method.

Additionally, after performing an optimization, you can save the whole task using opt.save() and load it into another script with opt = Opytimizer.load(). The History object will be available as an property of Opytimizer, e.g., opt.history.

Please let me know if it works!

Best regards,
Gustavo.

from opytimizer.

amir1m avatar amir1m commented on May 18, 2024

Awesome! Works as expected.

Thanks @gugarosa ! Appreciate the quick turnaround!

Take care.
Amir

from opytimizer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.