faridcher / ml-course

Starter code of Prof. Andrew Ng's machine learning MOOC in R statistical language
https://www.coursera.org/learn/machine-learning
170 stars 149 forks source link

why Theta is called as a subfunction #4

Closed rajasekhar-thiru closed 7 years ago

rajasekhar-thiru commented 7 years ago

Hi Fared, Curios to know why you create function within function (Theta as a subfunction of cost function). For example,

linearRegCostFunction <- function(X, y, lambda) { function(theta) {

why not linearRegCostFunction <- function(X, y, lambda,theta) {

Is it just a coding style or there is a particular reason.

Thanks in advance.

faridcher commented 7 years ago

I wanted linearRegCostFunction to return a function instead of a value, since the optim() function in R require a cost function as its second argument. of course there other ways of doing this, but this is my preferred style of coding for optimizations. ​

On Sun, May 14, 2017 at 6:30 PM, rajasekhar-thiru notifications@github.com wrote:

Hi Fared, Curios to know why you create function within function (Theta as a subfunction of cost function). For example,

linearRegCostFunction <- function(X, y, lambda) { function(theta) {

why not linearRegCostFunction <- function(X, y, lambda,theta) {

Is it just a coding style or there is a particular reason.

Thanks in advance.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/faridcher/machine-learning-course/issues/4, or mute the thread https://github.com/notifications/unsubscribe-auth/AJhSN0GZYDjBMeNbgRFIiWrbyS_vmrwBks5r54BugaJpZM4Nahw9 .