/// public override void LoadModel(string file) { using (StreamReader reader = Recommender.GetReader(file, this.GetType())) { int numberOfComponents = int.Parse(reader.ReadLine()); var weights = new List <double>(); var recommenders = new List <IRecommender>(); for (int i = 0; i < numberOfComponents; i++) { string[] data = reader.ReadLine().Split(' '); Type t = Type.GetType(data[0]); recommenders.Add((IRecommender)Activator.CreateInstance(t)); recommenders[i].LoadModel("model-" + i + ".txt"); // make sure the recommenders get their data FIXME weights.Add(double.Parse(data[1], CultureInfo.InvariantCulture)); } this.weights = weights; this.recommenders = recommenders; } }
/// 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())) { this.global_average = double.Parse(reader.ReadLine(), CultureInfo.InvariantCulture); this.entity_averages = VectorUtils.ReadVector(reader); } }
/// public override void LoadModel(string filename) { using (StreamReader reader = Recommender.GetReader(filename, this.GetType())) { CorrelationMatrix correlation = CorrelationMatrix.ReadCorrelationMatrix(reader); base.Train(); // train baseline model this.correlation = new BinaryCosine(correlation); } }
/// public override void LoadModel(string filename) { using (StreamReader reader = Recommender.GetReader(filename, this.GetType())) { var global_average = double.Parse(reader.ReadLine(), CultureInfo.InvariantCulture); var user_biases = VectorUtils.ReadVector(reader); var item_biases = VectorUtils.ReadVector(reader); this.global_average = global_average; this.user_biases = user_biases.ToArray(); this.item_biases = item_biases.ToArray(); } }
/// 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); } }
/// 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; } }
/// public override void LoadModel(string filename) { using (StreamReader reader = Recommender.GetReader(filename, this.GetType())) { int size = int.Parse(reader.ReadLine()); var view_count = new int[size]; while (!reader.EndOfStream) { string[] numbers = reader.ReadLine().Split(' '); int item_id = int.Parse(numbers[0]); int count = int.Parse(numbers[1]); view_count[item_id] = count; } this.view_count = view_count; } }
/// public override void LoadModel(string filename) { using (StreamReader reader = Recommender.GetReader(filename, this.GetType())) { int num_users = int.Parse(reader.ReadLine()); var nearest_neighbors = new int[num_users][]; for (int u = 0; u < nearest_neighbors.Length; u++) { string[] numbers = reader.ReadLine().Split(' '); nearest_neighbors[u] = new int[numbers.Length]; for (int i = 0; i < numbers.Length; i++) { nearest_neighbors[u][i] = int.Parse(numbers[i]); } } this.correlation = CorrelationMatrix.ReadCorrelationMatrix(reader); this.k = (uint)nearest_neighbors[0].Length; this.nearest_neighbors = nearest_neighbors; } }
/// 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; } }
/// 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(); }
/// 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)); }