Need some Linear Algebra Packages

Discussion in 'Java' started by ckumar, Jan 12, 2005.

  1. ckumar

    ckumar Guest

    Hai,

    Someone tell me which is the best package for Linear Algebra
    Calculations.Currently I came across some packages namely JLAPACK and
    JAMA.

    With regards
    ackumar
    ckumar, Jan 12, 2005
    #1
    1. Advertising

  2. On Wed, 12 Jan 2005 05:07:10 -0500, ckumar wrote:
    > Someone tell me which is the best package for Linear Algebra
    > Calculations.Currently I came across some packages namely JLAPACK
    > and JAMA.


    I don't know which is the best package (or how *you* define "best"),
    but there are many such packages, for example:

    http://math.nist.gov/javanumerics/#libraries

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
    Gordon Beaton, Jan 12, 2005
    #2
    1. Advertising

  3. ckumar

    ckumar Guest

    Hai,

    Thanx. I downloaded two packages from this site JAMA and Matrix Toolkit
    for Java(MTJ). I calculated Singular Vector Decomposition using these
    packages. On decomposing the input matrix(X) we will get three matrices
    namely,

    U - Left Singular Matrix
    S - Singular values
    V - Right singular Matrix

    then X=U*S*(VTranspose).

    This works fine for JAMA. But in MTJ I not able to get back the input
    matrix on multiplying these three matrices.

    I downloaded MTJ from following site
    http://www.math.uib.no/~bjornoh/mtj/

    I like to know whether the problem is on package or in my code.

    Regards,
    ackumar

    CODE:

    import mt.*;
    import mt.fact.*;
    import java.io.*;
    import java.lang.*;

    class mtjSVD{
    public static void main(String args[])
    {
    String val=new String();
    double[][] array={{1.0,2.0},{1.0,1.0},{1.0,3.0}};

    DenseMatrix X=new DenseMatrix(array);
    System.out.println("Rows="+X.numRows()+"\nCols="+X.numColumns());
    System.out.println("\n********************\tX\t*******************\n");
    printMatrix(X);

    SingularvalueComputer svc=new
    SingularvalueComputer(X.numRows(),X.numColumns(),true);
    SVD svd=new SVD(X.numRows(),X.numColumns());
    try{
    svd=svc.factor(X.copy());
    }catch(Exception ee){ee.printStackTrace();}

    DenseMatrix U=svd.getU();
    System.out.println("********************\tU\t*******************\n");
    printMatrix(U,5);

    DenseMatrix V=svd.getVt();
    System.out.println("********************\tV\t*******************\n");
    printMatrix(V,5);

    DenseMatrix S = new DenseMatrix(X.numRows(),X.numColumns());
    double singVal[]=svd.getS();

    for(int i=0;i<2;i++)
    S.set(i,i,singVal);
    System.out.println("********************\tS\t*******************\n");
    printMatrix(S);

    System.out.println("********************\tRetained -
    X\t*******************\n");
    DenseMatrix retainedX=new DenseMatrix(X.numRows(),X.numColumns());
    retainedX=(DenseMatrix)U.mult(S,retainedX);
    retainedX=(DenseMatrix)retainedX.mult(V.transpose(),retainedX);
    printMatrix(retainedX);

    }

    static void printMatrix(Matrix M)
    {
    for(int i=0;i<M.numRows();i++)
    {
    for(int j=0;j<M.numColumns();j++)
    {
    System.out.print(M.get(i,j)+"\t");
    }
    System.out.println("\n");
    }
    }

    static void printMatrix(Matrix M,int val)
    {
    for(int i=0;i<M.numRows();i++)
    {
    for(int j=0;j<M.numColumns();j++)
    {
    System.out.print((Double.toString(M.get(i,j))).substring(0,val)+" ");
    }
    System.out.println("\n");
    }
    }

    }
    ckumar, Jan 17, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bernard Xhumga
    Replies:
    0
    Views:
    460
    Bernard Xhumga
    Nov 24, 2003
  2. C. Barnes
    Replies:
    5
    Views:
    533
    Szabolcs Nagy
    Sep 11, 2005
  3. Replies:
    0
    Views:
    293
  4. Terry Reedy
    Replies:
    1
    Views:
    316
  5. C. Barnes
    Replies:
    0
    Views:
    456
    C. Barnes
    Sep 14, 2005
Loading...

Share This Page