Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This code for Gradient Descent algorithm for one vector x and I attached the image of plots of the algorithm after run I want to

This code for Gradient Descent algorithm for one vector x and I attached the image of plots of the algorithm after run

I want to update the same code for two vectors (two Dimensions) with plots them """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

import numpy as np from matplotlib import pyplot as plt class GradientDescent: def __init__(self, function, gradient, initial_solution, learning_rate=0.1, max_iter=100, tolerance=0.0000001): self.function = function self.gradient= gradient self.solution = initial_solution self.learning_rate = learning_rate self.max_iter = max_iter self.tolerance = tolerance def run(self): t = 0 while t

def gradient1(x,y): return 2*x

bounds = [-3,3]

plt.figure()

x = np.linspace(bounds[0], bounds[1],100) plt.plot(x,fun1(x))

random_solution = np.random.uniform(bounds[0], bounds[1])

gd = GradientDescent(fun1, gradient1, random_solution)

best_solution,best_value = gd.run()

image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 31st International Conference Dexa 2020 Bratislava Slovakia September 14 17 2020 Proceedings Part 1 Lncs 12391

Authors: Sven Hartmann ,Josef Kung ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

303059002X, 978-3030590024

More Books

Students also viewed these Databases questions

Question

What is the environment we are trying to create?

Answered: 1 week ago