Matlab梯度下降解决评分矩阵分解

简介: for iter = 1:num_iters %梯度下降 用户向量 for i = 1:m %返回有0有1 是逻辑值 ratedIndex1 = R_training(i,:)~=0 ; %U(i,:) * V' ...
for iter = 1:num_iters
   
    %梯度下降 用户向量
    for i = 1:m
        %返回有0有1 是逻辑值
       ratedIndex1 = R_training(i,:)~=0 ;
       %U(i,:) * V'  第i个用户分别对每个电影的评分
       
       %sumVec1  第i个用户分别对每个电影的评分 减去真实值
       sumVec1 = ratedIndex1 .* (U(i,:) * V' - R_training(i,:));
       product1 = sumVec1 * V;
       derivative1 = product1 + lambda_u * U(i,:);
       old_U(i,:) = U(i,:) - theta * derivative1;
    end
    
    %梯度下降 电影向量
    for j = 1:n
       ratedIndex2 = R_training(:,j)~=0;
       sumVec2 = ratedIndex2 .* (U * V(j,:)' - R_training(:,j));
       product2 = sumVec2' * U;
       derivative2 = product2 + lambda_v * V(j,:);
       old_V(j,:) = V(j,:) - theta * derivative2;
    end
    
    U = old_U;
    V = old_V;
    RMSE(i,1) = CompRMSE(train_vec,U,V);
    RMSE(i,2) = CompRMSE(probe_vec,U,V);

end

  ......................................................................

SGD解决

function [ recItems ] = mf_gd( trainMatrix, featureNumber, maxEpoch, learnRate, lambdaU, lambdaV, k)

%get the size the train matrix
[userNumber,itemNumber] = size(trainMatrix);

%init user factors and item factors
Ut = 0.01 * randn(userNumber, featureNumber);
Vt = 0.01 * randn(itemNumber, featureNumber);
%逻辑1和0
logitMatrix = trainMatrix > 0;

%calculate the gradient of user factors and item factors
%and user sgd to optimize the risk function
%alternative update user factors and item factors alternative
for round = 1:maxEpoch,
   dU = -(logitMatrix  .* trainMatrix)  * Vt + (Ut * Vt' .* logitMatrix ) * Vt + lambdaU * Ut;
   dV = -(logitMatrix' .* trainMatrix') * Ut + (Vt * Ut' .* logitMatrix') * Ut + lambdaV * Vt;
   Ut = Ut - learnRate * dU * 2;
   Vt = Vt - learnRate * dV * 2;
end

%predict the rating of each item given by each user
predictMatrix = Ut * Vt';

%sort the score of items for each user
[sortedMatrix, sortedItems] = sort(predictMatrix, 2, 'descend');

%get the top-k items for each suer
recItems = sortedItems(:, 1:k);
end

  

目录
相关文章
|
19天前
|
索引
matlab--------矩阵重构,重新排列的相关函数说明
matlab--------矩阵重构,重新排列的相关函数说明
63 0
matlab--------矩阵重构,重新排列的相关函数说明
|
19天前
|
并行计算 算法 计算机视觉
【MATLAB 】 EMD信号分解+模糊熵(近似熵)算法
【MATLAB 】 EMD信号分解+模糊熵(近似熵)算法
49 0
|
19天前
|
并行计算 算法 计算机视觉
【MATLAB 】 EEMD 信号分解+模糊熵(近似熵)算法
【MATLAB 】 EEMD 信号分解+模糊熵(近似熵)算法
55 0
|
19天前
|
并行计算 算法 计算机视觉
【MATLAB 】 CEEMD 信号分解+模糊熵(近似熵)算法
【MATLAB 】 CEEMD 信号分解+模糊熵(近似熵)算法
59 0
|
19天前
|
并行计算 算法 计算机视觉
【MATLAB 】 CEEMDAN 信号分解+模糊熵(近似熵)算法
【MATLAB 】 CEEMDAN 信号分解+模糊熵(近似熵)算法
103 0
|
4天前
|
机器学习/深度学习 算法 数据安全/隐私保护
基于DCT变换和位平面分解的数字水印嵌入提取算法matlab仿真
这是一个关于数字水印算法的摘要:使用MATLAB2022a实现,结合DCT和位平面分解技术。算法先通过DCT变换将图像转至频域,随后利用位平面分解嵌入水印,确保在图像处理后仍能提取。核心程序包括水印嵌入和提取,以及性能分析部分,通过PSNR和NC指标评估水印在不同噪声条件下的鲁棒性。
基于广义Benders分解法的综合能源系统优化规划(matlab程序)
基于广义Benders分解法的综合能源系统优化规划(matlab程序)
|
19天前
|
机器学习/深度学习 算法 数据可视化
Matlab决策树、模糊C-均值聚类算法分析高校教师职称学历评分可视化
Matlab决策树、模糊C-均值聚类算法分析高校教师职称学历评分可视化
|
19天前
|
机器学习/深度学习 算法 数据可视化
MATLAB基于深度学习U-net神经网络模型的能谱CT的基物质分解技术研究
MATLAB基于深度学习U-net神经网络模型的能谱CT的基物质分解技术研究
|
19天前
|
数据可视化 数据库
matlab中使用VMD(变分模态分解)对信号去噪
matlab中使用VMD(变分模态分解)对信号去噪
matlab中使用VMD(变分模态分解)对信号去噪

热门文章

最新文章