Need help with code completion in python below.: class cross_entropy:     def __init__(self):         self.X = None         self.Y = None              def forward(self,X,Y):         m = Y.shape[1]         logprobs = np.multiply(np.log(X), Y) + np.multiply((1 - Y), np.log(1 - X))          cost = - np.sum(logprobs) / m          cost = np.squeeze(cost)          self.X = X         self.Y = Y         return cost               def backward(self):         m = self.Y.shape[1]          diff = self.X-self.Y         diff = np.divide(diff,np.multiply(self.X,(1-self.X)))/m         self.X = None         self.Y = None         return diff      class mse:     def __init__(self):         self.X = None         self.Y = None              def forward(self,X,Y):                  # YOUR CODE HERE                   return cost              def backward(self):                  #YOUR CODE HERE         return diff

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
100%

Need help with code completion in python below.:

class cross_entropy:
    def __init__(self):
        self.X = None
        self.Y = None
        
    def forward(self,X,Y):
        m = Y.shape[1]
        logprobs = np.multiply(np.log(X), Y) + np.multiply((1 - Y), np.log(1 - X)) 
        cost = - np.sum(logprobs) / m 
        cost = np.squeeze(cost) 
        self.X = X
        self.Y = Y
        return cost 
        
    def backward(self):
        m = self.Y.shape[1] 
        diff = self.X-self.Y
        diff = np.divide(diff,np.multiply(self.X,(1-self.X)))/m
        self.X = None
        self.Y = None
        return diff
    
class mse:
    def __init__(self):
        self.X = None
        self.Y = None
        
    def forward(self,X,Y):
        
        # YOUR CODE HERE 
        
        return cost
        
    def backward(self):
        
        #YOUR CODE HERE
        return diff

Define the losses and their derivatives
Define the loss functions for loss evaluation
• Define the gradient of the loss functions for backpropagation
Note that the losses need to be computed between two vectors Y € RNXP and A2 € RNXP. In this assignment, we consider a two class classification
problem with N = 1. P is the number of training data samples or the number of data samples used in a batch. Please refer to the course notes and lecture for
details.
The widely used losses are
1. Cross entropy for two class classification
ΤΣ
p=1
The gradient of the loss term with respect to a₂ is specified by
2. Mean squared error for regression
C(a₂, y) = --
(yp log(a₂.p) + (1 − yp) log(1 − a2.p))
V C =
a2.p
C(a₂, y)
The gradient of the loss term with respect to a2 is specified by
Vo C =
a2.p
y-a2.p
Pa₂.p(1-a2.p)
1
P
| ||a2.p - y₂||²
p=1
12(a2.p - Yp)
P
Transcribed Image Text:Define the losses and their derivatives Define the loss functions for loss evaluation • Define the gradient of the loss functions for backpropagation Note that the losses need to be computed between two vectors Y € RNXP and A2 € RNXP. In this assignment, we consider a two class classification problem with N = 1. P is the number of training data samples or the number of data samples used in a batch. Please refer to the course notes and lecture for details. The widely used losses are 1. Cross entropy for two class classification ΤΣ p=1 The gradient of the loss term with respect to a₂ is specified by 2. Mean squared error for regression C(a₂, y) = -- (yp log(a₂.p) + (1 − yp) log(1 − a2.p)) V C = a2.p C(a₂, y) The gradient of the loss term with respect to a2 is specified by Vo C = a2.p y-a2.p Pa₂.p(1-a2.p) 1 P | ||a2.p - y₂||² p=1 12(a2.p - Yp) P
Expert Solution
Step 1

I have provided explanation and full code to complete the python program given in the question.

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Adjacency Matrix
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
  • SEE MORE 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