Yes nevermind that doesn't quite work.

I don't think you want to change the code as you say, since, you
really only want to consider items that users in the neighborhood
express a preference for. I guess this doesn't really work, when
approached this way -- the code definitely strongly assumes there is
one DataModel!

There are some alternatives though:

1) Do you really want two models? surely it would be better to base
your similarity computations on the 'real' data?

2) If you really want to compute similarities based on other data, I
think you will have to pre-compute all of those user-user
similarities, first, separately, then store them in a new
implementation of UserSimilarity. Do you see GenericItemSimilarity?
This is exactly what you need -- but for a UserSimilarity. Perhaps I
can make this implementation tonight. The disadvantage is that it will
consume a lot of memory to store all user-user similarities, but, it
will be fast.

2009/4/14 郑楠 <[email protected]>:
> Sorry, when I changed model to modelPaper in UserNeighborhood, the program
> computes the similarity using modelPaper, which is against my wish. I
> tracked the code, and found when generating the recommendation the
> method getAllOtherItems in class GenericUserBasedRecommender used model data
> not modelPaper data. After rewrite this method, it can use modelPaper data,
> the following is my rewriting code:
>   private Set<Item> getAllOtherItems(Iterable<User> theNeighborhood, User
> theUser) throws TasteException {
>     Set<Item> allItems = new FastSet<Item>();
>     DataModel model = getDataModel();
>     Iterable<? extends User> allUsers;
>     allUsers=model.getUsers();
>     for (User userNew : allUsers) {
>      for (User user : theNeighborhood) {
>      if(userNew.equals(user)){
>           Preference[] prefs = userNew.getPreferencesAsArray();
>           for (Preference pref : prefs) {
>             Item item = pref.getItem();
>             // If not already preferred by the user, add it
>             if (theUser.getPreferenceFor(item.getID()) == null) {
>               allItems.add(item);
>             }
>           }
>         }
>      }
>     }
>
>     return allItems;
>   }
> But it brings new problems. When computing the neighborhood of a user, the
> program uses model data, while computing the similarity of users in the
> phase of recommendedItems, it uses modelPaper data, which is not my wish. I
> guess the problem comes from estimate(Item item) method in
> class GenericUserBasedRecommender, here theUser refers to users in
> modelPaper, but I cannot find the solution. Do you have any idea?
> By the way, my database is much larger than the sample, the data I showed to
> you is the testing data which I used to check the methods. So when using
> real database, I'll change the number of neighbors to a large scale. Thank
> you for your advice. ^_^

Reply via email to