org.apache.mahout.cf.taste.impl.neighborhood
Class NearestNUserNeighborhood

java.lang.Object
  extended by org.apache.mahout.cf.taste.impl.neighborhood.NearestNUserNeighborhood
All Implemented Interfaces:
Refreshable, UserNeighborhood

public final class NearestNUserNeighborhood
extends Object

Computes a neighborhood consisting of the nearest n users to a given user. "Nearest" is defined by the given UserSimilarity.


Constructor Summary
NearestNUserNeighborhood(int n, double minSimilarity, UserSimilarity userSimilarity, DataModel dataModel)
           
NearestNUserNeighborhood(int n, double minSimilarity, UserSimilarity userSimilarity, DataModel dataModel, double samplingRate)
           
NearestNUserNeighborhood(int n, UserSimilarity userSimilarity, DataModel dataModel)
           
 
Method Summary
 long[] getUserNeighborhood(long userID)
           
 void refresh(Collection<Refreshable> alreadyRefreshed)
           Triggers "refresh" -- whatever that means -- of the implementation.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

NearestNUserNeighborhood

public NearestNUserNeighborhood(int n,
                                UserSimilarity userSimilarity,
                                DataModel dataModel)
                         throws TasteException
Parameters:
n - neighborhood size; capped at the number of users in the data model
Throws:
IllegalArgumentException - if n < 1, or userSimilarity or dataModel are null
TasteException

NearestNUserNeighborhood

public NearestNUserNeighborhood(int n,
                                double minSimilarity,
                                UserSimilarity userSimilarity,
                                DataModel dataModel)
                         throws TasteException
Parameters:
n - neighborhood size; capped at the number of users in the data model
minSimilarity - minimal similarity required for neighbors
Throws:
IllegalArgumentException - if n < 1, or userSimilarity or dataModel are null
TasteException

NearestNUserNeighborhood

public NearestNUserNeighborhood(int n,
                                double minSimilarity,
                                UserSimilarity userSimilarity,
                                DataModel dataModel,
                                double samplingRate)
                         throws TasteException
Parameters:
n - neighborhood size; capped at the number of users in the data model
minSimilarity - minimal similarity required for neighbors
samplingRate - percentage of users to consider when building neighborhood -- decrease to trade quality for performance
Throws:
IllegalArgumentException - if n < 1 or samplingRate is NaN or not in (0,1], or userSimilarity or dataModel are null
TasteException
Method Detail

getUserNeighborhood

public long[] getUserNeighborhood(long userID)
                           throws TasteException
Parameters:
userID - ID of user for which a neighborhood will be computed
Returns:
IDs of users in the neighborhood
Throws:
TasteException - if an error occurs while accessing data

toString

public String toString()
Overrides:
toString in class Object

refresh

public final void refresh(Collection<Refreshable> alreadyRefreshed)
Description copied from interface: Refreshable

Triggers "refresh" -- whatever that means -- of the implementation. The general contract is that any Refreshable should always leave itself in a consistent, operational state, and that the refresh atomically updates internal state from old to new.

Specified by:
refresh in interface Refreshable
Parameters:
alreadyRefreshed - Refreshables that are known to have already been refreshed as a result of an initial call to a Refreshable.refresh(Collection) method on some object. This ensure that objects in a refresh dependency graph aren't refreshed twice needlessly.


Copyright © 2008–2014 The Apache Software Foundation. All rights reserved.