You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by "Cuong P. Nguyen" <cn...@iit.edu> on 2010/10/16 18:53:54 UTC

complex matrix operation

Hi, can I use the package for basic complex-number matrix operations
(addition, subtraction, multiplication) ?

Thanks

Cuong


Re: [math] EuclideanIntegerPoint EuclideanDoublePoint

Posted by Ted Dunning <te...@gmail.com>.
On Wed, Oct 20, 2010 at 1:04 AM, VanIngen, Erik (FIPS) <
Erik.VanIngen@fao.org> wrote:

> Good morning!
>
> I need to to cluster analysis on values like this:
> 1.814263985     -0.633923297
> 2.501153739     -0.559033358
> 2.408755862     -0.509902975
> 1.935495243     -0.330554484
> 0.728818279     -0.169024633
> -0.523861032    0.110392311
>
> I can use EuclideanIntegerPoint, but than I have to convert the values to
> integers and would loose precission. So my trick would be to multiply with
> 1000, cluster and multiply the values with 0.001. Would that be a valid
> approach from a methodology point of view?
>

Numerically, this approach will often be a disaster.  I wouldn't recommend
it.


>
> Are there any plans to develop a EuclideanDoublePoint?
>
> Apache Mahout has a bunch of clustering code that you could use.  It isn't
limited to two dimensions, either, as a EDP might be.

Re: [math] Re: complex matrix operation

Posted by Luc Maisonobe <Lu...@free.fr>.
Le 16/10/2010 22:47, Cuong P. Nguyen a écrit :
> Hi Luc and friends, 
> 
> I have a question more related to java matrix storage. If I have a
> 3-dimentional m matrix say 2 by 2 by 2, I want to access the matrix

Matrices are limited to 2 dimensions. We don't have general k-th order
tensors in commons-math. For higher dimensions, you have to use simple
Java arrays, but you won't have any operations on them.

> efficiently so I would like to know the order in which the data is stored in
> the memory. I am not sure if it is stored consecutively this way in the
> memory register:
> m(1,1,1), m(1,1,2), m(1,2,1), m(1,2,2), m(2,1,1), m(2,1,2), m(2,2,1),
> m(2,2,2)

In Java, arrays are not a simple bunch of elements packed together with
a fancy numbering scheme like you have with other languages. A
three-dimensional array is really an array of two-dimensional arrays,
each of which being an array of one-dimensional arrays, which finally
are a bunch of elements with some meta-data. The lowest level arrays
correspond to the rightmost index while the top level array correspond
to the leftmost index. So m(1,1,1) and m(1,1,2) are certainly close
together in memory as they belong to the same lowest level array but
m(1,2,1) may be a few bytes away. Depending on the way you create your
array, it is even possible to have two consecutive rows be really widely
separated.


> 
> I also wonder if the package could store sparse vectors, matrices and
> perform basic operations on them?

Yes, there are sparse vectors and matrices.

Luc

> 
> Thanks,
> Cuong
> 
> -----Original Message-----
> From: Luc Maisonobe [mailto:Luc.Maisonobe@free.fr] 
> Sent: Saturday, October 16, 2010 2:00 PM
> To: Commons Users List
> Subject: Re: [math] Re: complex matrix operation
> 
> Le 16/10/2010 20:38, Cuong P. Nguyen a écrit :
>> Hi Luc and friends, 
>>
>> Thanks a lot for the quick response
>>
>> Could you give me any simple code example of Complex-type vector-matrix
>> multiplication or matrix-matrix multiplication ?
> 
> Here is a matrix vector multiplication:
> 
> // create a 2x2 complex matrix
> Complex[][] matrixData = new Complex[][] {
>     { new Complex(1.0,  0.0), new Complex( 0.0, 1.0) },
>     { new Complex(0.0, -1.0), new Complex(-1.0, 0.0) }
> };
> FieldMatrix<Complex> m = new Array2DRowFieldMatrix<Complex>(matrixData);
> 
> // create a vector
> Complex[] vectorData = new Complex[] {
>     new Complex(1.0, 2.0),
>     new Complex(3.0, 4.0),
> };
> FieldVector<Complex> u = new ArrayFieldVector<Complex>(vectorData);
> 
> // perform matrix-vector multiplication
> FieldVector<Complex> v = m.operate(u);
> 
> // print the initial vector
> for (int i = 0; i < u.getDimension(); ++i) {
>     System.out.println(ComplexFormat.formatComplex(u.getEntry(i)));
> }
> 
> System.out.println();
> 
> // print the result
> for (int i = 0; i < v.getDimension(); ++i) {
>     System.out.println(ComplexFormat.formatComplex(v.getEntry(i)));
> }
> 
> 
> 
> Luc
> 
>>
>> I am a new java beginner as well as new to Commons Math community.
>>
>> Thanks,
>>
>> Cuong
>>
>> -----Original Message-----
>> From: Luc Maisonobe [mailto:Luc.Maisonobe@free.fr] 
>> Sent: Saturday, October 16, 2010 1:25 PM
>> To: Commons Users List
>> Subject: [math] Re: complex matrix operation
>>
>> Le 16/10/2010 18:53, Cuong P. Nguyen a écrit :
>>> Hi,
>>
>> Hi Cuong,
>>
>> First, please use a [math] marker on the subject line when posting to
>> this list for the commons-math component. The list is shared among
>> several commons components and these markers help filtering.
>>
>>> can I use the package for basic complex-number matrix operations
>>> (addition, subtraction, multiplication) ?
>>
>> You can use the linear algebra packe from commons-math with complex
>> matrices. The appropriate interface is FieldMatrix<Complex> which has
>> two implementations: Array2DRowFieldMatrix<Complex> and
>> BlockFieldMatrix<Complex>. The former should be preferred for small
>> sizes and the later for large sizes. You can also use complex vectors
>> and LU decomposition with these matrices.
>>
>> Luc
>>
>>>
>>> Thanks
>>>
>>> Cuong
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 


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


Re: [math] EuclideanIntegerPoint EuclideanDoublePoint

Posted by Luc Maisonobe <Lu...@free.fr>.
Le 20/10/2010 10:04, VanIngen, Erik (FIPS) a écrit :
> Good morning!
> 
> I need to to cluster analysis on values like this:
> 1.814263985     -0.633923297
> 2.501153739     -0.559033358
> 2.408755862     -0.509902975
> 1.935495243     -0.330554484
> 0.728818279     -0.169024633
> -0.523861032    0.110392311
> 
> I can use EuclideanIntegerPoint, but than I have to convert the values to integers and would loose precission. So my trick would be to multiply with 1000, cluster and multiply the values with 0.001. Would that be a valid approach from a methodology point of view?
> 
> Are there any plans to develop a EuclideanDoublePoint?

The K-means++ clusterer can handle any implementation of the Clusterable
interface. The intent is to allow users to provide their own class to
suit their needs. The EuclideanIntegerPoint can be seen as a simple
reference implementation. There are no plans to add other
implementations yet.

In order to avoid data duplication, I would suggest that your existing
class that already holds the values implements the Clusterable interface
by itself. This way, you can directly provide your own data to K-means++.

Hope this helps
Luc

> 
> Cheers,
> Erik van Ingen
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 


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


RE: KMeansPlusPlusClusterer breaks on division by zero

Posted by "VanIngen, Erik (FIPS)" <Er...@fao.org>.
FYI

Issue has been resolved by Apache within 26 hours:
https://issues.apache.org/jira/browse/MATH-429

Thanks a lot!


-----Original Message-----
From: VanIngen, Erik (FIPS)
Sent: 22 October 2010 10:10
To: 'Commons Users List'
Cc: Ellenbroek, Anton (FIPS); Calderini, Francesco (FIPS); Grainger, Richard (FIPS); Sibeni, Fabrizio (FIPS)
Subject: KMeansPlusPlusClusterer breaks on division by zero


Good morning,

I just have filed a bugreport in JIRA: https://issues.apache.org/jira/browse/MATH-429

Kind Regards,
Erik van Ingen

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


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


KMeansPlusPlusClusterer breaks on division by zero

Posted by "VanIngen, Erik (FIPS)" <Er...@fao.org>.
Good morning,

I just have filed a bugreport in JIRA:
https://issues.apache.org/jira/browse/MATH-429

Kind Regards,
Erik van Ingen

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


[math] EuclideanIntegerPoint EuclideanDoublePoint

Posted by "VanIngen, Erik (FIPS)" <Er...@fao.org>.
Good morning!

I need to to cluster analysis on values like this:
1.814263985     -0.633923297
2.501153739     -0.559033358
2.408755862     -0.509902975
1.935495243     -0.330554484
0.728818279     -0.169024633
-0.523861032    0.110392311

I can use EuclideanIntegerPoint, but than I have to convert the values to integers and would loose precission. So my trick would be to multiply with 1000, cluster and multiply the values with 0.001. Would that be a valid approach from a methodology point of view?

Are there any plans to develop a EuclideanDoublePoint?

Cheers,
Erik van Ingen

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


[math] Re: complex matrix operation

Posted by "Cuong P. Nguyen" <cn...@iit.edu>.
Hi Luc and friends, 

I have a question more related to java matrix storage. If I have a
3-dimentional m matrix say 2 by 2 by 2, I want to access the matrix
efficiently so I would like to know the order in which the data is stored in
the memory. I am not sure if it is stored consecutively this way in the
memory register:
m(1,1,1), m(1,1,2), m(1,2,1), m(1,2,2), m(2,1,1), m(2,1,2), m(2,2,1),
m(2,2,2)

I also wonder if the package could store sparse vectors, matrices and
perform basic operations on them?

Thanks,
Cuong

-----Original Message-----
From: Luc Maisonobe [mailto:Luc.Maisonobe@free.fr] 
Sent: Saturday, October 16, 2010 2:00 PM
To: Commons Users List
Subject: Re: [math] Re: complex matrix operation

Le 16/10/2010 20:38, Cuong P. Nguyen a écrit :
> Hi Luc and friends, 
> 
> Thanks a lot for the quick response
> 
> Could you give me any simple code example of Complex-type vector-matrix
> multiplication or matrix-matrix multiplication ?

Here is a matrix vector multiplication:

// create a 2x2 complex matrix
Complex[][] matrixData = new Complex[][] {
    { new Complex(1.0,  0.0), new Complex( 0.0, 1.0) },
    { new Complex(0.0, -1.0), new Complex(-1.0, 0.0) }
};
FieldMatrix<Complex> m = new Array2DRowFieldMatrix<Complex>(matrixData);

// create a vector
Complex[] vectorData = new Complex[] {
    new Complex(1.0, 2.0),
    new Complex(3.0, 4.0),
};
FieldVector<Complex> u = new ArrayFieldVector<Complex>(vectorData);

// perform matrix-vector multiplication
FieldVector<Complex> v = m.operate(u);

// print the initial vector
for (int i = 0; i < u.getDimension(); ++i) {
    System.out.println(ComplexFormat.formatComplex(u.getEntry(i)));
}

System.out.println();

// print the result
for (int i = 0; i < v.getDimension(); ++i) {
    System.out.println(ComplexFormat.formatComplex(v.getEntry(i)));
}



Luc

> 
> I am a new java beginner as well as new to Commons Math community.
> 
> Thanks,
> 
> Cuong
> 
> -----Original Message-----
> From: Luc Maisonobe [mailto:Luc.Maisonobe@free.fr] 
> Sent: Saturday, October 16, 2010 1:25 PM
> To: Commons Users List
> Subject: [math] Re: complex matrix operation
> 
> Le 16/10/2010 18:53, Cuong P. Nguyen a écrit :
>> Hi,
> 
> Hi Cuong,
> 
> First, please use a [math] marker on the subject line when posting to
> this list for the commons-math component. The list is shared among
> several commons components and these markers help filtering.
> 
>> can I use the package for basic complex-number matrix operations
>> (addition, subtraction, multiplication) ?
> 
> You can use the linear algebra packe from commons-math with complex
> matrices. The appropriate interface is FieldMatrix<Complex> which has
> two implementations: Array2DRowFieldMatrix<Complex> and
> BlockFieldMatrix<Complex>. The former should be preferred for small
> sizes and the later for large sizes. You can also use complex vectors
> and LU decomposition with these matrices.
> 
> Luc
> 
>>
>> Thanks
>>
>> Cuong
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 


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


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


Re: [math] Re: complex matrix operation

Posted by Luc Maisonobe <Lu...@free.fr>.
Le 16/10/2010 20:38, Cuong P. Nguyen a écrit :
> Hi Luc and friends, 
> 
> Thanks a lot for the quick response
> 
> Could you give me any simple code example of Complex-type vector-matrix
> multiplication or matrix-matrix multiplication ?

Here is a matrix vector multiplication:

// create a 2x2 complex matrix
Complex[][] matrixData = new Complex[][] {
    { new Complex(1.0,  0.0), new Complex( 0.0, 1.0) },
    { new Complex(0.0, -1.0), new Complex(-1.0, 0.0) }
};
FieldMatrix<Complex> m = new Array2DRowFieldMatrix<Complex>(matrixData);

// create a vector
Complex[] vectorData = new Complex[] {
    new Complex(1.0, 2.0),
    new Complex(3.0, 4.0),
};
FieldVector<Complex> u = new ArrayFieldVector<Complex>(vectorData);

// perform matrix-vector multiplication
FieldVector<Complex> v = m.operate(u);

// print the initial vector
for (int i = 0; i < u.getDimension(); ++i) {
    System.out.println(ComplexFormat.formatComplex(u.getEntry(i)));
}

System.out.println();

// print the result
for (int i = 0; i < v.getDimension(); ++i) {
    System.out.println(ComplexFormat.formatComplex(v.getEntry(i)));
}



Luc

> 
> I am a new java beginner as well as new to Commons Math community.
> 
> Thanks,
> 
> Cuong
> 
> -----Original Message-----
> From: Luc Maisonobe [mailto:Luc.Maisonobe@free.fr] 
> Sent: Saturday, October 16, 2010 1:25 PM
> To: Commons Users List
> Subject: [math] Re: complex matrix operation
> 
> Le 16/10/2010 18:53, Cuong P. Nguyen a écrit :
>> Hi,
> 
> Hi Cuong,
> 
> First, please use a [math] marker on the subject line when posting to
> this list for the commons-math component. The list is shared among
> several commons components and these markers help filtering.
> 
>> can I use the package for basic complex-number matrix operations
>> (addition, subtraction, multiplication) ?
> 
> You can use the linear algebra packe from commons-math with complex
> matrices. The appropriate interface is FieldMatrix<Complex> which has
> two implementations: Array2DRowFieldMatrix<Complex> and
> BlockFieldMatrix<Complex>. The former should be preferred for small
> sizes and the later for large sizes. You can also use complex vectors
> and LU decomposition with these matrices.
> 
> Luc
> 
>>
>> Thanks
>>
>> Cuong
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
> 


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


[math] Re: complex matrix operation

Posted by "Cuong P. Nguyen" <cn...@iit.edu>.
Hi Luc and friends, 

Thanks a lot for the quick response

Could you give me any simple code example of Complex-type vector-matrix
multiplication or matrix-matrix multiplication ?

I am a new java beginner as well as new to Commons Math community.

Thanks,

Cuong

-----Original Message-----
From: Luc Maisonobe [mailto:Luc.Maisonobe@free.fr] 
Sent: Saturday, October 16, 2010 1:25 PM
To: Commons Users List
Subject: [math] Re: complex matrix operation

Le 16/10/2010 18:53, Cuong P. Nguyen a écrit :
> Hi,

Hi Cuong,

First, please use a [math] marker on the subject line when posting to
this list for the commons-math component. The list is shared among
several commons components and these markers help filtering.

> can I use the package for basic complex-number matrix operations
> (addition, subtraction, multiplication) ?

You can use the linear algebra packe from commons-math with complex
matrices. The appropriate interface is FieldMatrix<Complex> which has
two implementations: Array2DRowFieldMatrix<Complex> and
BlockFieldMatrix<Complex>. The former should be preferred for small
sizes and the later for large sizes. You can also use complex vectors
and LU decomposition with these matrices.

Luc

> 
> Thanks
> 
> Cuong
> 
> 


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


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


[math] Re: complex matrix operation

Posted by Luc Maisonobe <Lu...@free.fr>.
Le 16/10/2010 18:53, Cuong P. Nguyen a écrit :
> Hi,

Hi Cuong,

First, please use a [math] marker on the subject line when posting to
this list for the commons-math component. The list is shared among
several commons components and these markers help filtering.

> can I use the package for basic complex-number matrix operations
> (addition, subtraction, multiplication) ?

You can use the linear algebra packe from commons-math with complex
matrices. The appropriate interface is FieldMatrix<Complex> which has
two implementations: Array2DRowFieldMatrix<Complex> and
BlockFieldMatrix<Complex>. The former should be preferred for small
sizes and the later for large sizes. You can also use complex vectors
and LU decomposition with these matrices.

Luc

> 
> Thanks
> 
> Cuong
> 
> 


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