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

There may be something wrong about ItemKNN.java #3

Open
hegongshan opened this issue Oct 7, 2020 · 0 comments
Open

There may be something wrong about ItemKNN.java #3

hegongshan opened this issue Oct 7, 2020 · 0 comments

Comments

@hegongshan
Copy link

Hi, Prof. He!
In the ItemKNN.java, the similarity matrix is a diagonal matrix but the method buildModel_items only seems to calculate the values in the lower triangular part and doesn't assign the values to the symmetry elements.
The experimental results show that there are some differences between using itemCount && j != i and itemCount in line 5 (line 71 of the original code).

protected void buildModel_items(int startItem, int endItem) {
		// Build the similarity matrix for selected items.
		for (int i = startItem; i < endItem; i++) {
			HashMap<Integer, Double> map_item_score = new HashMap<Integer, Double>();
			for (int j = 0; j < itemCount && j != i; j++) {
				// Cosine similarity
				double score = trainMatrix.getColRef(i).innerProduct(trainMatrix.getColRef(j));
				if (score != 0) {
					score /= (lengths[i] * lengths[j]);
					map_item_score.put(j, score);
				}
			}
			if (K <= 0) { // All neighbors
				for (int j : map_item_score.keySet()) {
					similarity.setValue(i, j, map_item_score.get(j));
				}
			} else { // Only K nearest neighbors
				for (int j : CommonUtils.TopKeysByValue(map_item_score, K, null)) {
					similarity.setValue(i, j, map_item_score.get(j));
				}
			} // end if
		} // end for

for (int j = 0; j < itemCount & j != i; j ++) {

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

1 participant