## org.apache.mahout.cf.taste.impl.recommender.slopeone
Class MemoryDiffStorage

    java.lang.Object
      org.apache.mahout.cf.taste.impl.recommender.slopeone.MemoryDiffStorage

All Implemented Interfaces:
  Refreshable, DiffStorage

    public final class MemoryDiffStorage

extends java.lang.Object
implements DiffStorage

An implementation of `DiffStorage` that merely stores item-item diffs in memory. It is fast, but can consume a great deal of memory.

Constructor Summary
`MemoryDiffStorage(DataModel dataModel, Weighting stdDevWeighted, boolean compactAverages, long maxEntries)` Creates a new .

Method Summary
`RunningAverage` `getAverageItemPref(long itemID)`
`RunningAverage` `getDiff(long itemID1, long itemID2)`
`RunningAverage[]` `getDiffs(long userID, long itemID, PreferenceArray prefs)`
`FastIDSet` `getRecommendableItemIDs(long userID)`
`void` `refresh(java.util.Collection<Refreshable> alreadyRefreshed)` Triggers "refresh" -- whatever that means -- of the implementation.
`java.lang.String` `toString()`
`void` `updateItemPref(long itemID, float prefDelta, boolean remove)` Updates internal data structures to reflect an update in a preference value for an item.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### MemoryDiffStorage

    public MemoryDiffStorage(DataModel dataModel,
                             Weighting stdDevWeighted,
                             boolean compactAverages,
                             long maxEntries)
                      throws TasteException

  Creates a new .

  See `SlopeOneRecommender` for the meaning of `stdDevWeighted`. If `compactAverages` is set, this uses alternate data structures (`CompactRunningAverage` versus `FullRunningAverage`) that use almost 50% less memory but store item-item averages less accurately. `maxEntries` controls the maximum number of item-item average preference differences that will be tracked internally. After the limit is reached, if a new item-item pair is observed in the data it will be ignored. This is recommended for large datasets. The first `maxEntries` item-item pairs observed in the data are tracked. Assuming that item ratings are reasonably distributed among users, this should only ignore item-item pairs that are very infrequently co-rated by a user. The intuition is that data on these infrequently co-rated item-item pairs is less reliable and should be the first that is ignored. This parameter can be used to limit the memory requirements of `SlopeOneRecommender`, which otherwise grow as the square of the number of items that exist in the `DataModel`. Memory requirements can reach gigabytes with only about 10000 items, so this may be necessary on larger datasets.

  Parameters:
    `stdDevWeighted` - see `SlopeOneRecommender`
    `compactAverages` - if `true`, use `CompactRunningAverage` instead of `FullRunningAverage` internally
    `maxEntries` - maximum number of item-item average preference differences to track internally
  Throws:
    `java.lang.IllegalArgumentException` - if `maxEntries` is not positive or `dataModel` is null
    `TasteException`

Method Detail

### getDiff

    public RunningAverage getDiff(long itemID1,
                                  long itemID2)

  Specified by:
    `getDiff` in interface `DiffStorage`
  Returns:
    `RunningAverage` encapsulating the average difference in preferences between items corresponding to `itemID1` and `itemID2`, in that direction; that is, it's the average of item 2's preferences minus item 1's preferences

### getDiffs

    public RunningAverage[] getDiffs(long userID,
                                     long itemID,
                                     PreferenceArray prefs)

  Specified by:
    `getDiffs` in interface `DiffStorage`
  Parameters:
    `userID` - user ID to get diffs for
    `itemID` - itemID to assess
    `prefs` - user's preferendces
  Returns:
    `RunningAverage`s for that user's item-item diffs

### getAverageItemPref

    public RunningAverage getAverageItemPref(long itemID)

  Specified by:
    `getAverageItemPref` in interface `DiffStorage`
  Returns:
    `RunningAverage` encapsulating the average preference for the given item

### updateItemPref

    public void updateItemPref(long itemID,
                               float prefDelta,
                               boolean remove)

  Description copied from interface: `DiffStorage`

  Updates internal data structures to reflect an update in a preference value for an item.

  Specified by:
    `updateItemPref` in interface `DiffStorage`
  Parameters:
    `itemID` - item to update preference value for
    `prefDelta` - amount by which preference value changed (or its old value, if being removed
    `remove` - if `true`, operation reflects a removal rather than change of preference

### getRecommendableItemIDs

    public FastIDSet getRecommendableItemIDs(long userID)
                                      throws TasteException

  Specified by:
    `getRecommendableItemIDs` in interface `DiffStorage`
  Returns:
    item IDs that may possibly be recommended to the given user, which may not be all items since the item-item diff matrix may be sparse
  Throws:
    `TasteException`

### refresh

    public void refresh(java.util.Collection<Refreshable> alreadyRefreshed)

  Description copied from interface: `Refreshable`

  Triggers "refresh" -- whatever that means -- of the implementation. The general contract is that any 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` - s that are known to have already been refreshed as a result of an initial call to a method on some object. This ensure that objects in a refresh dependency graph aren't refreshed twice needlessly.

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `java.lang.Object`

Copyright © 2008-2010 The Apache Software Foundation. All Rights Reserved.