示例#1
0
        public void ReplaceWith(ISimilarityMatrix snapshot)
        {
            var snapshotDb     = snapshot as SqlceSimilarityMatrix;
            var snapshotDbPath = Paths.Database(snapshotDb.Instance, snapshotDb.DatabaseName);

            // If there's no data in the online matrix, the snapshot database will not be created
            if (!File.Exists(snapshotDbPath))
            {
                return;
            }

            var currentDbPath = Paths.Database(Instance, DatabaseName);

            if (File.Exists(currentDbPath))
            {
                var tempPath = Paths.Database(Instance, DatabaseName + "_tmp");
                File.Move(currentDbPath, tempPath);
                File.Move(snapshotDbPath, currentDbPath);
                File.Delete(tempPath);
            }
            else
            {
                File.Move(snapshotDbPath, currentDbPath);
            }
        }
示例#2
0
        public Delphi(BookData dataSet, RecommendationType type)
        {
            this.type = type;
            bool useCache = false; // by default don't use cache
            SimilarityMatrixRepository smRepo = new SimilarityMatrixRepository(useCache);

            this.similarityMatrix = smRepo.load(type, dataSet);
            this.dataSet          = dataSet;

            maxPredictedRating = new Dictionary <int, double>(dataSet.getUserCount() / 2);
        }
示例#3
0
        public Delphi(BookData dataSet, RecommendationType type, ISimilarityMatrix similarityMatrix)
        {
            Console.WriteLine("Enetring Delphi(Dataset,RecomendationType, SimilarityMatrix) constructor...");

            this.type             = type;
            this.similarityMatrix = similarityMatrix;
            this.dataSet          = dataSet;

            maxPredictedRating = new Dictionary <int, double>(dataSet.getUserCount() / 2);


            Console.WriteLine("Leaving Delphi(Dataset,RecomendationType,SimilarityMatrix) constructor...");
        }
示例#4
0
        public Delphi(BookData dataset, RecommendationType type, bool useSimilarityCache)
        {
            Console.WriteLine("Enetring Delphi(Dataset,RecomendationType, bool) constructor...");

            this.type = type;
            SimilarityMatrixRepository smRepo = new SimilarityMatrixRepository(useSimilarityCache);

            this.similarityMatrix = smRepo.load(type, dataset);
            this.dataSet          = dataSet;

            maxPredictedRating = new Dictionary <int, double>(dataSet.getUserCount() / 2);

            Console.WriteLine("Leaving Delphi(Dataset,RecomendationType,boolean) constructor...");
        }
示例#5
0
        public static void Register(string instance, string behaviorType, ISimilarityMatrix matrix)
        {
            if (!_matrixesByInstances.ContainsKey(instance))
            {
                _matrixesByInstances.Add(instance, new Dictionary<string, ISimilarityMatrix>());
            }

            var matrixesByNames = _matrixesByInstances[instance];
            if (matrixesByNames.ContainsKey(behaviorType))
            {
                matrixesByNames[behaviorType] = matrix;
            }
            else
            {
                matrixesByNames.Add(behaviorType, matrix);
            }
        }
示例#6
0
        public static void Register(string instance, string behaviorType, ISimilarityMatrix matrix)
        {
            if (!_matrixesByInstances.ContainsKey(instance))
            {
                _matrixesByInstances.Add(instance, new Dictionary <string, ISimilarityMatrix>());
            }

            var matrixesByNames = _matrixesByInstances[instance];

            if (matrixesByNames.ContainsKey(behaviorType))
            {
                matrixesByNames[behaviorType] = matrix;
            }
            else
            {
                matrixesByNames.Add(behaviorType, matrix);
            }
        }
        public ISimilarityMatrix load(RecommendationType type, BookData data, bool keepRatingCountMatrix)
        {
            ISimilarityMatrix m = null;

            switch (type)
            {
            case RecommendationType.ITEM_BASED:
                m = new ItemBasedSimilarity(data, keepRatingCountMatrix);
                break;

            case RecommendationType.ITEM_PENALTY_BASED:
                // m = new ItemPenaltyBasedSimilarity(IDictionary, data, keepRatingMatrix);
                break;

            case RecommendationType.USER_BASED:
                m = new UserBasedSimilarity(data, keepRatingCountMatrix);
                break;

            case RecommendationType.IMPROVED_USER_BASED:
                // m = new ImprovedUserBasedSimilarity(id, data, keepRatingCountMatrix);
                break;

            case RecommendationType.USER_CONTENT_BASED:
                // m = new UserContentBasedSimilarity(id, data);
                break;

            case RecommendationType.ITEM_CONTENT_BASED:
                // m = new ItemContentBasedSimilarity(id, data);
                break;

            case RecommendationType.USER_ITEM_CONTENT_BASED:
                // m = new UserItemContentBasedSimilarity(id, data);
                break;

            default: break;
            }

            if (cache != null)
            {
            }

            return(m);
        }
示例#8
0
        private void Recompute(ISimilarityMatrix matrix, IBehaviorStore behaviorStore)
        {
            var allItems = behaviorStore.GetAllItems().ToList();

            if (allItems.Count == 0)
            {
                return;
            }

            var calculator = new ItemSimilarityCalculator(behaviorStore, NullItemPopularityProvider.Instance);
            var batch      = new Dictionary <ItemPair, double>();

            for (var i = 0; i < allItems.Count; i++)
            {
                for (var j = i + 1; j < allItems.Count; j++)
                {
                    var item1 = allItems[i];
                    var item2 = allItems[j];

                    var similarity = calculator.CalculateSimilarity(item1, item2);
                    if (similarity > 0)
                    {
                        batch.Add(new ItemPair(item1, item2), similarity);

                        if (batch.Count == _updateBatchSize)
                        {
                            matrix.AddSimilarities(batch);
                            batch.Clear();
                        }
                    }
                }
            }

            if (batch.Count > 0)
            {
                matrix.AddSimilarities(batch);
            }
        }
        private void Recompute(ISimilarityMatrix matrix, IBehaviorStore behaviorStore)
        {
            var allItems = behaviorStore.GetAllItems().ToList();
            if (allItems.Count == 0)
            {
                return;
            }

            var calculator = new ItemSimilarityCalculator(behaviorStore, NullItemPopularityProvider.Instance);
            var batch = new Dictionary<ItemPair, double>();

            for (var i = 0; i < allItems.Count; i++)
            {
                for (var j = i + 1; j < allItems.Count; j++)
                {
                    var item1 = allItems[i];
                    var item2 = allItems[j];

                    var similarity = calculator.CalculateSimilarity(item1, item2);
                    if (similarity > 0)
                    {
                        batch.Add(new ItemPair(item1, item2), similarity);

                        if (batch.Count == _updateBatchSize)
                        {
                            matrix.AddSimilarities(batch);
                            batch.Clear();
                        }
                    }
                }
            }

            if (batch.Count > 0)
            {
                matrix.AddSimilarities(batch);
            }
        }
 public ItemToItemRelatedItemsProvider(ISimilarityMatrix matrix)
 {
     _matrix = matrix;
 }
示例#11
0
        public void ReplaceWith(ISimilarityMatrix snapshot)
        {
            var snapshotDb = snapshot as SqlceSimilarityMatrix;
            var snapshotDbPath = Paths.Database(snapshotDb.Instance, snapshotDb.DatabaseName);
            // If there's no data in the online matrix, the snapshot database will not be created
            if (!File.Exists(snapshotDbPath))
            {
                return;
            }

            var currentDbPath = Paths.Database(Instance, DatabaseName);

            if (File.Exists(currentDbPath))
            {
                var tempPath = Paths.Database(Instance, DatabaseName + "_tmp");
                File.Move(currentDbPath, tempPath);
                File.Move(snapshotDbPath, currentDbPath);
                File.Delete(tempPath);
            }
            else
            {
                File.Move(snapshotDbPath, currentDbPath);
            }
        }
 public ItemToItemRelatedItemsProvider(ISimilarityMatrix matrix)
 {
     _matrix = matrix;
 }