Esempio n. 1
0
		/**
		 * @param dataFile file containing preferences data
		 * @throws FileNotFoundException if dataFile does not exist
		 */
		public FileDataModel(String dataFile, bool autoReload)
		{
			if (String.IsNullOrEmpty(dataFile)) 
			{
				throw new ArgumentNullException("dataFile is null");
			}
            if (File.Exists(dataFile))
            {
				throw new FileNotFoundException(dataFile);
			}

            if (log.IsInfoEnabled)
            {
                log.Info("Creating FileDataModel for file " + dataFile);
            }

			this.dataFile = dataFile;
			this.lastModified = File.GetLastWriteTime(dataFile);
			this.refreshLock = new ReentrantLock();
			this.reloadLock = new ReentrantLock();

            this.useReload = autoReload;
            if (autoReload)
            {
                // Create the delegate that invokes methods for the timer.
                TimerCallback timerDelegate =
                    new TimerCallback(CheckStatus);

                // Schedule next refresh
                timer = new Timer(timerDelegate, this, RELOAD_CHECK_INTERVAL_MS, RELOAD_CHECK_INTERVAL_MS);
            }
		}
Esempio n. 2
0
		protected AbstractRecommender(DataModel dataModel) 
		{
			if (dataModel == null) 
            {
				throw new ArgumentNullException("dataModel is null");
			}
			this.dataModel = dataModel;
			this.refreshLock = new ReentrantLock();
		}
Esempio n. 3
0
		public SpearmanCorrelation(UserCorrelation rankingUserCorrelation) 
		{
			if (rankingUserCorrelation == null) 
			{
				throw new ArgumentNullException("rankingUserCorrelation is null");
			}
			this.rankingUserCorrelation = rankingUserCorrelation;
			this.refreshLock = new ReentrantLock();		
		}
Esempio n. 4
0
		public SpearmanCorrelation(DataModel dataModel) 
		{
			if (dataModel == null) 
			{
				throw new ArgumentNullException("dataModel is null");
			}
			this.rankingUserCorrelation = new PearsonCorrelation(dataModel);
			this.refreshLock = new ReentrantLock();
		}
Esempio n. 5
0
        /// <summary>
        /// <p>Creates a new {@link MemoryDiffStorage}.</p>
        /// <p>See {@link taste.Recommender.SlopeOne.SlopeOneRecommender} for the
        /// meaning of <code>stdDevWeighted</code>. If <code>compactAverages</code>
        /// is set, this uses alternate data structures ({@link CompactRunningAverage} versus
        /// {@link FullRunningAverage}) that use almost 50% less memory but store item-item
        /// averages less accurately. <code>maxEntries</code> 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 <code>maxEntries</code> 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.</p>
        /// <p>  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
        /// {@link SlopeOneRecommender}, which otherwise grow as the square of the number of items that exist 
        /// in the {@link DataModel}. Memory requirements can reach gigabytes with only about 10000 items, so this may
        /// be necessary on larger datasets.</p>
        /// </summary>
        /// <param name="dataModel"></param>
        /// <param name="stdDevWeighted">see  {@link taste.Recommender.SlopeOne.SlopeOneRecommender}</param>
        /// <param name="compactAverages">
        /// if <code>true</code>, use {@link CompactRunningAverage} instead of {@link FullRunningAverage} internally
        /// </param>
        /// <param name="maxEntries">maximum number of item-item average preference differences to track internally</param>
		public MemoryDiffStorage(DataModel dataModel,
		                         bool stdDevWeighted,
		                         bool compactAverages,
		                         long maxEntries) 
		{
			if (dataModel == null) 
            {
				throw new ArgumentNullException("dataModel is null");
			}
			if (maxEntries <= 0L) 
            {
				throw new ArgumentException("maxEntries must be positive");
			}
			this.dataModel = dataModel;
			this.stdDevWeighted = stdDevWeighted;
			this.compactAverages = compactAverages;
			this.maxEntries = maxEntries;
			this.averageDiffs = new Dictionary<Object, Dictionary<Object, RunningAverage>>(1003);
			this.averageItemPref = new Dictionary<Object, RunningAverage>(101);
			this.buildAverageDiffsLock = new ReaderWriterLock();
			this.refreshLock = new ReentrantLock();
			BuildAverageDiffs();
		}
 protected AbstractADODiffStorage(AbstractADODataModel dataModel,
                                   String getDiffSQL,
                                   String getDiffsSQL,
                                   String getAverageItemPrefSQL,
                                   String[] updateDiffSQLs,
                                   String[] removeDiffSQLs,
                                   String getRecommendableItemsSQL,
                                   String deleteDiffsSQL,
                                   String createDiffsSQL,
                                   String diffsExistSQL,
                                   int minDiffCount)
 {
     if (dataModel == null)
     {
         throw new ArgumentNullException("dataModel is null");
     }
     if (minDiffCount < 0)
     {
         throw new ArgumentException("minDiffCount is not positive");
     }
     this.dataModel = dataModel;
     this.getDiffSQL = getDiffSQL;
     this.getDiffsSQL = getDiffsSQL;
     this.getAverageItemPrefSQL = getAverageItemPrefSQL;
     this.updateDiffSQLs = updateDiffSQLs;
     this.removeDiffSQLs = removeDiffSQLs;
     this.getRecommendableItemsSQL = getRecommendableItemsSQL;
     this.deleteDiffsSQL = deleteDiffsSQL;
     this.createDiffsSQL = createDiffsSQL;
     this.diffsExistSQL = diffsExistSQL;
     this.minDiffCount = minDiffCount;
     this.refreshLock = new ReentrantLock();
     if (IsDiffsExist())
     {
         log.Info("Diffs already exist in database; using them instead of recomputing");
     }
     else
     {
         log.Info("No diffs exist in database; recomputing...");
         BuildAverageDiffs();
     }
 }