@Override
	public void train() {

		double sim = 0;

		String[] t = socialNeighbourhood.split("_");
		int k = new Integer(t[1]);

		for (Integer user1 : data.getItemsByUser().keySet()) {
			if (data.getUserFriends().get(user1) == null) {
				// User has no friends :)
				continue;
			}

			ArrayList<Integer> friendsKthLevel = getFriendsKthLevel(user1, k);

			for (Integer user2 : friendsKthLevel) {

				if (user1 < user2) {

					sim = computeSimilarity(user1, user2);

					if (socialThreshold != null) {
						if (sim < socialThreshold) {
							continue;
						}
					}

					// this is for user1's list
					if (userSimilarities.containsKey(user1)) {
						userSimilarities.get(user1).put(user2, sim);
					} else {
						LinkedHashMap<Integer, Double> s = new LinkedHashMap<Integer, Double>();
						s.put(user2, sim);
						userSimilarities.put(user1, s);
					}

					// this is for user2's list
					if (userSimilarities.containsKey(user2)) {
						userSimilarities.get(user2).put(user1, sim);
					} else {
						LinkedHashMap<Integer, Double> s = new LinkedHashMap<Integer, Double>();
						s.put(user1, sim);
						userSimilarities.put(user2, s);
					}

				}
			}
		}

		// Calculate the average size of the similarity lists
		int similaritiesCount = 0;
		for (Map.Entry<Integer, LinkedHashMap<Integer, Double>> entry : userSimilarities.entrySet()) {
			similaritiesCount += entry.getValue().size();
		}
		Recommender.setAverageSizeOfSimilarityListUsers((double) similaritiesCount
				/ (double) userSimilarities.size());

	}