[Test()] public void TestCreate()
        {
            var sparse_boolean_matrix = new SparseBooleanMatrix();

            sparse_boolean_matrix[0, 1] = true;
            sparse_boolean_matrix[0, 4] = true;
            sparse_boolean_matrix[1, 0] = true;
            sparse_boolean_matrix[1, 2] = true;
            sparse_boolean_matrix[1, 4] = true;
            sparse_boolean_matrix[3, 1] = true;
            sparse_boolean_matrix[3, 3] = true;
            sparse_boolean_matrix[3, 4] = true;

            var correlation_matrix = new BinaryCosine(sparse_boolean_matrix.NumberOfRows);

            correlation_matrix.ComputeCorrelations(sparse_boolean_matrix);

            Assert.AreEqual(4, correlation_matrix.NumberOfRows);
            Assert.IsTrue(correlation_matrix.IsSymmetric);

            Assert.AreEqual(1 / Math.Sqrt(6), correlation_matrix[0, 1], DELTA);
            Assert.AreEqual(1 / Math.Sqrt(6), correlation_matrix[1, 0], DELTA);
            Assert.AreEqual(1 / 3d, correlation_matrix[1, 3], DELTA);

            Assert.AreEqual(0f, correlation_matrix[2, 0]);
            Assert.AreEqual(0f, correlation_matrix[2, 1]);
            Assert.AreEqual(1f, correlation_matrix[2, 2]);
            Assert.AreEqual(0f, correlation_matrix[2, 3]);

            Assert.AreEqual(0f, correlation_matrix[0, 2]);
            Assert.AreEqual(0f, correlation_matrix[1, 2]);
            Assert.AreEqual(0f, correlation_matrix[3, 2]);
        }
        ///
        public override void LearnAttributeToFactorMapping()
        {
            BinaryCosine cosine_correlation = new BinaryCosine(MaxItemID + 1);

            Console.Error.WriteLine("training with max_item_id={0}", MaxItemID);
            cosine_correlation.ComputeCorrelations(item_attributes);
            this.item_correlation   = cosine_correlation;
            _MapToLatentFactorSpace = Utils.Memoize <int, float[]>(__MapToLatentFactorSpace);
        }
        [Test()] public void TestComputeCorrelations()
        {
            var sparse_boolean_matrix = new SparseBooleanMatrix();

            sparse_boolean_matrix[0, 1] = true;
            sparse_boolean_matrix[0, 4] = true;
            sparse_boolean_matrix[1, 0] = true;
            sparse_boolean_matrix[1, 2] = true;
            sparse_boolean_matrix[1, 4] = true;
            sparse_boolean_matrix[3, 1] = true;
            sparse_boolean_matrix[3, 3] = true;
            sparse_boolean_matrix[3, 4] = true;

            var correlation = new BinaryCosine(4);

            correlation.ComputeCorrelations(sparse_boolean_matrix);
            Assert.AreEqual(1 / Math.Sqrt(6), correlation[0, 1], DELTA);
            Assert.AreEqual(1 / Math.Sqrt(6), correlation[1, 0], DELTA);
            Assert.AreEqual(1 / 3d, correlation[1, 3], DELTA);
        }
Exemplo n.º 4
0
        [Test()] public void TestComputeCorrelations()
        {
            // create test objects
            var sparse_boolean_matrix = new SparseBooleanMatrix();

            sparse_boolean_matrix[0, 1] = true;
            sparse_boolean_matrix[0, 4] = true;
            sparse_boolean_matrix[1, 0] = true;
            sparse_boolean_matrix[1, 2] = true;
            sparse_boolean_matrix[1, 4] = true;
            sparse_boolean_matrix[3, 1] = true;
            sparse_boolean_matrix[3, 3] = true;
            sparse_boolean_matrix[3, 4] = true;
            // test
            var cosine = new BinaryCosine(5);

            cosine.ComputeCorrelations(sparse_boolean_matrix);
            Assert.AreEqual(Math.Round(1 / Math.Sqrt(6), 4), Math.Round(cosine[0, 1], 4));
            Assert.AreEqual(Math.Round(1 / Math.Sqrt(6), 4), Math.Round(cosine[1, 0], 4));
            Assert.AreEqual(Math.Round(1 / 3d, 4), Math.Round(cosine[1, 3], 4));
        }