You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Raviv Granot <ra...@gmail.com> on 2010/08/17 14:49:46 UTC

[MATH] Sparse Matrix - visiting all entries

Hi,
I see 2 implementations of sparse matrix in the math.commons.linear library.

1. OpenMapRealMatrix
2. SparseFieldMatrix
Both are documented as "Sparse matrix implementation based on an open
addressed map".
Does anyone know what are the differences between the two? also, which
method should I use to iterate only
over the non zero elements? it seems that the WalkInRawOrder method runs
over the entire row-length x col-length,
the same as for RealMatrix.

Thanks in advance!

Raviv

Re: [MATH] Sparse Matrix - visiting all entries

Posted by Raviv Granot <ra...@gmail.com>.
All,

I think I made a mistake in my last question. I now see that
sparseIteration() iterates over
RealVector.Entry that contains getIndex() and getValue() methods, which
solve my problem.

Sorry for the trouble,

Thanks!

On Tue, Aug 17, 2010 at 11:13 AM, Raviv Granot <ra...@gmail.com>wrote:

> Thanks for the info. I will definitely check the Mahout option.
>
> One more comment about the commons.math library. I noticed that the
> implementation for
> Sparse Vecotr (OpenMapRealVecotr) provides a method "sparseIteration()",
> which
> is what I'm looking for in the Matrix implementation. Changing my design a
> little bit,
> I can work with a map/list of sparse vectors instead of a matrix. However,
> it seems there's
> still one important functionality that is missing. How can you iterate over
> the non-zero
> indices efficiently? sparseIteration() iterates over the elements, but can
> you know which
> index each element belongs to?
> I know I can use the "getData()" method to get a double array where every
> index maps to an element, but then again, it's the same problem of being
> very inefficient.
>
> Any ideas would be very appreciated.
>
> Thanks!
>
> On Tue, Aug 17, 2010 at 9:24 AM, Ted Dunning <te...@gmail.com>wrote:
>
>> Apache Mahout also has a matrix package with sparse matrix support.  In
>> particular, iterateNonZero is supported and there are multiple sparse
>> vector/matrix formats that provide different performance trade-offs.
>>
>> Our purpose is not necessarily to be a general purpose math package and
>> the
>> system is still somewhat in flux so there is a good chance that Mahout
>> Math
>> isn't what you need.  On the other hand, because Mahout is much less
>> mature,
>> changes are much easier to push through.  Commons Math has a fairly strict
>> back compatibility policy that means that changes such as you want can
>> take
>> a very long time even for trunk.
>>
>> On Tue, Aug 17, 2010 at 5:49 AM, Raviv Granot <ra...@gmail.com>
>>  wrote:
>>
>> > Hi,
>> > I see 2 implementations of sparse matrix in the math.commons.linear
>> > library.
>> >
>> > 1. OpenMapRealMatrix
>> > 2. SparseFieldMatrix
>> > Both are documented as "Sparse matrix implementation based on an open
>> > addressed map".
>> > Does anyone know what are the differences between the two? also, which
>> > method should I use to iterate only
>> > over the non zero elements? it seems that the WalkInRawOrder method runs
>> > over the entire row-length x col-length,
>> > the same as for RealMatrix.
>> >
>> > Thanks in advance!
>> >
>> > Raviv
>> >
>>
>
>

Re: [MATH] Sparse Matrix - visiting all entries

Posted by Raviv Granot <ra...@gmail.com>.
Thanks for the info. I will definitely check the Mahout option.

One more comment about the commons.math library. I noticed that the
implementation for
Sparse Vecotr (OpenMapRealVecotr) provides a method "sparseIteration()",
which
is what I'm looking for in the Matrix implementation. Changing my design a
little bit,
I can work with a map/list of sparse vectors instead of a matrix. However,
it seems there's
still one important functionality that is missing. How can you iterate over
the non-zero
indices efficiently? sparseIteration() iterates over the elements, but can
you know which
index each element belongs to?
I know I can use the "getData()" method to get a double array where every
index maps to an element, but then again, it's the same problem of being
very inefficient.

Any ideas would be very appreciated.

Thanks!

On Tue, Aug 17, 2010 at 9:24 AM, Ted Dunning <te...@gmail.com> wrote:

> Apache Mahout also has a matrix package with sparse matrix support.  In
> particular, iterateNonZero is supported and there are multiple sparse
> vector/matrix formats that provide different performance trade-offs.
>
> Our purpose is not necessarily to be a general purpose math package and the
> system is still somewhat in flux so there is a good chance that Mahout Math
> isn't what you need.  On the other hand, because Mahout is much less
> mature,
> changes are much easier to push through.  Commons Math has a fairly strict
> back compatibility policy that means that changes such as you want can take
> a very long time even for trunk.
>
> On Tue, Aug 17, 2010 at 5:49 AM, Raviv Granot <ra...@gmail.com>
>  wrote:
>
> > Hi,
> > I see 2 implementations of sparse matrix in the math.commons.linear
> > library.
> >
> > 1. OpenMapRealMatrix
> > 2. SparseFieldMatrix
> > Both are documented as "Sparse matrix implementation based on an open
> > addressed map".
> > Does anyone know what are the differences between the two? also, which
> > method should I use to iterate only
> > over the non zero elements? it seems that the WalkInRawOrder method runs
> > over the entire row-length x col-length,
> > the same as for RealMatrix.
> >
> > Thanks in advance!
> >
> > Raviv
> >
>

Re: [MATH] Sparse Matrix - visiting all entries

Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
> [...]  Commons Math has a fairly strict back compatibility policy [...]

 s/fairly/very/

> [...] that means that changes such as you want can take
> a very long time even for trunk.

But now is a time of opportunity for incompatible changes, as work towards
v3.0 has started!  :-)


Gilles

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [MATH] Sparse Matrix - visiting all entries

Posted by Ted Dunning <te...@gmail.com>.
Apache Mahout also has a matrix package with sparse matrix support.  In
particular, iterateNonZero is supported and there are multiple sparse
vector/matrix formats that provide different performance trade-offs.

Our purpose is not necessarily to be a general purpose math package and the
system is still somewhat in flux so there is a good chance that Mahout Math
isn't what you need.  On the other hand, because Mahout is much less mature,
changes are much easier to push through.  Commons Math has a fairly strict
back compatibility policy that means that changes such as you want can take
a very long time even for trunk.

On Tue, Aug 17, 2010 at 5:49 AM, Raviv Granot <ra...@gmail.com>
 wrote:

> Hi,
> I see 2 implementations of sparse matrix in the math.commons.linear
> library.
>
> 1. OpenMapRealMatrix
> 2. SparseFieldMatrix
> Both are documented as "Sparse matrix implementation based on an open
> addressed map".
> Does anyone know what are the differences between the two? also, which
> method should I use to iterate only
> over the non zero elements? it seems that the WalkInRawOrder method runs
> over the entire row-length x col-length,
> the same as for RealMatrix.
>
> Thanks in advance!
>
> Raviv
>