Пример #1
0
        ///
        public override void LoadModel(string filename)
        {
            using (StreamReader reader = Recommender.GetReader(filename, this.GetType()))
            {
                var bias = double.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 = bias;
                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;
            }
        }
        ///
        public override void LoadModel(string filename)
        {
            using (StreamReader reader = Recommender.GetReader(filename, this.GetType()))
            {
                var bias = double.Parse(reader.ReadLine(), CultureInfo.InvariantCulture);

                IList <double> user_bias    = VectorUtils.ReadVector(reader);
                var            user_factors = (Matrix <double>)IMatrixUtils.ReadMatrix(reader, new Matrix <double>(0, 0));
                IList <double> item_bias    = VectorUtils.ReadVector(reader);
                var            item_factors = (Matrix <double>)IMatrixUtils.ReadMatrix(reader, new Matrix <double>(0, 0));

                if (user_factors.dim2 != item_factors.dim2)
                {
                    throw new IOException(
                              string.Format(
                                  "Number of user and item factors must match: {0} != {1}",
                                  user_factors.dim2, item_factors.dim2));
                }
                if (user_bias.Count != user_factors.dim1)
                {
                    throw new IOException(
                              string.Format(
                                  "Number of users must be the same for biases and factors: {0} != {1}",
                                  user_bias.Count, user_factors.dim1));
                }
                if (item_bias.Count != item_factors.dim1)
                {
                    throw new IOException(
                              string.Format(
                                  "Number of items must be the same for biases and factors: {0} != {1}",
                                  item_bias.Count, item_factors.dim1));
                }

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

                // assign new model
                this.global_bias = bias;
                if (this.NumFactors != user_factors.dim2)
                {
                    Console.Error.WriteLine("Set num_factors to {0}", user_factors.dim1);
                    this.NumFactors = (uint)user_factors.dim2;
                }
                this.user_factors = user_factors;
                this.item_factors = item_factors;
                this.user_bias    = new double[user_factors.dim1];
                user_bias.CopyTo(this.user_bias, 0);
                this.item_bias = new double[item_factors.dim1];
                item_bias.CopyTo(this.item_bias, 0);
            }
        }
Пример #3
0
        ///
        public override void LoadModel(string file)
        {
            InitModel();

            using (StreamReader reader = Recommender.GetReader(file, this.GetType()))
            {
                var global_average = double.Parse(reader.ReadLine(), CultureInfo.InvariantCulture);

                var diff_matrix = (SkewSymmetricSparseMatrix)IMatrixUtils.ReadMatrix(reader, this.diff_matrix);                   // TODO take symmetric matrix into account for smaller model files
                var freq_matrix = (SymmetricSparseMatrix <int>)IMatrixUtils.ReadMatrix(reader, this.freq_matrix);                 // TODO take anti-symmetric matrix into account for smaller model files

                // assign new model
                this.global_average = global_average;
                this.diff_matrix    = diff_matrix;
                this.freq_matrix    = freq_matrix;
            }
        }
Пример #4
0
        ///
        public override void LoadModel(string file)
        {
            InitModel();

            using (StreamReader reader = Recommender.GetReader(file, this.GetType()))
            {
                var global_average = double.Parse(reader.ReadLine(), CultureInfo.InvariantCulture);

                var diff_matrix_like    = (SkewSymmetricSparseMatrix)IMatrixUtils.ReadMatrix(reader, this.diff_matrix_like);
                var freq_matrix_like    = (SymmetricSparseMatrix <int>)IMatrixUtils.ReadMatrix(reader, this.freq_matrix_like);
                var diff_matrix_dislike = (SkewSymmetricSparseMatrix)IMatrixUtils.ReadMatrix(reader, this.diff_matrix_dislike);
                var freq_matrix_dislike = (SymmetricSparseMatrix <int>)IMatrixUtils.ReadMatrix(reader, this.freq_matrix_dislike);
                var user_average        = VectorUtils.ReadVector(reader);

                // assign new model
                this.global_average      = global_average;
                this.diff_matrix_like    = diff_matrix_like;
                this.freq_matrix_like    = freq_matrix_like;
                this.diff_matrix_dislike = diff_matrix_dislike;
                this.freq_matrix_dislike = freq_matrix_dislike;
                this.user_average        = user_average;
            }
        }
Пример #5
0
        ///
        public override void LoadModel(string file)
        {
            using (StreamReader reader = Recommender.GetReader(file, this.GetType()))
            {
                var            user_factors = (Matrix <double>)IMatrixUtils.ReadMatrix(reader, new Matrix <double>(0, 0));
                IList <double> item_bias    = VectorUtils.ReadVector(reader);
                var            item_factors = (Matrix <double>)IMatrixUtils.ReadMatrix(reader, new Matrix <double>(0, 0));

                if (user_factors.NumberOfColumns != item_factors.NumberOfColumns)
                {
                    throw new IOException(
                              string.Format("Number of user and item factors must match: {0} != {1}",
                                            user_factors.NumberOfColumns, item_factors.NumberOfColumns));
                }
                if (item_bias.Count != item_factors.dim1)
                {
                    throw new IOException(
                              string.Format(
                                  "Number of items must be the same for biases and factors: {0} != {1}",
                                  item_bias.Count, item_factors.dim1));
                }

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

                // assign new model
                if (this.num_factors != user_factors.NumberOfColumns)
                {
                    Console.Error.WriteLine("Set num_factors to {0}", user_factors.NumberOfColumns);
                    this.num_factors = user_factors.NumberOfColumns;
                }
                this.user_factors = user_factors;
                this.item_bias    = item_bias;
                this.item_factors = item_factors;
            }
            random = Util.Random.GetInstance();
        }
Пример #6
0
 ///
 public override void LoadModel(string filename)
 {
     using (StreamReader reader = Recommender.GetReader(filename, this.GetType()))
         this.item_attribute_weight_by_user = (Matrix <double>)IMatrixUtils.ReadMatrix(reader, new Matrix <double>(0, 0));
 }