/** * @param dataModel * {@link DataModel} which provides users * @param clusterSimilarity * {@link ClusterSimilarity} used to compute cluster similarity * @param numClusters * desired number of clusters to create * @throws IllegalArgumentException * if arguments are {@code null}, or {@code numClusters} is less than 2 */ public TreeClusteringRecommender2(DataModel dataModel, ClusterSimilarity clusterSimilarity, int numClusters) : base(dataModel) { if (numClusters < 2) { throw new Exception("numClusters must be at least 2"); } //Preconditions.checkArgument(numClusters >= 2, "numClusters must be at least 2"); this.clusterSimilarity = clusterSimilarity;//Preconditions.checkNotNull(clusterSimilarity); this.numClusters = numClusters; this.clusteringThreshold = Double.NaN; this.clusteringByThreshold = false; this.refreshHelper = new RefreshHelper(buildClusters); refreshHelper.addDependency(dataModel); refreshHelper.addDependency(clusterSimilarity); buildClusters(); }
/** * @param dataModel * {@link DataModel} which provides users * @param clusterSimilarity * {@link ClusterSimilarity} used to compute cluster * similarity * @param clusteringThreshold * clustering similarity threshold; clusters will be aggregated into larger clusters until the next * two nearest clusters' similarity drops below this threshold * @throws IllegalArgumentException * if arguments are {@code null}, or {@code clusteringThreshold} is {@link Double#NaN} */ public TreeClusteringRecommender2(DataModel dataModel, ClusterSimilarity clusterSimilarity, double clusteringThreshold) : base(dataModel) { // Preconditions.checkArgument(!Double.isNaN(clusteringThreshold), "clusteringThreshold must not be NaN"); if (Double.IsNaN(clusteringThreshold)) { throw new Exception("clusteringThreshold must not be NaN"); } this.clusterSimilarity = clusterSimilarity; //Preconditions.checkNotNull(clusterSimilarity); this.numClusters = int.MinValue; // Integer.MIN_VALUE; this.clusteringThreshold = clusteringThreshold; this.clusteringByThreshold = true; this.refreshHelper = new RefreshHelper(buildClusters); refreshHelper.addDependency(dataModel); refreshHelper.addDependency(clusterSimilarity); buildClusters(); }
/** * @param dataModel * {@link DataModel} which provides users * @param clusterSimilarity * {@link ClusterSimilarity} used to compute cluster similarity * @param clusteringThreshold * clustering similarity threshold; clusters will be aggregated into larger clusters until the next * two nearest clusters' similarity drops below this threshold * @param samplingRate * percentage of all cluster-cluster pairs to consider when finding next-most-similar clusters. * Decreasing this value from 1.0 can increase performance at the cost of accuracy * @throws IllegalArgumentException * if arguments are {@code null}, or {@code clusteringThreshold} is {@link Double#NaN}, * or samplingRate is {@link Double#NaN} or nonpositive or greater than 1.0 */ public TreeClusteringRecommender(DataModel dataModel, ClusterSimilarity clusterSimilarity, double clusteringThreshold, double samplingRate) : base(dataModel) { //Preconditions.checkArgument(!Double.IsNaN(clusteringThreshold), "clusteringThreshold must not be NaN"); //Preconditions.checkArgument(samplingRate > 0.0 && samplingRate <= 1.0, "samplingRate is invalid: %f", samplingRate); random = RandomUtils.getRandom(); this.clusterSimilarity = clusterSimilarity; //Preconditions.checkNotNull(clusterSimilarity); this.numClusters = int.MinValue; //Integer.MIN_VALUE; this.clusteringThreshold = clusteringThreshold; this.clusteringByThreshold = true; this.samplingRate = samplingRate; this.refreshHelper = new RefreshHelper(buildClusters); refreshHelper.addDependency(dataModel); refreshHelper.addDependency(clusterSimilarity); buildClusters(); }
/** * @param dataModel * {@link DataModel} which provdes users * @param clusterSimilarity * {@link ClusterSimilarity} used to compute cluster similarity * @param numClusters * desired number of clusters to create * @param samplingRate * percentage of all cluster-cluster pairs to consider when finding next-most-similar clusters. * Decreasing this value from 1.0 can increase performance at the cost of accuracy * @throws IllegalArgumentException * if arguments are {@code null}, or {@code numClusters} is less than 2, or samplingRate * is {@link Double#NaN} or nonpositive or greater than 1.0 */ public TreeClusteringRecommender(DataModel dataModel, ClusterSimilarity clusterSimilarity, int numClusters, double samplingRate) : base(dataModel) { //Preconditions.checkArgument(numClusters >= 2, "numClusters must be at least 2"); //Preconditions.checkArgument(samplingRate > 0.0 && samplingRate <= 1.0, // "samplingRate is invalid: %f", samplingRate); random = RandomUtils.getRandom(); this.clusterSimilarity = clusterSimilarity;//Preconditions.checkNotNull(clusterSimilarity); this.numClusters = numClusters; this.clusteringThreshold = Double.NaN; this.clusteringByThreshold = false; this.samplingRate = samplingRate; this.refreshHelper = new RefreshHelper(buildClusters); refreshHelper.addDependency(dataModel); refreshHelper.addDependency(clusterSimilarity); buildClusters(); }
public MemoryDiffStorage(DataModel dataModel, Weighting stdDevWeighted, long maxEntries) { //Preconditions.checkArgument(dataModel != null, "dataModel is null"); //Preconditions.checkArgument(dataModel.getNumItems() >= 1, "dataModel has no items"); //Preconditions.checkArgument(maxEntries > 0L, "maxEntries must be positive"); this.dataModel = dataModel; this.stdDevWeighted = stdDevWeighted == Weighting.WEIGHTED; this.maxEntries = maxEntries; this.averageDiffs = new FastByIDMap <FastByIDMap <RunningAverage> >(); this.averageItemPref = new FastByIDMap <RunningAverage>(); this.buildAverageDiffsLock = new ReaderWriterLockSlim(); this.allRecommendableItemIDs = new FastIDSet(dataModel.getNumItems()); this.refreshHelper = new RefreshHelper(buildAverageDiffs); refreshHelper.addDependency(dataModel); buildAverageDiffs(); }