LoadModel() public method

public LoadModel ( string filename ) : void
filename string
return void
示例#1
0
        ///
        public override void LoadModel(string filename)
        {
            global_effects.LoadModel(filename + "-global-effects");
            global_effects.Ratings = Ratings;

            using (StreamReader reader = Recommender.GetReader(filename, this.GetType()))
            {
                var global_bias         = double.Parse(reader.ReadLine(), CultureInfo.InvariantCulture);
                var num_learned_factors = int.Parse(reader.ReadLine(), CultureInfo.InvariantCulture);

                var user_factors = (Matrix <double>)IMatrixUtils.ReadMatrix(reader, new Matrix <double>(0, 0));
                var item_factors = (Matrix <double>)IMatrixUtils.ReadMatrix(reader, new Matrix <double>(0, 0));

                if (user_factors.NumberOfColumns != item_factors.NumberOfColumns)
                {
                    throw new Exception(
                              string.Format("Number of user and item factors must match: {0} != {1}",
                                            user_factors.NumberOfColumns, item_factors.NumberOfColumns));
                }

                this.MaxUserID = user_factors.NumberOfRows - 1;
                this.MaxItemID = item_factors.NumberOfRows - 1;

                // assign new model
                this.global_bias         = global_bias;
                this.num_learned_factors = num_learned_factors;
                if (this.NumFactors != user_factors.NumberOfColumns)
                {
                    Console.Error.WriteLine("Set num_factors to {0}", user_factors.NumberOfColumns);
                    this.NumFactors = (uint)user_factors.NumberOfColumns;
                }
                this.user_factors = user_factors;
                this.item_factors = item_factors;
            }
        }
示例#2
0
        ///
        public override void LoadModel(string filename)
        {
            baseline_predictor.LoadModel(filename + "-global-effects");

            using (StreamReader reader = Model.GetReader(filename, this.GetType()))
            {
                Correlation = (RatingCorrelationType)Enum.Parse(typeof(RatingCorrelationType), reader.ReadLine());
                InitModel();

                if (correlation is SymmetricCorrelationMatrix)
                {
                    ((SymmetricCorrelationMatrix)correlation).ReadSymmetricCorrelationMatrix(reader);
                }
                else if (correlation is AsymmetricCorrelationMatrix)
                {
                    ((AsymmetricCorrelationMatrix)correlation).ReadAsymmetricCorrelationMatrix(reader);
                }
                else
                {
                    throw new NotSupportedException("Unsupported correlation type: " + correlation.GetType());
                }
            }
        }