Hi. I'am working on SVD++ algorithm for my course project and I've recently faced a huge bottleneck it the code which I am unable to solve by myself.
the code which consumes approximately 70% of time is:
for item=1:length(UserDataClear2)
Ys=Ys+ItemInfo{UserDataClear2{user}(item),4};
end
It does the following:
for each user there is a vector of items he rated (just numbers). It finds corresponding vector ItemInfo(x,4) where x stand for item's number (which i get from user profile, so set of items changes for each user).
I need to find a sum of all these vectors (ItemInfo(x,4)) - which seems to be the hardest part, as these vectors are stored in cell array.
Other variants such as
for item=1:length(UserDataClear2)
Ys{item}=ItemInfo{UserDataClear2{user}(item),4};
end
YsSum=sum(cat(2,Ys{:}),2)
work much slower.
In other words: I need to sum vectors from cell arrays, whereas vectors these vectors are different for each user; all of them are stored in huge cell array.
Any ideas how this code can be imporved?
Sincerely, Alex.

 채택된 답변

Andrew Newell
Andrew Newell 2012년 1월 7일

1 개 추천

The slowdown seems to be caused by the use of cell data for indices into ItemInfo. Try this:
Ys = sum([ItemInfo{UserDataClear2{user},4}])
This accesses the array UserDataClear2 only once.

댓글 수: 2

Alexey Zanin
Alexey Zanin 2012년 1월 7일
Brilliant and simple, thanks a lot!
The following code does summation allong the correct dimension of cell array:
Ys=sum([ItemInfo{UserDataClear2{user}(1:length(UserDataClear{user}(:,1))),4}],2);
Andrew Newell
Andrew Newell 2012년 1월 7일
Yikes!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by