Proposal: Add weights to gonum/matrix/mat64 API

34 views
Skip to first unread message

Kunde21

unread,
Apr 15, 2017, 8:35:10 AM4/15/17
to gonum-dev
Between reading optimizing ML algos and working on some research code, I'd like to suggest adding the capability to weight rows and columns in  gonum/matrix/mat64 using []float64 or mat64.Vector.  

Since a square matrix would require a dimension precedence, I'd suggest a flag type to denote the weighted dimension.  They would error if len(:

const(
   row dimFlag
= iota
   col
)

func
(m *mat64.Dense)Weight(dim dimFlag, wgt mat64.Vector)

func (m *mat64.Dense)WeightTo(dim dimFlag, wgt mat64.Vector, dst mat64.Dense)

The alternative is to use a full matrix type to perform matrix multiplication with a diagonal matrix.  That's a waste of memory and/or operations multiplying by zero.  

This aligns with the vecElemMul efficiency request in that it can be implemented as element-wise multiplication of a weight and a row/col vector.  

The assembly code isn't terribly difficult, but the API can be built in multiple ways.  I'm leaning towards Weights with a dimension flag, but it could be built as separate WeigtRows() and WeightCols() calls.  I'm mainly looking for a consensus on need and API design.  

Dan Kortschak

unread,
Apr 15, 2017, 9:34:11 AM4/15/17
to Kunde21, gonum-dev

blas has banded matrix types that will do this for you. We have not added mat64 support for this, but it is the more general API here.

--
afk
Dan


Reply all
Reply to author
Forward
0 new messages