Esempio n. 1
0
        public void TestGetPositivelyCorrelatedEntities()
        {
            // create a test CorrelationMatrix
            var matrix = new SymmetricCorrelationMatrix(3);

            matrix[0, 0] = 1f;
            matrix[0, 1] = 0.1f;
            matrix[0, 2] = -0.2f;
            matrix[1, 0] = 0.1f;
            matrix[1, 1] = 1f;
            matrix[1, 2] = 0.3f;
            matrix[2, 0] = -0.2f;
            matrix[2, 1] = 0.3f;
            matrix[2, 2] = 1f;

            Assert.AreEqual(1f, matrix[0, 0]);
            Assert.AreEqual(0.3f, matrix[1, 2]);

            // test
            IList <int> cor_entities_list = matrix.GetPositivelyCorrelatedEntities(2);

            int[] cor_entities = new int[1];
            cor_entities_list.CopyTo(cor_entities, 0);
            int[] pos_cor_entities = { 1 };
            Assert.AreEqual(pos_cor_entities, cor_entities);
        }
        /// <summary>map to latent factor space (actual function)</summary>
        protected override float[] __MapToLatentFactorSpace(int item_id)
        {
            var est_factors = new float[num_factors];

            IList <int> relevant_items = item_correlation.GetPositivelyCorrelatedEntities(item_id);

            float weight_sum = 0;
            uint  neighbors  = k;

            foreach (int item_id2 in relevant_items)
            {
                if (item_id2 >= item_factors.dim1)                 // check whether item is in training data
                {
                    continue;
                }
                if (Feedback.ItemMatrix[item_id2].Count == 0)
                {
                    continue;
                }

                float weight = item_correlation[item_id, item_id2];
                weight_sum += weight;
                for (int f = 0; f < num_factors; f++)
                {
                    est_factors[f] += weight * item_factors[item_id2, f];
                }

                if (--neighbors == 0)
                {
                    break;
                }
            }

            for (int f = 0; f < num_factors; f++)
            {
                est_factors[f] /= weight_sum;
            }

            return(est_factors);
        }
		public void TestGetPositivelyCorrelatedEntities()
		{
			// create a test CorrelationMatrix
			var matrix = new SymmetricCorrelationMatrix(3);
			matrix[0, 0] = 1f;
			matrix[0, 1] = 0.1f;
			matrix[0, 2] = -0.2f;
			matrix[1, 0] = 0.1f;
			matrix[1, 1] = 1f;
			matrix[1, 2] = 0.3f;
			matrix[2, 0] = -0.2f;
			matrix[2, 1] = 0.3f;
			matrix[2, 2] = 1f;

			Assert.AreEqual(1f, matrix[0, 0]);
			Assert.AreEqual(0.3f, matrix[1, 2]);

			// test
			IList<int> cor_entities_list = matrix.GetPositivelyCorrelatedEntities(2);
			int[] cor_entities = new int[1];
			cor_entities_list.CopyTo(cor_entities, 0);
			int[] pos_cor_entities = { 1 };
			Assert.AreEqual(pos_cor_entities, cor_entities);
		}