/// 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 SaveModel(string file) { using (StreamWriter writer = Recommender.GetWriter(file, this.GetType())) { IMatrixUtils.WriteMatrix(writer, user_factors); IMatrixUtils.WriteMatrix(writer, item_factors); } }
/// public override void SaveModel(string filename) { using (StreamWriter writer = Recommender.GetWriter(filename, this.GetType())) { writer.WriteLine(global_bias.ToString(CultureInfo.InvariantCulture)); IMatrixUtils.WriteMatrix(writer, user_factors); IMatrixUtils.WriteMatrix(writer, item_factors); } }
/// public override void SaveModel(string file) { using (StreamWriter writer = Recommender.GetWriter(file, this.GetType())) { writer.WriteLine(global_average.ToString(CultureInfo.InvariantCulture)); IMatrixUtils.WriteSparseMatrix(writer, diff_matrix); IMatrixUtils.WriteSparseMatrix(writer, freq_matrix); } }
/// 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 static void Main() { XmlConfigurator.Configure(); IMatrix matrix = default(IMatrix); IMatrixUtils matrixUtils = default(IMatrixUtils); try { int rowsAndCowsInTheMatrix = NumberOfMatrixRowsAndCows; ICell startingCell = new Cell(StartingPositionOnRowsAndCows, StartingPositionOnRowsAndCows); matrix = new Matrix(rowsAndCowsInTheMatrix); matrixUtils = new MatrixUtils(matrix, PossibleDirections.AllDirections, startingCell); throw new ArgumentException("I Have Error Loging"); } catch (Exception ex) { Logger.Error("Initializing of Matrix failed", ex); } matrixUtils.FillMatrix(); Console.WriteLine(matrix.MatrixToString()); }
/// 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)); }
/// public override void SaveModel(string filename) { using (StreamWriter writer = Recommender.GetWriter(filename, this.GetType())) IMatrixUtils.WriteMatrix(writer, item_attribute_weight_by_user); }