TreeClusteringRecommender extends AbstractRecommender implements ClusteringRecommender { @Override public float estimatePreference(long userID, long itemID) throws TasteException { DataModel model = getDataModel(); Float actualPref = model.getPreferenceValue(userID, itemID); if (actualPref != null) { return actualPref; } buildClusters(); List<RecommendedItem> topRecsForUser = topRecsByUserID.get(userID); if (topRecsForUser != null) { for (RecommendedItem item : topRecsForUser) { if (itemID == item.getItemID()) { return item.getValue(); } } } return Float.NaN; } TreeClusteringRecommender(DataModel dataModel, ClusterSimilarity clusterSimilarity, int numClusters);  TreeClusteringRecommender(DataModel dataModel,
                                   ClusterSimilarity clusterSimilarity,
                                   int numClusters,
                                   double samplingRate);  TreeClusteringRecommender(DataModel dataModel,
                                   ClusterSimilarity clusterSimilarity,
                                   double clusteringThreshold);  TreeClusteringRecommender(DataModel dataModel,
                                   ClusterSimilarity clusterSimilarity,
                                   double clusteringThreshold,
                                   double samplingRate); @Override List<RecommendedItem> recommend(long userID, int howMany, IDRescorer rescorer); @Override float estimatePreference(long userID, long itemID); @Override FastIDSet getCluster(long userID); @Override FastIDSet[] getClusters(); @Override void refresh(Collection<Refreshable> alreadyRefreshed); @Override String toString();  }
@Test public void testEstimatePref() throws Exception { DataModel dataModel = getDataModel( new long[] {1, 2, 3, 4}, new Double[][] { {0.1, 0.3}, {0.2, 0.3, 0.3}, {0.4, 0.3, 0.5}, {0.7, 0.3, 0.8, 0.9}, }); UserSimilarity similarity = new PearsonCorrelationSimilarity(dataModel); ClusterSimilarity clusterSimilarity = new FarthestNeighborClusterSimilarity(similarity); Recommender recommender = new TreeClusteringRecommender(dataModel, clusterSimilarity, 2); assertEquals(0.9f, recommender.estimatePreference(3, 3), EPSILON); }