mahout-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Alexey Grigorev (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (MAHOUT-1691) iterable of vectors to matrix
Date Wed, 15 Apr 2015 18:41:58 GMT

    [ https://issues.apache.org/jira/browse/MAHOUT-1691?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14496680#comment-14496680
] 

Alexey Grigorev commented on MAHOUT-1691:
-----------------------------------------

or maybe it's better to have something like a method `rowMap` in `MatrixOps`, so there will
be no need to use java's iterators. Then in the implementation we also would be able to use
`m.like` instead of checking if vectors are dense or not.

It may look something like 

{code}
val res = drmX.mapBlock(drmX.ncol) {
  case (keys, block) => {
    keys -> block.mapRow(row => (row - mean) / std)
  }
}
{code}

> iterable of vectors to matrix 
> ------------------------------
>
>                 Key: MAHOUT-1691
>                 URL: https://issues.apache.org/jira/browse/MAHOUT-1691
>             Project: Mahout
>          Issue Type: Improvement
>          Components: Math
>    Affects Versions: 0.10.1
>            Reporter: Alexey Grigorev
>            Priority: Minor
>              Labels: math, scala
>
> In Mahout scala bindings, instead of writing  
> {code}
> val res = drmX.mapBlock(drmX.ncol) {
>   case (keys, block) => {
>     val copy = block.like
>     copy := block.map(row => (row - mean) / std)
>     (keys, copy)
>   }
> }
> {code}
> I would like to be able to write 
> {code}
> val res = drmX.mapBlock(drmX.ncol) {
>   case (keys, block) => {
>     keys -> block.map(row => (row - mean) / std)
>   }
> }
> {code}
> Solution: add a method for implicit conversion from iterable to Matrix:
> {code}
>   implicit def iterable2Matrix(that: Iterable[Vector]): Matrix = {
>     val first = that.head
>     val nrow = that.size
>     val ncol = first.size
>     val m = if (first.isDense) {
>       new DenseMatrix(nrow, ncol)
>     } else {
>       new SparseRowMatrix(nrow, ncol)
>     }
>     that.zipWithIndex.foreach { case (row, idx) => 
>       m.assignRow(idx.toInt, row)
>     }
>     m
>   }
> {code}
> If it sounds nice, I can send a pull request with this implemented



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message