示例#1
0
        ///
        public override void Train()
        {
            int num_attributes = item_attributes.NumberOfColumns;

            x_reg = new float[num_attributes];
            for (int attribute_id = 0; attribute_id < num_attributes; attribute_id++)
            {
                x_reg[attribute_id] = FrequencyRegularization ? (float)(Regularization / item_attributes.NumEntriesByColumn(attribute_id)) : Regularization;
            }

            base.Train();
        }
        ///
        protected override void InitModel()
        {
            base.InitModel();

            user_factors = null;
            item_factors = null;
            p            = new Matrix <float> (MaxUserID + 1, NumFactors);
            p.InitNormal(InitMean, InitStdDev);
            y = new Matrix <float> (MaxItemID + 1, NumFactors);
            y.InitNormal(InitMean, InitStdDev);
            x = new Matrix <float> (item_attributes.NumberOfColumns, NumFactors);
            x.InitNormal(InitMean, InitStdDev);
            q = new Matrix <float> (MaxItemID + 1, NumFactors);
            q.InitNormal(InitMean, InitStdDev);

            int num_attributes = item_attributes.NumberOfColumns;

            x_reg = new float[num_attributes];
            for (int attribute_id = 0; attribute_id < num_attributes; attribute_id++)
            {
                x_reg [attribute_id] = FrequencyRegularization? (RegX / (float)(1 + Math.Exp(-0.005 * item_attributes.NumEntriesByColumn(attribute_id)))) : RegX;
            }

            y_reg = new float[MaxItemID + 1];
            for (int item_id = 0; item_id <= MaxItemID; item_id++)
            {
                var feedback_count_by_item = Feedback.ItemMatrix [item_id];
                if (feedback_count_by_item.Count > 0)
                {
                    y_reg [item_id] = FrequencyRegularization ? (float)(RegY / Math.Sqrt(feedback_count_by_item.Count)) : RegY;
                }
                else
                {
                    y_reg [item_id] = 0;
                }
            }

            Console.Write("Learning attributes...");
            BPRLinear learnAttr = new BPRLinear();

            learnAttr.Feedback       = Feedback;
            learnAttr.ItemAttributes = item_attributes;
            learnAttr.NumIter        = NumIter;     //10;
            learnAttr.LearnRate      = LearnRate;   //0.05f;
            learnAttr.Regularization = 0.015f;      //0.001f;
            learnAttr.Train();
            item_attribute_weight_by_user = learnAttr.ItemAttributeWeights;
            learnAttr = null;
            Console.WriteLine("Done");
        }