LFD Book Forum  

Go Back   LFD Book Forum > Course Discussions > Online LFD course > Homework 5

Reply
 
Thread Tools Display Modes
  #1  
Old 05-06-2013, 12:37 PM
pyguy pyguy is offline
Junior Member
 
Join Date: Apr 2013
Posts: 5
Default Q8 implementation question

I'm trying to compute the stochastic gradient descent for linear regression, and the formula I'm using is:

\nabla e_n(\mathbf w) = \frac{-y_n\mathbf x_n}{1 + e^{y_n\mathbf{w^T}\mathbf{x_n}}}

I'm running the experiment with what I believe to be the correct inputs, but I'm not getting the what I expect to be the output, so I'm trying to trace my steps and see where I went wrong. I was looking at the formula, and one part that I was uncertain about was the \mathbf{w^T}\mathbf{x_n} part. Aren't \mathbf{w} and \mathbf{x_n} both 1x3 row vectors? If I transpose \mathbf{w}, and multiply, I'd get a 3x3 matrix which didn't make sense to me in the calculation, so I'm essentially multiplying them right now as if they were just 1x3 row vectors.
Reply With Quote
  #2  
Old 05-06-2013, 01:11 PM
yaser's Avatar
yaser yaser is offline
Caltech
 
Join Date: Aug 2009
Location: Pasadena, California, USA
Posts: 1,477
Default Re: Q8 implementation question

Quote:
Originally Posted by pyguy View Post
I'm trying to compute the stochastic gradient descent for linear regression, and the formula I'm using is:

\nabla e_n(\mathbf w) = \frac{-y_n\mathbf x_n}{1 + e^{y_n\mathbf{w^T}\mathbf{x_n}}}

I'm running the experiment with what I believe to be the correct inputs, but I'm not getting the what I expect to be the output, so I'm trying to trace my steps and see where I went wrong. I was looking at the formula, and one part that I was uncertain about was the \mathbf{w^T}\mathbf{x_n} part. Aren't \mathbf{w} and \mathbf{x_n} both 1x3 row vectors? If I transpose \mathbf{w}, and multiply, I'd get a 3x3 matrix which didn't make sense to me in the calculation, so I'm essentially multiplying them right now as if they were just 1x3 row vectors.
The convention is that vectors are column vectors, so \mathbf{w}^{\rm T}\mathbf{x_n} is an inner product, not an outer product.
__________________
Where everyone thinks alike, no one thinks very much
Reply With Quote
  #3  
Old 05-06-2013, 07:15 PM
pyguy pyguy is offline
Junior Member
 
Join Date: Apr 2013
Posts: 5
Default Re: Q8 implementation question

Thank you! I knew I was missing something with the math and my best guess was I was doing something wrong there.
Reply With Quote
  #4  
Old 05-07-2013, 05:18 AM
jlevy jlevy is offline
Junior Member
 
Join Date: Apr 2013
Posts: 5
Default Re: Q8 implementation question

Looks to me like the derivative is incorrect
__________________
Joe Levy
[URL="https://trustmeimastatistician.wordpress.com/"]Trust me, I'm a statistician[/URL]
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:45 AM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
The contents of this forum are to be used ONLY by readers of the Learning From Data book by Yaser S. Abu-Mostafa, Malik Magdon-Ismail, and Hsuan-Tien Lin, and participants in the Learning From Data MOOC by Yaser S. Abu-Mostafa. No part of these contents is to be communicated or made accessible to ANY other person or entity.