Code for Recommender Systems
2017-03-13 02:52
543 查看
Two ways to eliminate extra zero ones
idx = find(R(i, :)==1) Thetatemp = Theta(idx,:) Ytemp = Y(i,idx)
Xgrad(i,:) = (X(i,:)∗ThetaTtemp −Ytemp)∗Thetatemp.
R .* M sum(sum(R.*M))
idx = find(R(i, :)==1) Thetatemp = Theta(idx,:) Ytemp = Y(i,idx)
Xgrad(i,:) = (X(i,:)∗ThetaTtemp −Ytemp)∗Thetatemp.
R .* M sum(sum(R.*M))
function [J, grad] = cofiCostFunc(params, Y, R, num_users, num_movies, ... num_features, lambda) %COFICOSTFUNC Collaborative filtering cost function % [J, grad] = COFICOSTFUNC(params, Y, R, num_users, num_movies, ... % num_features, lambda) returns the cost and gradient for the % collaborative filtering problem. % % Unfold the U and W matrices from params X = reshape(params(1:num_movies*num_features), num_movies, num_features); Theta = reshape(params(num_movies*num_features+1:end), ... num_users, num_features); % You need to return the following values correctly J = 0; X_grad = zeros(size(X)); Theta_grad = zeros(size(Theta)); % Instructions: Compute the cost function and gradient for collaborative % filtering. Concretely, you should first implement the cost % function (without regularization) and make sure it is % matches our costs. After that, you should implement the % gradient and use the checkCostFunction routine to check % that the gradient is correct. Finally, you should implement % regularization. % % Notes: X - num_movies x num_features matrix of movie features % Theta - num_users x num_features matrix of user features % Y - num_movies x num_users matrix of user ratings of movies % R - num_movies x num_users matrix, where R(i, j) = 1 if the % i-th movie was rated by the j-th user % % You should set the following variables correctly: % % X_grad - num_movies x num_features matrix, containing the % partial derivatives w.r.t. to each element of X % Theta_grad - num_users x num_features matrix, containing the % partial derivatives w.r.t. to each element of Theta J=1/2*sum(sum(R.*((X*Theta'-Y).^2)))+lambda/2*sum(sum(X.^2))+lambda/2*sum(sum(Theta.^2)); X_grad=(R.*(X*Theta'-Y))*Theta+lambda*X; Theta_grad=(R.*(X*Theta'-Y))'*X+lambda*Theta; grad = [X_grad(:); Theta_grad(:)]; end
相关文章推荐
- 《Statistical Methods for Recommender Systems》阅读笔记--第三章(2)推荐系统中的EE问题
- Data Mining Methods for Recommender Systems推荐读书笔记
- 《Statistical Methods for Recommender Systems》阅读笔记--第4章(1)评估方法--数据切分及线上评估方法
- 论文笔记:Wide & Deep Learning for Recommender Systems
- Collaborative Knowledge Base Embedding for Recommender Systems(译)
- 论文:Coverage, Redundancy and Size-Awareness in Genre Diversity for Recommender Systems
- 《Statistical Methods for Recommender Systems》阅读笔记---第一章
- Code Design for Dependable Systems: Theory and Practical Applications
- 《Wide & Deep Learning for Recommender Systems 》笔记
- RecSys’16 Workshop on Deep Learning for Recommender Systems (DLRS)
- 《Statistical Methods for Recommender Systems》--第五章(2)一般系统架构
- Wide &Deep Learning for Recommender Systems
- Writing Efficient C Code for Embedded Systems
- 《Wide and Deep Learning for Recommender Systems》学习笔记
- 【读论文系列】Collaborative Deep Learning for Recommender Systems
- 《Collaborative Deep Learning for Recommender Systems》阅读笔记
- 《Statistical Methods for Recommender Systems》阅读笔记--第二章
- 《Statistical Methods for Recommender Systems》阅读笔记--第三章(1)--EE问题
- [转]-[携程]-A Hybrid Collaborative Filtering Model with Deep Structure for Recommender Systems
- 《Statistical Methods for Recommender Systems》--第五章(1)推荐问题设定和系统架构