/// <summary>Creates a CorrelationMatrix from the lines of a StreamReader</summary> /// <remarks> /// In the first line, we expect to be the number of entities. /// All the other lines have the format /// <pre> /// EntityID1 EntityID2 Correlation /// </pre> /// where EntityID1 and EntityID2 are non-negative integers and Correlation is a floating point number. /// </remarks> /// <param name="reader">the StreamReader to read from</param> static public CorrelationMatrix ReadCorrelationMatrix(StreamReader reader) { int num_entities = int.Parse(reader.ReadLine()); CorrelationMatrix cm = Create(num_entities); // diagonal values for (int i = 0; i < num_entities; i++) { cm[i, i] = 1; } var split_chars = new char[] { '\t', ' ', ',' }; while (!reader.EndOfStream) { string[] numbers = reader.ReadLine().Split(split_chars); int i = int.Parse(numbers[0]); int j = int.Parse(numbers[1]); float c = float.Parse(numbers[2], CultureInfo.InvariantCulture); if (i >= num_entities) { throw new IOException("Entity ID is too big: i = " + i); } if (j >= num_entities) { throw new IOException("Entity ID is too big: j = " + j); } cm[i, j] = c; } return(cm); }
/// <summary>Creates a correlation matrix</summary> /// <remarks>Gives out a useful warning if there is not enough memory</remarks> /// <param name="num_entities">the number of entities</param> /// <returns>the correlation matrix</returns> static public CorrelationMatrix Create(int num_entities) { CorrelationMatrix cm; try { cm = new CorrelationMatrix(num_entities); } catch (OverflowException) { Console.Error.WriteLine("Too many entities: " + num_entities); throw; } return(cm); }
/// <summary>Copy constructor. Creates an object of type Cosine from an existing correlation matrix</summary> /// <param name ="correlation_matrix">the correlation matrix to copy</param> public BinaryCosine(CorrelationMatrix correlation_matrix) : base(correlation_matrix.NumberOfRows) { this.data = correlation_matrix.data; }
/// <summary>Copy constructor. Creates an object of type Jaccard from an existing correlation matrix</summary> /// <param name ="correlation_matrix">the correlation matrix to copy</param> public Jaccard(CorrelationMatrix correlation_matrix) : base(correlation_matrix.NumberOfRows) { this.data = correlation_matrix.data; }