internal MostSimilarEstimator(User toUser, UserCorrelation correlation, Rescorer <Pair <User, User> > rescorer) { this.toUser = toUser; this.correlation = correlation; this.rescorer = rescorer; }
public SpearmanCorrelation(DataModel dataModel) { if (dataModel == null) { throw new ArgumentNullException("dataModel is null"); } this.rankingUserCorrelation = new PearsonCorrelation(dataModel); this.refreshLock = new ReentrantLock(); }
public SpearmanCorrelation(UserCorrelation rankingUserCorrelation) { if (rankingUserCorrelation == null) { throw new ArgumentNullException("rankingUserCorrelation is null"); } this.rankingUserCorrelation = rankingUserCorrelation; this.refreshLock = new ReentrantLock(); }
/** * <p>Constructs a {@link FarthestNeighborClusterSimilarity} based on the given {@link UserCorrelation}. * By setting <code>samplingPercentage</code> to a value less than 1.0, this implementation will only examine * that fraction of all user-user correlations between two clusters, increasing performance at the expense * of accuracy.</p> * * @param Correlation * @param samplingPercentage * @since 1.4.5 */ public FarthestNeighborClusterSimilarity(UserCorrelation correlation, double samplingPercentage) { if (correlation == null) { throw new ArgumentNullException("Correlation is null"); } if (double.IsNaN(samplingPercentage) || samplingPercentage <= 0.0 || samplingPercentage > 1.0) { throw new ArgumentException("samplingPercentage is invalid: " + samplingPercentage); } this.correlation = correlation; this.samplingPercentage = samplingPercentage; }
/// <summary> /// construct a NearestNUserNeighborhood /// </summary> /// <param name="n">n Neighborhood size</param> /// <param name="userCorrelation">nearness metric</param> /// <param name="dataModel">data Model</param> /// <param name="samplingRate">percentage of users to consider when building Neighborhood -- decrease to /// trade quality for performance</param> public NearestNUserNeighborhood(int n, UserCorrelation userCorrelation, DataModel dataModel, double samplingRate) : base(userCorrelation, dataModel, samplingRate) { if (n < 1) { throw new ArgumentException("n must be at least 1"); } this.cache = new SoftCache <Object, ICollection <User> >(new Retriever(this, n), dataModel.GetNumUsers()); }
/** * @param threshold similarity threshold * @param userCorrelation similarity metric * @param dataModel data Model * @param samplingRate percentage of users to consider when building Neighborhood -- decrease to * trade quality for performance * @throws IllegalArgumentException if threshold or samplingRate is {@link Double#NaN}, * or if samplingRate is not positive and less than or equal to 1.0, or if userCorrelation * or dataModel are <code>null</code> * @since 1.3 */ public ThresholdUserNeighborhood(double threshold, UserCorrelation userCorrelation, DataModel dataModel, double samplingRate) : base(userCorrelation, dataModel, samplingRate) { if (Double.IsNaN(threshold)) { throw new ArgumentException("threshold must not be NaN"); } this.cache = new SoftCache <Object, ICollection <User> >(new Retriever(this, threshold), dataModel.GetNumUsers()); }
public GenericUserBasedRecommender(DataModel dataModel, UserNeighborhood neighborhood, UserCorrelation correlation) : base(dataModel) { if (neighborhood == null) { throw new ArgumentNullException("Neighborhood is null"); } this.neighborhood = neighborhood; this.correlation = correlation; this.refreshLock = new ReentrantLock(); }
/// <summary> /// <p>Constructs a <see cref="taste.Recommender.NearestNeighborClusterSimilarity">NearestNeighborClusterSimilarity</see> based on the given /// <see cref="taste.Correlation.UserCorrelation">UserCorrelation</see>. /// By setting <code>samplingPercentage</code> to a value less than 1.0, this implementation will only examine /// that fraction of all user-user correlations between two clusters, increasing performance at the expense /// of accuracy.</p> /// </summary> /// <param name="Correlation"></param> /// <param name="samplingPercentage"></param> public NearestNeighborClusterSimilarity(UserCorrelation correlation, double samplingPercentage) { if (correlation == null) { throw new ArgumentNullException("Correlation is null"); } if (double.IsNaN(samplingPercentage) || samplingPercentage <= 0.0 || samplingPercentage > 1.0) { throw new ArgumentException("samplingPercentage is invalid: " + samplingPercentage); } this.correlation = correlation; this.samplingPercentage = samplingPercentage; }
public AbstractUserNeighborhood(UserCorrelation userCorrelation, DataModel dataModel, double samplingRate) { if (userCorrelation == null || dataModel == null) { throw new ArgumentNullException("userCorrelation or dataModel is null"); } if (Double.IsNaN(samplingRate) || samplingRate <= 0.0 || samplingRate > 1.0) { throw new ArgumentException("samplingRate must be in (0,1]"); } this.userCorrelation = userCorrelation; this.dataModel = dataModel; this.samplingRate = samplingRate; }
public ICollection <User> GetValue(Object key) { if (log.IsInfoEnabled) { log.Info("Computing Neighborhood around user ID '" + key + '\''); } DataModel dataModel = _owner.DataModel; User theUser = dataModel.GetUser(key); IList <User> neighborhood = new List <User>(); IEnumerable <User> users = dataModel.GetUsers(); UserCorrelation userCorrelationImpl = _owner.UserCorrelation; IEnumerator <User> en = users.GetEnumerator(); while (en.MoveNext()) { User user = en.Current; if (_owner.SampleForUser && !key.Equals(user.ID)) { double theCorrelation = userCorrelationImpl.GetUserCorrelation(theUser, user); if (!Double.IsNaN(theCorrelation) && theCorrelation >= threshold) { neighborhood.Add(user); } } } if (log.IsInfoEnabled) { log.Info("UserNeighborhood around user ID '" + key + "' is: " + neighborhood); } //return Collections.unmodifiableList(Neighborhood); return(neighborhood); }
/** * @param threshold similarity threshold * @param userCorrelation similarity metric * @param dataModel data Model * @throws IllegalArgumentException if threshold is {@link Double#NaN}, * or if samplingRate is not positive and less than or equal to 1.0, or if userCorrelation * or dataModel are <code>null</code> */ public ThresholdUserNeighborhood(double threshold, UserCorrelation userCorrelation, DataModel dataModel) : this(threshold, userCorrelation, dataModel, 1.0) { }
public ICollection <User> GetValue(Object key) { if (log.IsInfoEnabled) { log.Info("Computing Neighborhood around user ID '" + key + '\''); } DataModel dataModel = owner.DataModel; User theUser = dataModel.GetUser(key); UserCorrelation userCorrelationImpl = owner.UserCorrelation; LinkedList <UserCorrelationPair> queue = new LinkedList <UserCorrelationPair>(); bool full = false; foreach (User user in dataModel.GetUsers()) { if (owner.SampleForUser && !key.Equals(user.ID)) { double theCorrelation = userCorrelationImpl.GetUserCorrelation(theUser, user); if (!Double.IsNaN(theCorrelation) && (!full || theCorrelation > queue.Last.Value.Correlation)) { LinkedListNode <UserCorrelationPair> iterator = queue.Last; while (iterator != null && iterator.Previous != null) { iterator = iterator.Previous; if (theCorrelation <= iterator.Value.Correlation) { iterator = iterator.Next; break; } if (iterator == queue.First) { break; } } UserCorrelationPair pair = new UserCorrelationPair(user, theCorrelation); if (iterator == null) { queue.AddFirst(pair); } else { queue.AddAfter(iterator, pair); } if (full) { queue.RemoveLast(); } else if (queue.Count > n) { full = true; queue.RemoveLast(); } } } } IList <User> neighborhood = new List <User>(queue.Count); foreach (UserCorrelationPair pair in queue) { //assert pair != null; neighborhood.Add(pair.User); } if (log.IsInfoEnabled) { log.Info("UserNeighborhood around user ID '" + key + "' is: " + neighborhood); } //return Collections.unmodifiableList(Neighborhood); return(neighborhood); }
/** * <p>Constructs a {@link FarthestNeighborClusterSimilarity} based on the given {@link UserCorrelation}. * All user-user correlations are examined.</p> * * @param Correlation */ public FarthestNeighborClusterSimilarity(UserCorrelation correlation) :this(correlation, 1.0) { }
/// <summary> /// construct a NearestNUserNeighborhood /// </summary> /// <param name="n">Neighborhood size</param> /// <param name="userCorrelation">nearness metric</param> /// <param name="dataModel">data Model</param> public NearestNUserNeighborhood(int n, UserCorrelation userCorrelation, DataModel dataModel) : this(n, userCorrelation, dataModel, 1.0) { }
/** * <p>Constructs a {@link NearestNeighborClusterSimilarity} based on the given {@link UserCorrelation}. * All user-user correlations are examined.</p> * * @param Correlation */ public NearestNeighborClusterSimilarity(UserCorrelation correlation) : this(correlation, 1.0) { }