Write a program in python Using swarm basic optimization with arguments to find a minimum of Rosenbrook function, To find the minimum of the test function y = x – 2sin(x). set up the bound for the value [-5.12, 5.12]. Use Swarm to find the value of X which minimizes the test function. Use the default hyperparameters. # hyperparameters options = {'c1': 0.5, 'c2': 0.3, 'w':0.9}

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write a program in python Using swarm basic optimization with arguments to find a minimum of Rosenbrook function, To find the minimum of the test function y = x – 2sin(x).

set up the bound for the value [-5.12, 5.12].

Use Swarm to find the value of X which minimizes the test function.

Use the default hyperparameters.

# hyperparameters

options = {'c1': 0.5, 'c2': 0.3, 'w':0.9} 

 

Using Arguments
Arguments can either be passed in using a tuple or a dictionary, using the kwargs={} paradigm. First
lets optimize the Rosenbrock function using keyword arguments. Note in the definition of the
Rosenbrock function above, there were two arguments that need to be passed other than the
design variables, and one optional keyword argument, a, b, and c, respectively
[7]: from pyswarms.single.global_best import GlobalBest PSO
#instatiate the optimizer
x_max = 10 np.ones (2)
x_min = -1 * x_max
*
bounds = (x_min, x_max)
options {'c1': 0.5, 'c2': 0.3, 'w': 0.9}
optimizer = GlobalBest PSO(n_particles=10, dimensions=2, options=options, bounds-bounds)
# now run the optimization, pass a=1 and b=100 as a tuple assigned to args
cost, pos = optimizer.optimize(rosenbrock_with_args, 1000, a=1, b=100, c=0)
Transcribed Image Text:Using Arguments Arguments can either be passed in using a tuple or a dictionary, using the kwargs={} paradigm. First lets optimize the Rosenbrock function using keyword arguments. Note in the definition of the Rosenbrock function above, there were two arguments that need to be passed other than the design variables, and one optional keyword argument, a, b, and c, respectively [7]: from pyswarms.single.global_best import GlobalBest PSO #instatiate the optimizer x_max = 10 np.ones (2) x_min = -1 * x_max * bounds = (x_min, x_max) options {'c1': 0.5, 'c2': 0.3, 'w': 0.9} optimizer = GlobalBest PSO(n_particles=10, dimensions=2, options=options, bounds-bounds) # now run the optimization, pass a=1 and b=100 as a tuple assigned to args cost, pos = optimizer.optimize(rosenbrock_with_args, 1000, a=1, b=100, c=0)
Basic Optimization with Arguments
Here, we will run a basic optimization using an objective function that needs parameterization. We
will use the single. GBestPSO and a version of the rosenbrock function to demonstrate
[6]: # import modules
import numpy as np
# create a parameterized version of the classic Rosenbrock unconstrained optimzation function
def rosenbrock_with_args(x, a, b, c=0):
f = (a - x[:, 0]) ** 2 + b * (x[:, 1] x[:, 0] ** 2) ** 2 + c
return f
Transcribed Image Text:Basic Optimization with Arguments Here, we will run a basic optimization using an objective function that needs parameterization. We will use the single. GBestPSO and a version of the rosenbrock function to demonstrate [6]: # import modules import numpy as np # create a parameterized version of the classic Rosenbrock unconstrained optimzation function def rosenbrock_with_args(x, a, b, c=0): f = (a - x[:, 0]) ** 2 + b * (x[:, 1] x[:, 0] ** 2) ** 2 + c return f
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

What if the swarm was 2-dimentional and the max bound was 10* np.ones(2)  and minimum bound = -1 *max.
How can  I write a helper function that, given a vector/array A, returns a vector/array B in which
every element’s value is sine of the corresponding element’s value in A. For instance,
given array A=(e1 e2, e3), the helper function will return an array B=(sine(e1), sine(e2),
sine(e3)).

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education