想了解下深度学习,看到网上有人推荐Andrew NG团队做的UFLDL,他们给的上机练习挺多,而且是用matlab,感觉自己编程太菜,顺便可以跟着练练实际操作。第一节linear regression,内容没有什么难度,上机也不难,但还是遇到了点小麻烦。
% YOUR CODE HERE %
for num=1:m
f = f + 1/2*(theta'*X(:,num)-y(num))^2;
g = g + (theta'*X(:,num)-y(num))*X(:,num);
end
编写f和g之后执行ex1a_linreg.m后出现如下错误:
??? Undefined function or method 'lbfgsAddC' for input arguments of type 'int32'.
这里给出了解决方法:
You get the error “??? Undefined function or method ‘lbfgsAddC’”. This occurs if Matlab can’t find the mex file for your operating system. If this occurs, you can either: (i) set ‘options.useMex’ to 0, or (ii) compile the mex file for your operating system by running the mexAll function. If you end up compiling a file in minFunc for your operating system, please send it to me and I will add to the distribution.
这是一位UBC的教授主页里面的东西,还有更详细的关于他写的minFunc的一些资料,现在不太想深究里面太具体的玩意。我就把ex1a_linreg.m中
options = struct('MaxIter', 200);
替换为
options = struct('MaxIter', 200,'useMex',0);
就可以了。
练习中还让感受一下matlab的vectorization features加快执行速度。
Using MATLAB’s vectorization features to speed up code.
%%% YOUR CODE HERE %%%
f = 1/2*(theta'*X-y)*(theta'*X-y)';
g = X*(theta'*X-y)';
执行速度明显提升。