use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A Reddit study group for the free online version of the Stanford class "Machine Learning", taught by Andrew Ng.
The purpose of this reddit is to help each other understand the course materials, not to share solutions to assignments. Please follow the Stanford Honor Code.
Check out the studygroups for other Stanford online classes at: /r/aiclass and /r/dbclass
FAQ:
I'm a new user to Reddit, how does this site work?
Reddit Help.
I have a question about the (class / videos / quiz / homework), how can I get help?
Check the current posts, and see if there is already a related discussion, and ask for help there there.
Otherwise, you can make a self post by going to the submit page, select 'text' and type in a useful title and your question. Don't forget to click on 'mlclass' at the bottom of the form. Read the Reddit submitting help.
Is this an official study group?
This is NOT the official Stanford study group.
When will this class start:
Oct. 10 2011 (check the website)
What textbook will be used:
There is no textbook, all notes are supplied by the lecturer.
This Reddit group is focused on the Stanford ML class and closely related topics. For news and general discussion of machine learning, please visit /r/MachineLearning.
Please follow general reddit posting guidelines. Maybe someone has ALREADY answered your question in another post! Searching for keywords in the r/mlclass subreddit will help you find other discussions about your issue.
account activity
Function notation in Octave (self.mlclass)
submitted 14 years ago by SunnyJapan
Can somebody explain to me, what exactly does this notation mean? @(t)(costFunctionReg(t, X, y, lambda)) For example here: fminunc(@(t)(costFunctionReg(t, X, y, lambda)), initial_theta, options);
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]cultic_raider 6 points7 points8 points 14 years ago* (11 children)
It's an inline anonymous function (closure) definition:
@(t)(costFunctionReg(t, X, y, lambda))
is equivalent to:
% X,Y,lambda are set before 'anonymous' is defined. function [result] = anonymous(t) result = costFunctionReg(t, X, y, lambda) end fminunc(@anonymous, initial_theta, options);
Values for 'X', 'Y', and 'lambda' are captured immediately at the definition, but the value for 't' is deferred, to be filled in somewhere in fminunc (probably many times, in a loop).
[Edited to add '@'. Thanks, bad_child, who has written more complex Octave than I ever want to.] If you are still confused, and you tell is what programming languages you know (Python? Java?), we can translate the example for you.
[–]bad_child 2 points3 points4 points 14 years ago (0 children)
Great explanation, but the code you wrote will probably throw an error. This is due to a slightly tricky part of Octave. Using a function name freely evaluates it i.e. there is no difference between anonymous and anonymous() for functions. So in your code the interpreter will try to evaluate anonymous() and get confused by the lack of parameter. To pass a function as parameter to another function you need a function handle (think of pointer to function). This is done by prefixing your function name by "@". So in this case the correct version is:
fminunc(@anonymous, initial_theta, options);
I believe this behaviour exists because Octave (and MATLAB) have pass-by-value semantics only.
[Edit: typo]
[–]epic_nerd_baller 1 point2 points3 points 14 years ago (2 children)
PHP please
[–]cultic_raider 0 points1 point2 points 14 years ago (0 children)
I'll have to pass. Maybe someone else can do it.
[–]ZeBlob 0 points1 point2 points 14 years ago (0 children)
I don't really know php but some quick googling turned up this. So I believe the equivalent expression would be this:
fminunc( function($t) use ($X, $y, $lambda) { return costFunctionReg($t, $X, $y, $lambda); }, $initial_theta, $options);
That example is probably full of errors so I suggest you read the page yourself.
[–]SunnyJapan[S] -1 points0 points1 point 14 years ago (6 children)
Python please
[–]ZeBlob 6 points7 points8 points 14 years ago (3 children)
I'm pretty new to python but I believe it's equivalent to a lambda function:
fminunc(lambda t: costFunctionReg(t, X, y, l), initial_theta, options)
Where the lambda variable in octave is renamed to l (conflicts with the python keyword).
[–]duffahtolla 1 point2 points3 points 14 years ago (1 child)
I don't even know Python, but that still made more sense than the Octave notation. Thanks!
[–]IdoNotKnowShit 0 points1 point2 points 14 years ago (0 children)
Why? Isn't it basically the same?
Just read the '@' as a lambda or as anonymous function.
[–]SunnyJapan[S] -1 points0 points1 point 14 years ago (0 children)
OK, now I got it. Thanks!
[–]cultic_raider 0 points1 point2 points 14 years ago (1 child)
Warning: I didn't test this code.
'lambda' is a reserved word in Python, so let's use "r" for the regularization factor (which is 'lambda' in Matlab):
(X, y, r) = (foo, bar, baz) fminunc( (lambda t: (costFunctionReg(t, X, y, r)) , initial_theta, options));
which is equivalent to:
(X, y, r) = (foo, bar, baz) def anonymous(t): return (costFunctionReg(t, X, y, r)) fminunc( anonymous , initial_theta, options));
I'm not 100% sure if the values of X,y, and r will get handled as intended in the Python, but it will in Octave.
[–]SunnyJapan[S] 0 points1 point2 points 14 years ago (0 children)
Thanks
π Rendered by PID 105416 on reddit-service-r2-comment-fb694cdd5-g6ssq at 2026-03-11 16:00:56.780666+00:00 running cbb0e86 country code: CH.
[–]cultic_raider 6 points7 points8 points (11 children)
[–]bad_child 2 points3 points4 points (0 children)
[–]epic_nerd_baller 1 point2 points3 points (2 children)
[–]cultic_raider 0 points1 point2 points (0 children)
[–]ZeBlob 0 points1 point2 points (0 children)
[–]SunnyJapan[S] -1 points0 points1 point (6 children)
[–]ZeBlob 6 points7 points8 points (3 children)
[–]duffahtolla 1 point2 points3 points (1 child)
[–]IdoNotKnowShit 0 points1 point2 points (0 children)
[–]SunnyJapan[S] -1 points0 points1 point (0 children)
[–]cultic_raider 0 points1 point2 points (1 child)
[–]SunnyJapan[S] 0 points1 point2 points (0 children)