Problem) Gradient descent learning in Python: 1. a) Create class NeuralNetwork(): that creates a single neuron...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Problem) Gradient descent learning in Python: 1. a) Create class NeuralNetwork(): that creates a single neuron with a linear activation, train it using gradient descent learning. This class should have the following function: def __init__(self, learning_r): that initializes a 3x1 weight vector randomly and initializes the learning rate to learning_r. Also, it creates a history variable that saves the weights and the training cost after each epoch (i.e., iteration). def sigmoid(self, x): that takes an input x, and applies the sigmoid function to return: ii. iii. iv. b) Use the gradient descent rule to train a single neuron on the datapoints given below: Create an np array of a shape 10x2 that contains the inputs, and another array with a shape 10x1 that contains the labels. i. ii. iii. p(x) = 1 1+ex def forward_propagation(self, inputs): that performs forward propagation by multiplying the inputs by the neuron weights, uses sigmoid activation function and then generates the output. def train(self, inputs_train, labels_train, num_train_iterations): that performs the gradient descent learning rule for num_train_iterations times using the inputs and labels. iv. Plot the given data points with two different markers for each group. Add the bias to the inputs array to have a 10x3 shape. Create the network with one neuron using the class NeuralNetwork() with learning rate of 1 then train it using train(inputs, labels, 50) function. input X1 X2 1 1 1 0 0 1 0.5 -1 1 0.5 3 0.7 2 -1 0 -1 1 2 0 0 0 desired label 1 1 0 0 1 1 0 0 1 0 c) Use the trained weights and plot the final classifier line. d) Plot the training cost (i.e., the learning curve) for all the epochs. e) Repeat step (b.iv) with the learning rates of 0.5, 0.1, and 0.01. Plot the final classifier line and the learning curve for each learning rate. f) What behavior do you observe from the learning curves with the different learning rates? Explain your observations. Which learning rate is more suitable? Explain. Problem) Gradient descent learning in Python: 1. a) Create class NeuralNetwork(): that creates a single neuron with a linear activation, train it using gradient descent learning. This class should have the following function: def __init__(self, learning_r): that initializes a 3x1 weight vector randomly and initializes the learning rate to learning_r. Also, it creates a history variable that saves the weights and the training cost after each epoch (i.e., iteration). def sigmoid(self, x): that takes an input x, and applies the sigmoid function to return: ii. iii. iv. b) Use the gradient descent rule to train a single neuron on the datapoints given below: Create an np array of a shape 10x2 that contains the inputs, and another array with a shape 10x1 that contains the labels. i. ii. iii. p(x) = 1 1+ex def forward_propagation(self, inputs): that performs forward propagation by multiplying the inputs by the neuron weights, uses sigmoid activation function and then generates the output. def train(self, inputs_train, labels_train, num_train_iterations): that performs the gradient descent learning rule for num_train_iterations times using the inputs and labels. iv. Plot the given data points with two different markers for each group. Add the bias to the inputs array to have a 10x3 shape. Create the network with one neuron using the class NeuralNetwork() with learning rate of 1 then train it using train(inputs, labels, 50) function. input X1 X2 1 1 1 0 0 1 0.5 -1 1 0.5 3 0.7 2 -1 0 -1 1 2 0 0 0 desired label 1 1 0 0 1 1 0 0 1 0 c) Use the trained weights and plot the final classifier line. d) Plot the training cost (i.e., the learning curve) for all the epochs. e) Repeat step (b.iv) with the learning rates of 0.5, 0.1, and 0.01. Plot the final classifier line and the learning curve for each learning rate. f) What behavior do you observe from the learning curves with the different learning rates? Explain your observations. Which learning rate is more suitable? Explain.
Expert Answer:
Answer rating: 100% (QA)
a Heres an implementation of the NeuralNetwork class with the required functions python import numpy as np import matplotlibpyplot as plt class NeuralNetwork def initself learningr selfweights nprando... View the full answer
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Posted Date:
Students also viewed these programming questions
-
What is perfection? Why is it important? How does it happen? (Be specific here.)
-
This assignment reviews object-oriented programming concepts such as classes, methods, constructors, accessor methods, and access modifiers. It makes use of an array of objects as a class data...
-
In this programming assignment you will practice using ArrayLists, Inheritance and Polymorphism. You are to write a game called Magical Creatures War. You will do this by implementing a class called...
-
Two ball bearings from different manufacturers are being considered for a certain application. Bearing A has a catalog rating of 2.0 kN based on a catalog rating system of 3 000 hours at 500 rev/min....
-
A fishnet is made of 1-mm-diameter strings knotted into 2 2 cm squares. Estimate the horsepower required to tow 300 ft2 of this netting at 3 kn in seawater at 20C. The net plane is normal to the...
-
Suppose the Treasury bill rate is 4% and the market risk premium is 7%. a. What are the project costs of capital for new ventures with betas of .75 and 1.75? b. Which of the following capital...
-
In a differential pulley block, the diameter of the smaller pulley is 9/10 th of the larger pulley. Find the load lifted by the block with an effort of 200 N if the efficiency is 45%.
-
Companies need to offer competitive benefits to employees or risk having employees become dissatisfied with their current job situations. KPMG Canada recently faced such a challenge when the companys...
-
Identify and evaluate the components of a comprehensive total rewards and motivation system? Illustrate with specific examples.
-
Both Novador and Sashimia are members of the WTO. Sashimia is also one of 12 fishing nations that are members of the Southern Atlantic Tuna Fishing Organization (SATFO). SATFO was established in 1998...
-
Find the Laplace transform of (i)e bt sinh at, (ii)e bt cosh at, (iii)t e at , (iv)t e -at , (v) t (n-1) e at .
-
turning to the impact of the interest rate cut communicated in Exhibit B on firms (businesses). How do lower interest rates affect a typical firm? Please explain and consider factors such as...
-
the gross sales of a business are 170,000 and sales returns and allowances 450. It is estimated that an additional allowance of 1% of net sales will be required. what should be The amount listed for...
-
Complete the table about estimation of asset acquisition. a. In your own words, describe each listed data used in estimation of asset acquisition. b. In your own words, explain how the data is used...
-
Sarah and Andrew are two traders in a pure exchange economic with two goods, Bikes (B) and Computers (C). Sarah's preferences are described by the Cobb-Douglas Utility function: U = BC3 Andrew's...
-
You borrowed from the bank $500,000 with an annual interest rate of 6% and a maturity of 30 years. There is no balloon payment. Determine the monthly mortgage payment. 2. Assuming semi-annual...
-
What code(s) would be reported for the following case? Preoperative diagnosis: Bilateral impacted ventilating tube Postoperative diagnosis: Same Anesthesia: General Procedure performed: Removal and...
-
Should we separate the debt and equity features of convertible debt? Team 1: Pro separation: Present arguments in favor of separating the debt and equity features of convertible debt. Team 2: Against...
-
Rewrite the Course class in Listing 10.6. Use an ArrayList to replace an array to store students. Draw the new UML diagram for the class. You should not change the original contract of the Course...
-
Design a class named Time. The class contains:??The data fields?hour,?minute, and?second?that represent a time.? A no-arg constructor that creates a Time object for the current time. (The values of...
-
Write the following method that tests whether a two-dimensional array has four consecutive numbers of the same value, either horizontally, vertically, or diagonally.public static...
-
December 2007. When she joined, she signed a membership agreement that had a release of liability that stated: 24 Hour. will not be liable for any injury, including, without limitation, personal,...
-
Recall the facts in Leonard v. Pepsico Had this been a contract, would it have been subject to the Statute of Frauds?
-
John J. Williams began working at Delaware Elevator as a branch sales manager in late 2004. The company manufactures components for elevators and installs and repairs elevators. It employs 175 people...
Study smarter with the SolutionInn App