public double computeSimilarity(int item1, int item2) {

		double sim = 0;

		ArrayList<Integer> sharedUsers = new ArrayList<Integer>();
		for (Integer user : data.getUsersByItem().get(item1)) {
			if (data.getUsersByItem().get(item2).contains(user)) {
				sharedUsers.add(user);
			}
		}

		if (sharedUsers.isEmpty()) {
			return sim;
		}

		double[] item1Ratings = new double[sharedUsers.size()];
		double[] item2Ratings = new double[sharedUsers.size()];

		int i = 0;
		for (Integer user : sharedUsers) {
			item1Ratings[i] = data.getUserItemRatings().get(user).get(item1);
			item2Ratings[i] = data.getUserItemRatings().get(user).get(item2);
			i++;
		}

		// Calculate the similarity using the defined metric
		if (sMetric.equals("cosine")) {
			sim = Similarity.calculateCosineSimilarity(item1Ratings,
					item2Ratings);
		} else if (sMetric.equals("pearson")) {
			sim = Similarity.calculatePearsonCorrelation(item1Ratings,
					item2Ratings, data.getAverageItemRatings().get(item1),
					data.getAverageItemRatings().get(item2));
		}

		return sim;
	}