Github user yu-iskw commented on a diff in the pull request:
https://github.com/apache/spark/pull/8563#discussion_r43609930
--- Diff:
mllib/src/main/scala/org/apache/spark/mllib/linalg/distributed/BlockMatrix.scala
---
@@ -402,4 +441,474 @@ class BlockMatrix @Since("1.3.0") (
s"A.colsPerBlock: $colsPerBlock, B.rowsPerBlock:
${other.rowsPerBlock}")
}
}
+
+ /**
+ * Schur Complement of a BlockMatrix. For a matrix that is in 4
partitions:
+ * A=[a11, a12; a21; a22], the Schur Complement S is S = a22 - (a21 *
a11^-1 * a12).
+ * The Schur Complement is always (n-1) x (n-1), which is the size of
a22. a11 is expected
+ * to fit into memory so that Breeze inversions can be computed.
+ *
+ * @return BlockMatrix Schur Complement as BlockMatrix
+ * @since 1.6.0
+ */
+ private[mllib] def SchurComplement: BlockMatrix = {
+ require(this.numRowBlocks == this.numColBlocks, "Block Matrix must be
square.")
+ require(this.numRowBlocks > 1, "Block Matrix must be larger than one
block.")
+ val topRange = (0, 0); val botRange = (1, this.numColBlocks - 1)
+ val a11 = this.subBlock(topRange, topRange)
+ val a12 = this.subBlock(topRange, botRange)
+ val a21 = this.subBlock(botRange, topRange)
+ val a22 = this.subBlock(botRange, botRange)
+
+ val a11Brz = inv(a11.toBreeze) // note that intermediate a11 calcs
derive from inv(a11)
+ val a11Mtx = Matrices.dense(a11.numRows.toInt, a11.numCols.toInt,
a11Brz.toArray)
+ val a11RDD = this.blocks.sparkContext.parallelize(Seq(((0, 0),
a11Mtx)))
+ val a11Inv = new BlockMatrix(a11RDD, this.rowsPerBlock,
this.colsPerBlock)
+
+ val S = a22.subtract(a21.multiply(a11Inv.multiply(a12)))
+ S
+ }
+
+ /**
+ * Returns a rectangular (sub)BlockMatrix with block ranges as
specified. Block Ranges
+ * refer to a range of blocks that each contain a matrix. The returned
BlockMatrix
+ * is numbered so that the upper left block is indexed as (0,0).
+ *
+ *
+ * @param blockRowRange The lower and upper row range of blocks, as
(Int,Int)
+ * @param blockColRange The lower and upper col range of blocks, as
(Int, Int)
+ * @return a BlockMatrix with (0,0) as the upper leftmost block index
+ * @since 1.6.0
+ */
+ private [mllib] def subBlock(blockRowRange: (Int, Int), blockColRange:
(Int, Int)):
+ BlockMatrix = {
--- End diff --
fix the style
http://docs.scala-lang.org/style/declarations.html
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]