///
        public override void LearnAttributeToFactorMapping()
        {
            // create attribute-to-latent factor weight matrix
            this.attribute_to_factor = new Matrix <float>(NumItemAttributes + 1, num_factors);
            // store the results of the different runs in the following array
            var old_attribute_to_factor = new Matrix <float> [num_init_mapping];

            Console.Error.WriteLine("Will use {0} examples ...", num_iter_mapping * MaxItemID);

            var old_rmse_per_factor = new double[num_init_mapping][];

            for (int h = 0; h < num_init_mapping; h++)
            {
                MatrixExtensions.InitNormal(attribute_to_factor, InitMean, InitStdDev);
                Console.Error.WriteLine("----");

                for (int i = 0; i < num_iter_mapping * MaxItemID; i++)
                {
                    IterateMapping();
                }
                old_attribute_to_factor[h] = new Matrix <float>(attribute_to_factor);
                old_rmse_per_factor[h]     = ComputeMappingFit();
            }

            var min_rmse_per_factor = new double[num_factors];

            for (int i = 0; i < num_factors; i++)
            {
                min_rmse_per_factor[i] = Double.MaxValue;
            }
            var best_factor_init = new int[num_factors];

            // find best factor mappings
            for (int i = 0; i < num_init_mapping; i++)
            {
                for (int j = 0; j < num_factors; j++)
                {
                    if (old_rmse_per_factor[i][j] < min_rmse_per_factor[j])
                    {
                        min_rmse_per_factor[j] = old_rmse_per_factor[i][j];
                        best_factor_init[j]    = i;
                    }
                }
            }

            // set the best weight combinations for each factor mapping
            for (int i = 0; i < num_factors; i++)
            {
                Console.Error.WriteLine("Factor {0}, pick {1}", i, best_factor_init[i]);

                attribute_to_factor.SetColumn(i,
                                              old_attribute_to_factor[best_factor_init[i]].GetColumn(i)
                                              );
            }

            _MapToLatentFactorSpace = Utils.Memoize <int, float[]>(__MapToLatentFactorSpace);
        }
        ///
        public override void LearnAttributeToFactorMapping()
        {
            // create attribute-to-factor weight matrix
            attribute_to_factor = new Matrix <float>(NumUserAttributes, num_factors);

            Console.Error.WriteLine("\nBPR-OPT-USERMAP training");
            Console.Error.WriteLine("num_user_attributes=" + NumUserAttributes);

            MatrixExtensions.InitNormal(attribute_to_factor, InitMean, InitStdDev);

            for (int i = 0; i < num_iter_mapping; i++)
            {
                IterateMapping();
            }
        }
        ///
        public override void LearnAttributeToFactorMapping()
        {
            this.factor_bias = new float[num_factors];

            for (int i = 0; i < num_factors; i++)
            {
                factor_bias[i] = MatrixExtensions.ColumnAverage(item_factors, i);
                Console.Error.WriteLine("fb {0}: {1}", i, factor_bias[i]);
            }

            this.attribute_to_factor = new Matrix <float>(NumItemAttributes, num_factors);
            MatrixExtensions.InitNormal(attribute_to_factor, InitMean, InitStdDev);

            for (int i = 0; i < num_iter_mapping; i++)
            {
                IterateMapping();
            }

            _MapToLatentFactorSpace = Utils.Memoize <int, float[]>(__MapToLatentFactorSpace);
        }
Exemplo n.º 4
0
        void LearnItemAttributeToFactorMapping()
        {
            // no mapping of no item attributes present
            if (item_attributes.NumberOfEntries == 0)
            {
                return;
            }

            // create attribute-to-latent factor weight matrix
            this.item_attribute_to_factor = new Matrix <float>(NumItemAttributes + 1, num_factors);
            // store the results of the different runs in the following array
            var old_attribute_to_factor = new Matrix <float> [num_init_mapping];

            //Console.Error.WriteLine("Will use {0} examples ...", num_iter_mapping * MaxItemID);

            var old_rmse_per_factor = new double[num_init_mapping][];

            for (int h = 0; h < num_init_mapping; h++)
            {
                MatrixExtensions.InitNormal(item_attribute_to_factor, InitMean, InitStdDev);
                Console.Error.WriteLine("----");

                for (int i = 0; i < num_iter_mapping * MaxItemID; i++)
                {
                    UpdateItemMapping();
                }
                old_attribute_to_factor[h] = new Matrix <float>(item_attribute_to_factor);
                old_rmse_per_factor[h]     = ComputeItemMappingFit();
            }

            var min_rmse_per_factor = new double[num_factors];

            for (int i = 0; i < num_factors; i++)
            {
                min_rmse_per_factor[i] = Double.MaxValue;
            }
            var best_factor_init = new int[num_factors];

            // find best factor mappings
            for (int i = 0; i < num_init_mapping; i++)
            {
                for (int j = 0; j < num_factors; j++)
                {
                    if (old_rmse_per_factor[i][j] < min_rmse_per_factor[j])
                    {
                        min_rmse_per_factor[j] = old_rmse_per_factor[i][j];
                        best_factor_init[j]    = i;
                    }
                }
            }

            // set the best weight combinations for each factor mapping
            for (int i = 0; i < num_factors; i++)
            {
                Console.Error.WriteLine("Factor {0}, pick {1}", i, best_factor_init[i]);

                item_attribute_to_factor.SetColumn(i,
                                                   old_attribute_to_factor[best_factor_init[i]].GetColumn(i)
                                                   );
            }

            ComputeFactorsForNewItems();
        }