Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayOutOfBounds exception with ItemKNN #305

Open
diarmuidmorgan opened this issue Mar 25, 2019 · 2 comments
Open

ArrayOutOfBounds exception with ItemKNN #305

diarmuidmorgan opened this issue Mar 25, 2019 · 2 comments

Comments

@diarmuidmorgan
Copy link

Hi apologies in advance if I'm just doing something wrong.

I'm running librec itemknn from the commandline with the config listed in the algorithm list.

It will repeatedly crash with the following output.

19/03/25 12:45:41 INFO TextDataConvertor: Dataset: [./librecdata/depaul.csv] 19/03/25 12:45:41 INFO TextDataConvertor: DataSet: ./librecdata/depaul.csv is finished 19/03/25 12:45:42 INFO TextDataConvertor: rating Scale: [1.0, 2.0, 3.0, 4.0, 5.0] 19/03/25 12:45:42 INFO TextDataConvertor: user number: 97, item number is: 79 19/03/25 12:45:42 INFO TextDataModel: Transform data to Convertor successfully! 19/03/25 12:45:42 INFO TextDataModel: Split data to train Set and test Set successfully! 19/03/25 12:45:42 INFO TextDataModel: Data cardinality of training is 1144 19/03/25 12:45:42 INFO TextDataModel: Data cardinality of testing is 299 19/03/25 12:45:43 INFO ItemKNNRecommender: Job Setup completed. 19/03/25 12:45:43 INFO ItemKNNRecommender: Job Train completed. Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 79 at net.librec.math.structure.VectorBasedDenseVector.get(VectorBasedDenseVector.java:91) at net.librec.recommender.cf.ItemKNNRecommender.predict(ItemKNNRecommender.java:132) at net.librec.recommender.MatrixRecommender.predict(MatrixRecommender.java:272) at net.librec.recommender.MatrixRecommender.recommendRating(MatrixRecommender.java:238) at net.librec.recommender.MatrixRecommender.recommendRating(MatrixRecommender.java:219) at net.librec.eval.EvalContext.<init>(EvalContext.java:50) at net.librec.eval.EvalContext.<init>(EvalContext.java:57) at net.librec.job.RecommenderJob.executeEvaluator(RecommenderJob.java:213) at net.librec.job.RecommenderJob.executeRecommenderJob(RecommenderJob.java:131) at net.librec.job.RecommenderJob.runJob(RecommenderJob.java:89) at net.librec.tool.driver.RecDriver.run(RecDriver.java:84) at net.librec.tool.driver.RecDriver.main(RecDriver.java:108)

Am I doing something wrong?

Thanks,
Diarmuid

@diarmuidmorgan
Copy link
Author

Looking through the source code of cf.ItemKNNRecommender I see this line in the predict method:
if (isRanking) { return predictValue; } else { return predictValue > 0 ? itemMeans.get(userIdx) + predictValue / simSum : globalMean; } }

Else where in the train method, itemMeans is initialized with dimension n_users
`protected void trainModel() throws LibrecException {
itemMeans = new VectorBasedDenseVector(numItems);
double globalMean = trainMatrix.mean();
itemList = new ArrayList<>();
for (int itemIndex = 0; itemIndex < numItems; itemIndex++) {
itemList.add(itemIndex);
}
itemList.parallelStream().forEach(itemIndex -> {
SequentialSparseVector itemRatingVector = trainMatrix.column(itemIndex);
itemMeans.set(itemIndex, itemRatingVector.getNumEntries() > 0 ? itemRatingVector.mean() : globalMean);
});

    createItemSimilarityList();
}`

Should it be itemMeans.get(itemIdx) instead?

@ChenglongMa
Copy link

@diarmuidmorgan I got the same issue, and I agree with you. It should be itemMeans.get(itemIdx);
@wangyufengkevin could you fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants