test_class.file: singa-mathematics/src/test/java/bio/singa/mathematics/matrices/MatricesTest.java
test_class.identifier: MatricesTest
test_case.body: @Test
      void shouldReadLabeledSymmetricMatrixFromCSV() throws Exception {
          Path labeledSymmetricMatrixPath = Paths.get(Resources.getResourceAsFileLocation("matrices/labeled_symmetric_matrix.csv"));
          LabeledMatrix<String> labeledSymmetricMatrix = Matrices.readLabeledMatrixFromCSV(labeledSymmetricMatrixPath);
          assertArrayEquals(new double[]{8.0, 14.0, 20.0, 28.0}, labeledSymmetricMatrix.getColumnByLabel("L4").getElements());
      }
test_case.class_method_signature: MatricesTest.shouldReadLabeledSymmetricMatrixFromCSV()
test_case.full_signature: @Test void shouldReadLabeledSymmetricMatrixFromCSV()
test_case.identifier: shouldReadLabeledSymmetricMatrixFromCSV
test_case.invocations: get getResourceAsFileLocation readLabeledMatrixFromCSV assertArrayEquals getElements getColumnByLabel
test_case.modifiers: @Test
test_case.parameters: ()
test_case.return: void
test_case.signature: void shouldReadLabeledSymmetricMatrixFromCSV()
focal_class.declarator: DEFAULT_CSV_DELIMITER = ","
focal_class.modifier: private static final
focal_class.original_string: private static final String DEFAULT_CSV_DELIMITER = ",";
focal_class.type: String
focal_class.var_name: DEFAULT_CSV_DELIMITER
focal_class.file: singa-mathematics/src/main/java/bio/singa/mathematics/matrices/Matrices.java
focal_class.identifier: Matrices
focal_class.class_method_signature: Matrices.Matrices()
focal_class.full_signature: private  Matrices()
focal_class.identifier: Matrices
focal_class.modifiers: private
focal_class.parameters: ()
focal_class.signature:  Matrices()
focal_class.class_method_signature: Matrices.generateIdentityMatrix(int size)
focal_class.full_signature: public static SquareMatrix generateIdentityMatrix(int size)
focal_class.identifier: generateIdentityMatrix
focal_class.modifiers: public static
focal_class.parameters: (int size)
focal_class.return: SquareMatrix
focal_class.signature: SquareMatrix generateIdentityMatrix(int size)
focal_class.class_method_signature: Matrices.generateMatrixOfOnes(int rowSize, int columnSize)
focal_class.full_signature: public static Matrix generateMatrixOfOnes(int rowSize, int columnSize)
focal_class.identifier: generateMatrixOfOnes
focal_class.modifiers: public static
focal_class.parameters: (int rowSize, int columnSize)
focal_class.return: Matrix
focal_class.signature: Matrix generateMatrixOfOnes(int rowSize, int columnSize)
focal_class.class_method_signature: Matrices.divideIntoColumns(Matrix matrix)
focal_class.full_signature: public static List<Vector> divideIntoColumns(Matrix matrix)
focal_class.identifier: divideIntoColumns
focal_class.modifiers: public static
focal_class.parameters: (Matrix matrix)
focal_class.return: List<Vector>
focal_class.signature: List<Vector> divideIntoColumns(Matrix matrix)
focal_class.class_method_signature: Matrices.assembleMatrixFromColumns(List<Vector> columnVectors)
focal_class.full_signature: public static Matrix assembleMatrixFromColumns(List<Vector> columnVectors)
focal_class.identifier: assembleMatrixFromColumns
focal_class.modifiers: public static
focal_class.parameters: (List<Vector> columnVectors)
focal_class.return: Matrix
focal_class.signature: Matrix assembleMatrixFromColumns(List<Vector> columnVectors)
focal_class.class_method_signature: Matrices.divideIntoRows(Matrix matrix)
focal_class.full_signature: public static List<Vector> divideIntoRows(Matrix matrix)
focal_class.identifier: divideIntoRows
focal_class.modifiers: public static
focal_class.parameters: (Matrix matrix)
focal_class.return: List<Vector>
focal_class.signature: List<Vector> divideIntoRows(Matrix matrix)
focal_class.class_method_signature: Matrices.assembleMatrixFromRows(List<Vector> rowVectors)
focal_class.full_signature: public static Matrix assembleMatrixFromRows(List<Vector> rowVectors)
focal_class.identifier: assembleMatrixFromRows
focal_class.modifiers: public static
focal_class.parameters: (List<Vector> rowVectors)
focal_class.return: Matrix
focal_class.signature: Matrix assembleMatrixFromRows(List<Vector> rowVectors)
focal_class.class_method_signature: Matrices.getPositionsOfMinimalElement(Matrix matrix)
focal_class.full_signature: public static List<Pair<Integer>> getPositionsOfMinimalElement(Matrix matrix)
focal_class.identifier: getPositionsOfMinimalElement
focal_class.modifiers: public static
focal_class.parameters: (Matrix matrix)
focal_class.return: List<Pair<Integer>>
focal_class.signature: List<Pair<Integer>> getPositionsOfMinimalElement(Matrix matrix)
focal_class.class_method_signature: Matrices.getPositionOfMinimalElement(Matrix matrix)
focal_class.full_signature: public static Optional<Pair<Integer>> getPositionOfMinimalElement(Matrix matrix)
focal_class.identifier: getPositionOfMinimalElement
focal_class.modifiers: public static
focal_class.parameters: (Matrix matrix)
focal_class.return: Optional<Pair<Integer>>
focal_class.signature: Optional<Pair<Integer>> getPositionOfMinimalElement(Matrix matrix)
focal_class.class_method_signature: Matrices.getPositionsOfMaximalElement(Matrix matrix)
focal_class.full_signature: public static List<Pair<Integer>> getPositionsOfMaximalElement(Matrix matrix)
focal_class.identifier: getPositionsOfMaximalElement
focal_class.modifiers: public static
focal_class.parameters: (Matrix matrix)
focal_class.return: List<Pair<Integer>>
focal_class.signature: List<Pair<Integer>> getPositionsOfMaximalElement(Matrix matrix)
focal_class.class_method_signature: Matrices.getPositionOfMaximalElement(Matrix matrix)
focal_class.full_signature: public static Optional<Pair<Integer>> getPositionOfMaximalElement(Matrix matrix)
focal_class.identifier: getPositionOfMaximalElement
focal_class.modifiers: public static
focal_class.parameters: (Matrix matrix)
focal_class.return: Optional<Pair<Integer>>
focal_class.signature: Optional<Pair<Integer>> getPositionOfMaximalElement(Matrix matrix)
focal_class.class_method_signature: Matrices.performQRDecomposition(Matrix matrix)
focal_class.full_signature: public static QRDecomposition performQRDecomposition(Matrix matrix)
focal_class.identifier: performQRDecomposition
focal_class.modifiers: public static
focal_class.parameters: (Matrix matrix)
focal_class.return: QRDecomposition
focal_class.signature: QRDecomposition performQRDecomposition(Matrix matrix)
focal_class.class_method_signature: Matrices.readLabeledMatrixFromCSV(Stream<String> csvLines, String delimiter)
focal_class.full_signature: public static LabeledMatrix<String> readLabeledMatrixFromCSV(Stream<String> csvLines, String delimiter)
focal_class.identifier: readLabeledMatrixFromCSV
focal_class.modifiers: public static
focal_class.parameters: (Stream<String> csvLines, String delimiter)
focal_class.return: LabeledMatrix<String>
focal_class.signature: LabeledMatrix<String> readLabeledMatrixFromCSV(Stream<String> csvLines, String delimiter)
focal_class.class_method_signature: Matrices.readUnlabeledMatrixFromCSV(Stream<String> csvLines, String delimiter)
focal_class.full_signature: public static Matrix readUnlabeledMatrixFromCSV(Stream<String> csvLines, String delimiter)
focal_class.identifier: readUnlabeledMatrixFromCSV
focal_class.modifiers: public static
focal_class.parameters: (Stream<String> csvLines, String delimiter)
focal_class.return: Matrix
focal_class.signature: Matrix readUnlabeledMatrixFromCSV(Stream<String> csvLines, String delimiter)
focal_class.class_method_signature: Matrices.readLabeledMatrixFromCSV(InputStream inputStream, String delimiter)
focal_class.full_signature: public static LabeledMatrix<String> readLabeledMatrixFromCSV(InputStream inputStream, String delimiter)
focal_class.identifier: readLabeledMatrixFromCSV
focal_class.modifiers: public static
focal_class.parameters: (InputStream inputStream, String delimiter)
focal_class.return: LabeledMatrix<String>
focal_class.signature: LabeledMatrix<String> readLabeledMatrixFromCSV(InputStream inputStream, String delimiter)
focal_class.class_method_signature: Matrices.readLabeledMatrixFromCSV(InputStream inputStream)
focal_class.full_signature: public static LabeledMatrix<String> readLabeledMatrixFromCSV(InputStream inputStream)
focal_class.identifier: readLabeledMatrixFromCSV
focal_class.modifiers: public static
focal_class.parameters: (InputStream inputStream)
focal_class.return: LabeledMatrix<String>
focal_class.signature: LabeledMatrix<String> readLabeledMatrixFromCSV(InputStream inputStream)
focal_class.class_method_signature: Matrices.readLabeledMatrixFromCSV(Path path)
focal_class.full_signature: public static LabeledMatrix<String> readLabeledMatrixFromCSV(Path path)
focal_class.identifier: readLabeledMatrixFromCSV
focal_class.modifiers: public static
focal_class.parameters: (Path path)
focal_class.return: LabeledMatrix<String>
focal_class.signature: LabeledMatrix<String> readLabeledMatrixFromCSV(Path path)
focal_class.class_method_signature: Matrices.readLabeledMatrixFromCSV(Path path, String delimiter)
focal_class.full_signature: public static LabeledMatrix<String> readLabeledMatrixFromCSV(Path path, String delimiter)
focal_class.identifier: readLabeledMatrixFromCSV
focal_class.modifiers: public static
focal_class.parameters: (Path path, String delimiter)
focal_class.return: LabeledMatrix<String>
focal_class.signature: LabeledMatrix<String> readLabeledMatrixFromCSV(Path path, String delimiter)
focal_class.class_method_signature: Matrices.readUnlabeledMatrixFromCSV(Path path, String delimiter)
focal_class.full_signature: public static Matrix readUnlabeledMatrixFromCSV(Path path, String delimiter)
focal_class.identifier: readUnlabeledMatrixFromCSV
focal_class.modifiers: public static
focal_class.parameters: (Path path, String delimiter)
focal_class.return: Matrix
focal_class.signature: Matrix readUnlabeledMatrixFromCSV(Path path, String delimiter)
focal_class.class_method_signature: Matrices.readUnlabeledMatrixFromCSV(Path path)
focal_class.full_signature: public static Matrix readUnlabeledMatrixFromCSV(Path path)
focal_class.identifier: readUnlabeledMatrixFromCSV
focal_class.modifiers: public static
focal_class.parameters: (Path path)
focal_class.return: Matrix
focal_class.signature: Matrix readUnlabeledMatrixFromCSV(Path path)
focal_class.class_method_signature: Matrices.calculateCovarianceMatrix(Matrix a, Matrix b)
focal_class.full_signature: public static Matrix calculateCovarianceMatrix(Matrix a, Matrix b)
focal_class.identifier: calculateCovarianceMatrix
focal_class.modifiers: public static
focal_class.parameters: (Matrix a, Matrix b)
focal_class.return: Matrix
focal_class.signature: Matrix calculateCovarianceMatrix(Matrix a, Matrix b)
focal_class.class_method_signature: Matrices.performSVDecomposition(Matrix matrix)
focal_class.full_signature: public static SVDecomposition performSVDecomposition(Matrix matrix)
focal_class.identifier: performSVDecomposition
focal_class.modifiers: public static
focal_class.parameters: (Matrix matrix)
focal_class.return: SVDecomposition
focal_class.signature: SVDecomposition performSVDecomposition(Matrix matrix)
focal_class.class_method_signature: Matrices.normalize(Matrix matrix)
focal_class.full_signature: public static Matrix normalize(Matrix matrix)
focal_class.identifier: normalize
focal_class.modifiers: public static
focal_class.parameters: (Matrix matrix)
focal_class.return: Matrix
focal_class.signature: Matrix normalize(Matrix matrix)
focal_method.body: public static LabeledMatrix<String> readLabeledMatrixFromCSV(Stream<String> csvLines, String delimiter) {
          List<String[]> rawRows = csvLines
                  .map(line -> line.split(delimiter))
                  .map(splittedLine -> Arrays.stream(splittedLine)
                          .filter(cell -> !cell.isEmpty())
                          .collect(Collectors.toList()).toArray(new String[0]))
                  .collect(Collectors.toList());
          // check if columns are potentially labeled
          List<Integer> distinctRowLengths = rawRows.stream()
                  .map(rawRow -> rawRow.length)
                  .distinct()
                  .collect(Collectors.toList());
  
          // keep all row lengths for triangular check
          List<Integer> rowLengths = rawRows.stream()
                  .map(rawRow -> rawRow.length)
                  .collect(Collectors.toList());
  
          // check for triangular form of symmetric matrix
          boolean triangularUpper = true;
          boolean triangularLower = true;
          for (int i = 1; i < rowLengths.size() - 1; i++) {
              if (rowLengths.get(i + 1) != rowLengths.get(i) + 1) {
                  triangularLower = false;
              }
              if (rowLengths.get(i + 1) != rowLengths.get(i) - 1) {
                  triangularUpper = false;
              }
          }
  
          List<String[]> rawColumns = new ArrayList<>();
          if (distinctRowLengths.size() == 2 && (distinctRowLengths.get(0) == distinctRowLengths.get(1) - 1)) {
  
              List<String> columnLabels = Arrays.asList(rawRows.get(0));
              int rowLength = rawRows.get(1).length;
              for (int i = 0; i < rowLength; i++) {
                  String[] rawColumn = new String[rawRows.size() - 1];
                  for (int j = 1; j < rawRows.size(); j++) {
                      rawColumn[j - 1] = rawRows.get(j)[i];
                  }
                  rawColumns.add(rawColumn);
              }
              List<String> rowLabels = Arrays.asList(rawColumns.get(0));
              double[][] values = new double[rawRows.size() - 1][rawColumns.size() - 1];
              for (int i = 1; i < rawRows.size(); i++) {
                  for (int j = 1; j < rawColumns.size(); j++) {
                      double value = Double.valueOf(rawRows.get(i)[j]);
                      values[i - 1][j - 1] = value;
                  }
              }
              // construct appropriate matrix
              if (SymmetricMatrix.isSymmetric(values)) {
                  LabeledSymmetricMatrix<String> labeledSymmetricMatrix = new LabeledSymmetricMatrix<>(values);
                  labeledSymmetricMatrix.setColumnLabels(columnLabels);
                  return labeledSymmetricMatrix;
              } else {
                  LabeledMatrix<String> labeledRegularMatrix = new LabeledRegularMatrix<>(values);
                  labeledRegularMatrix.setColumnLabels(columnLabels);
                  labeledRegularMatrix.setRowLabels(rowLabels);
                  return labeledRegularMatrix;
              }
          } else if (triangularLower || triangularUpper) {
              // labels have to be symmetric if triangular matrix
              List<String> columnLabels = Arrays.asList(rawRows.get(0));
              double[][] values = new double[rawRows.size() - 1][rawRows.size() - 1];
              if (triangularLower) {
                  for (int i = rawRows.size() - 1; i > 0; i--) {
                      for (int j = 1; j < i + 1; j++) {
                          double value = Double.valueOf(rawRows.get(i)[j]);
                          values[i - 1][j - 1] = value;
                          values[j - 1][i - 1] = value;
                      }
                  }
              } else {
                  for (int i = 1; i < rawRows.size(); i++) {
                      for (int j = 1; j < rawRows.size() - i + 1; j++) {
                          double value = Double.valueOf(rawRows.get(i)[j]);
                          values[i - 1][j + i - 2] = value;
                          values[j + i - 2][i - 1] = value;
                      }
                  }
              }
              if (SymmetricMatrix.isSymmetric(values)) {
                  LabeledSymmetricMatrix<String> labeledSymmetricMatrix = new LabeledSymmetricMatrix<>(values);
                  labeledSymmetricMatrix.setColumnLabels(columnLabels);
                  return labeledSymmetricMatrix;
              } else {
                  throw new IllegalArgumentException("triangular matrix has to be symmetric");
              }
          } else {
              throw new IllegalArgumentException("labeling seems to be incorrect");
          }
      }
focal_method.class_method_signature: Matrices.readLabeledMatrixFromCSV(Stream<String> csvLines, String delimiter)
focal_method.full_signature: public static LabeledMatrix<String> readLabeledMatrixFromCSV(Stream<String> csvLines, String delimiter)
focal_method.identifier: readLabeledMatrixFromCSV
focal_method.invocations: collect map map split toArray collect filter stream isEmpty toList toList collect distinct map stream toList collect map stream toList size get get get get size get get asList get get size size get add asList get size size size size valueOf get isSymmetric setColumnLabels setColumnLabels setRowLabels asList get size size size valueOf get size size valueOf get isSymmetric setColumnLabels
focal_method.modifiers: public static
focal_method.parameters: (Stream<String> csvLines, String delimiter)
focal_method.return: LabeledMatrix<String>
focal_method.signature: LabeledMatrix<String> readLabeledMatrixFromCSV(Stream<String> csvLines, String delimiter)