org.astrogrid.matrix
Class MatrixUtils

java.lang.Object
  extended by org.astrogrid.matrix.MatrixUtils

public class MatrixUtils
extends java.lang.Object

Utility functions that operate on matrices. These are intended to operate in the same fashion as the similarly named MATLAB functions.

Since:
AIDA Stage 1
Version:
$Name: $
Author:
Paul Harrison (paul.harrison@manchester.ac.uk) 4 Aug 2009

Constructor Summary
MatrixUtils()
           
 
Method Summary
static Matrix add(double eps, Matrix q)
           
static no.uib.cipr.matrix.Vector add(double d, no.uib.cipr.matrix.Vector v)
           
static Matrix add(Matrix q, double eps)
           
static AGDenseMatrix add(no.uib.cipr.matrix.Matrix a, no.uib.cipr.matrix.Matrix b)
          R = A+B.
static no.uib.cipr.matrix.Vector add(no.uib.cipr.matrix.Vector v, double d)
           
static no.uib.cipr.matrix.Vector add(no.uib.cipr.matrix.Vector a, no.uib.cipr.matrix.Vector b)
          Elementwise addition of vectors.
static Matrix cov(Matrix x)
          Forms the covariance matrix.
static no.uib.cipr.matrix.DenseVector delElement(no.uib.cipr.matrix.DenseVector v, int i)
           
static double det(Matrix m)
           
static no.uib.cipr.matrix.Vector diag(no.uib.cipr.matrix.Matrix x)
           
static Matrix diag(no.uib.cipr.matrix.Vector v)
           
static Matrix dirichlet_sample(no.uib.cipr.matrix.Vector m, int j)
           
static Matrix divide(Matrix a, Matrix b)
          Elementwise divide of matrix.
static no.uib.cipr.matrix.Vector divide(no.uib.cipr.matrix.Vector a, no.uib.cipr.matrix.Vector b)
          Elementwise divide of vector.
static Matrix exp(Matrix m)
           
static no.uib.cipr.matrix.Vector exp(no.uib.cipr.matrix.Vector v)
           
static Matrix eye(int ndim)
          produces square identity matrix.
static Matrix eye(int ndim, double val)
          produces square diagonal matrix using val.
static Matrix inv(Matrix a)
           
static Matrix log(Matrix m)
           
static no.uib.cipr.matrix.Vector log(no.uib.cipr.matrix.Vector v)
           
static no.uib.cipr.matrix.Vector max(Matrix im)
           
static double max(no.uib.cipr.matrix.Vector iv)
           
static int min(no.uib.cipr.matrix.Vector v)
           
static AGDenseMatrix mult(no.uib.cipr.matrix.Matrix a, no.uib.cipr.matrix.Matrix b)
          C = AB
static AGDenseMatrix mult(no.uib.cipr.matrix.Matrix a, no.uib.cipr.matrix.Vector b)
          C = AB
static Matrix mult(no.uib.cipr.matrix.Vector a, no.uib.cipr.matrix.Matrix b)
          a*b - treating a as a column vector.
static Matrix multABAT(no.uib.cipr.matrix.Matrix a, no.uib.cipr.matrix.Matrix b)
          C = A*B*AT
static AGDenseMatrix multAt(no.uib.cipr.matrix.Matrix a, no.uib.cipr.matrix.Matrix b)
          C = ATB
static AGDenseMatrix multAt(no.uib.cipr.matrix.Vector v, no.uib.cipr.matrix.Matrix b)
          C = ATB.
static Matrix multATBA(no.uib.cipr.matrix.DenseVector v, no.uib.cipr.matrix.Matrix b)
          C = AT*B*A
static AGDenseMatrix multBt(no.uib.cipr.matrix.Matrix a, no.uib.cipr.matrix.Matrix b)
          C = ABT
static Matrix ones(int n)
           
static Matrix ones(int n, int m)
           
static Matrix pow(Matrix m, double exp)
          raise each member to the power.
static no.uib.cipr.matrix.Vector pow(no.uib.cipr.matrix.Vector v, double exp)
           
static double psi(double d)
           
static Matrix psi(Matrix m)
           
static Matrix rand(int i, int j)
           
static Matrix recip(double a, Matrix m)
          Form the elementwise a/mij.
static no.uib.cipr.matrix.Vector recip(double a, no.uib.cipr.matrix.Vector v)
          Form the elementwise a/vi.
static Matrix recip(Matrix m)
           
static no.uib.cipr.matrix.Vector recip(no.uib.cipr.matrix.Vector v)
           
static Matrix repmat(Matrix v, int ni, int nj)
           
static Matrix repmat(no.uib.cipr.matrix.Vector v, int ni, int nj)
          Repeat a vector into a matrix treating the vector as a column vector.
static Matrix repmatt(no.uib.cipr.matrix.Vector v, int ni, int nj)
          Repeat a vector into a matrix treating the vector as a row vector.
static Matrix repmatv(no.uib.cipr.matrix.Vector v, int ni, int nj)
           
static AGDenseMatrix reshape(Matrix m, int ni, int nj)
           
static AGDenseMatrix reshape(no.uib.cipr.matrix.Vector v, int ni, int nj)
           
static no.uib.cipr.matrix.Vector seq(int n)
          Return a vector filled with a sequence from 1 to n;
static no.uib.cipr.matrix.Vector sub(double d, no.uib.cipr.matrix.Vector v)
          R= d-v = elementwise subtraction.
static Matrix sub(no.uib.cipr.matrix.Matrix a, double b)
           
static Matrix sub(no.uib.cipr.matrix.Matrix a, no.uib.cipr.matrix.Matrix b)
          R = A-B.
static no.uib.cipr.matrix.Vector sub(no.uib.cipr.matrix.Vector v, double d)
           
static no.uib.cipr.matrix.Vector sub(no.uib.cipr.matrix.Vector a, no.uib.cipr.matrix.Vector b)
          Elementwise difference of vectors.
static no.uib.cipr.matrix.Vector sum(Matrix m)
           
static no.uib.cipr.matrix.Vector sum(Matrix x, int dim)
           
static double sum(no.uib.cipr.matrix.Vector v)
           
static Matrix sumsq(Matrix m)
          produces a matrix which is the sum of the squares of each row.
static Matrix times(double b, Matrix a)
           
static no.uib.cipr.matrix.Vector times(double b, no.uib.cipr.matrix.Vector a)
          Elementwise product of vectors and double
static Matrix times(Matrix a, double b)
           
static Matrix times(no.uib.cipr.matrix.Matrix a, no.uib.cipr.matrix.Matrix b)
          Elementwise multiply of matrix.
static no.uib.cipr.matrix.Vector times(no.uib.cipr.matrix.Vector a, double b)
          Elementwise product of vectors and double
static no.uib.cipr.matrix.Vector times(no.uib.cipr.matrix.Vector a, no.uib.cipr.matrix.Vector b)
          Elementwise product of vectors.
static double trace(Matrix m)
           
static AGDenseMatrix transpose(no.uib.cipr.matrix.Matrix a)
           
static Matrix vprod(no.uib.cipr.matrix.Vector a)
          Forms the vector product of the two vectors -i.e.
static Matrix vprod(no.uib.cipr.matrix.Vector a, no.uib.cipr.matrix.Vector b)
          Forms the vector product of the two vectors -i.e.
static AGDenseMatrix zeros(int n)
           
static AGDenseMatrix zeros(int n, int m)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MatrixUtils

public MatrixUtils()
Method Detail

cov

public static Matrix cov(Matrix x)
Forms the covariance matrix. For matrices, where each row is an observation, and each column a variable, COV(X) is the covariance matrix. DIAG(COV(X)) is a vector of variances for each column, and SQRT(DIAG(COV(X))) is a vector of standard deviations COV(X) or COV(X,Y) normalizes by (N-1) if N>1, where N is the number of observations. This makes COV(X) the best unbiased estimate of the covariance matrix if the observations are from a normal distribution. For N=1, COV normalizes by N. compatible with MatLab definition of the same also @see http://mathworld.wolfram.com/Covariance.html

Parameters:
x -
Returns:

zeros

public static AGDenseMatrix zeros(int n)

zeros

public static AGDenseMatrix zeros(int n,
                                  int m)

ones

public static Matrix ones(int n)

ones

public static Matrix ones(int n,
                          int m)

sum

public static no.uib.cipr.matrix.Vector sum(Matrix x,
                                            int dim)

sum

public static double sum(no.uib.cipr.matrix.Vector v)

sum

public static no.uib.cipr.matrix.Vector sum(Matrix m)

diag

public static no.uib.cipr.matrix.Vector diag(no.uib.cipr.matrix.Matrix x)

diag

public static Matrix diag(no.uib.cipr.matrix.Vector v)

repmatv

public static Matrix repmatv(no.uib.cipr.matrix.Vector v,
                             int ni,
                             int nj)

repmat

public static Matrix repmat(Matrix v,
                            int ni,
                            int nj)

repmat

public static Matrix repmat(no.uib.cipr.matrix.Vector v,
                            int ni,
                            int nj)
Repeat a vector into a matrix treating the vector as a column vector.

Parameters:
v -
ni -
nj -
Returns:

repmatt

public static Matrix repmatt(no.uib.cipr.matrix.Vector v,
                             int ni,
                             int nj)
Repeat a vector into a matrix treating the vector as a row vector.

Parameters:
v -
ni -
nj -
Returns:

reshape

public static AGDenseMatrix reshape(Matrix m,
                                    int ni,
                                    int nj)

reshape

public static AGDenseMatrix reshape(no.uib.cipr.matrix.Vector v,
                                    int ni,
                                    int nj)

det

public static double det(Matrix m)

trace

public static double trace(Matrix m)

divide

public static Matrix divide(Matrix a,
                            Matrix b)
Elementwise divide of matrix.

Parameters:
a -
b -
Returns:

times

public static Matrix times(no.uib.cipr.matrix.Matrix a,
                           no.uib.cipr.matrix.Matrix b)
Elementwise multiply of matrix.

Parameters:
a -
b -
Returns:

divide

public static no.uib.cipr.matrix.Vector divide(no.uib.cipr.matrix.Vector a,
                                               no.uib.cipr.matrix.Vector b)
Elementwise divide of vector.

Parameters:
a -
b -
Returns:

add

public static no.uib.cipr.matrix.Vector add(no.uib.cipr.matrix.Vector a,
                                            no.uib.cipr.matrix.Vector b)
Elementwise addition of vectors.

Parameters:
a -
b -
Returns:

times

public static no.uib.cipr.matrix.Vector times(no.uib.cipr.matrix.Vector a,
                                              no.uib.cipr.matrix.Vector b)
Elementwise product of vectors.

Parameters:
a -
b -
Returns:

times

public static no.uib.cipr.matrix.Vector times(no.uib.cipr.matrix.Vector a,
                                              double b)
Elementwise product of vectors and double

Parameters:
a -
b -
Returns:

times

public static no.uib.cipr.matrix.Vector times(double b,
                                              no.uib.cipr.matrix.Vector a)
Elementwise product of vectors and double

Parameters:
a -
b -
Returns:

times

public static Matrix times(double b,
                           Matrix a)

times

public static Matrix times(Matrix a,
                           double b)

sub

public static no.uib.cipr.matrix.Vector sub(no.uib.cipr.matrix.Vector a,
                                            no.uib.cipr.matrix.Vector b)
Elementwise difference of vectors.

Parameters:
a -
b -
Returns:

inv

public static Matrix inv(Matrix a)

mult

public static AGDenseMatrix mult(no.uib.cipr.matrix.Matrix a,
                                 no.uib.cipr.matrix.Matrix b)
C = AB

Parameters:
a -
b -
Returns:

mult

public static AGDenseMatrix mult(no.uib.cipr.matrix.Matrix a,
                                 no.uib.cipr.matrix.Vector b)
C = AB

Parameters:
a -
b -
Returns:

multBt

public static AGDenseMatrix multBt(no.uib.cipr.matrix.Matrix a,
                                   no.uib.cipr.matrix.Matrix b)
C = ABT

Parameters:
a -
b -
Returns:

multAt

public static AGDenseMatrix multAt(no.uib.cipr.matrix.Matrix a,
                                   no.uib.cipr.matrix.Matrix b)
C = ATB

Parameters:
a -
b -
Returns:

multABAT

public static Matrix multABAT(no.uib.cipr.matrix.Matrix a,
                              no.uib.cipr.matrix.Matrix b)
C = A*B*AT

Parameters:
a -
b -
Returns:

multATBA

public static Matrix multATBA(no.uib.cipr.matrix.DenseVector v,
                              no.uib.cipr.matrix.Matrix b)
C = AT*B*A

Parameters:
a -
b -
Returns:

mult

public static Matrix mult(no.uib.cipr.matrix.Vector a,
                          no.uib.cipr.matrix.Matrix b)
a*b - treating a as a column vector.

Parameters:
a -
b -
Returns:

multAt

public static AGDenseMatrix multAt(no.uib.cipr.matrix.Vector v,
                                   no.uib.cipr.matrix.Matrix b)
C = ATB. Make the vector row vector before multiplying.

Parameters:
a -
b -
Returns:

add

public static AGDenseMatrix add(no.uib.cipr.matrix.Matrix a,
                                no.uib.cipr.matrix.Matrix b)
R = A+B. Elementwise addition of matrices - must be the same size.

Parameters:
a -
b -
Returns:

add

public static no.uib.cipr.matrix.Vector add(no.uib.cipr.matrix.Vector v,
                                            double d)

add

public static no.uib.cipr.matrix.Vector add(double d,
                                            no.uib.cipr.matrix.Vector v)

add

public static Matrix add(Matrix q,
                         double eps)

add

public static Matrix add(double eps,
                         Matrix q)

sub

public static Matrix sub(no.uib.cipr.matrix.Matrix a,
                         no.uib.cipr.matrix.Matrix b)
R = A-B. Elementwise subtraction of matrices - must be the same size.

Parameters:
a -
b -
Returns:

sub

public static Matrix sub(no.uib.cipr.matrix.Matrix a,
                         double b)

sub

public static no.uib.cipr.matrix.Vector sub(double d,
                                            no.uib.cipr.matrix.Vector v)
R= d-v = elementwise subtraction.

Parameters:
d -
v -
Returns:

sub

public static no.uib.cipr.matrix.Vector sub(no.uib.cipr.matrix.Vector v,
                                            double d)

eye

public static Matrix eye(int ndim,
                         double val)
produces square diagonal matrix using val.

Parameters:
ndim -
val - - the value to put on the diagonal.
Returns:

eye

public static Matrix eye(int ndim)
produces square identity matrix.

Parameters:
ndim - - the dimension of the matrix
Returns:

transpose

public static AGDenseMatrix transpose(no.uib.cipr.matrix.Matrix a)

max

public static double max(no.uib.cipr.matrix.Vector iv)

max

public static no.uib.cipr.matrix.Vector max(Matrix im)

rand

public static Matrix rand(int i,
                          int j)

dirichlet_sample

public static Matrix dirichlet_sample(no.uib.cipr.matrix.Vector m,
                                      int j)

psi

public static Matrix psi(Matrix m)

psi

public static double psi(double d)

log

public static Matrix log(Matrix m)

exp

public static Matrix exp(Matrix m)

exp

public static no.uib.cipr.matrix.Vector exp(no.uib.cipr.matrix.Vector v)

log

public static no.uib.cipr.matrix.Vector log(no.uib.cipr.matrix.Vector v)

pow

public static Matrix pow(Matrix m,
                         double exp)
raise each member to the power.

Parameters:
m -
exp -
Returns:

pow

public static no.uib.cipr.matrix.Vector pow(no.uib.cipr.matrix.Vector v,
                                            double exp)

recip

public static Matrix recip(Matrix m)

recip

public static no.uib.cipr.matrix.Vector recip(no.uib.cipr.matrix.Vector v)

recip

public static Matrix recip(double a,
                           Matrix m)
Form the elementwise a/mij.

Parameters:
m -
a -
Returns:

recip

public static no.uib.cipr.matrix.Vector recip(double a,
                                              no.uib.cipr.matrix.Vector v)
Form the elementwise a/vi.

Parameters:
m -
a -
Returns:

sumsq

public static Matrix sumsq(Matrix m)
produces a matrix which is the sum of the squares of each row.

Parameters:
m -
Returns:

seq

public static no.uib.cipr.matrix.Vector seq(int n)
Return a vector filled with a sequence from 1 to n;

Parameters:
n -
Returns:

vprod

public static Matrix vprod(no.uib.cipr.matrix.Vector a,
                           no.uib.cipr.matrix.Vector b)
Forms the vector product of the two vectors -i.e. abT.

Parameters:
a -
b -
Returns:

vprod

public static Matrix vprod(no.uib.cipr.matrix.Vector a)
Forms the vector product of the two vectors -i.e. aaT.

Parameters:
a -
b -
Returns:

delElement

public static no.uib.cipr.matrix.DenseVector delElement(no.uib.cipr.matrix.DenseVector v,
                                                        int i)

min

public static int min(no.uib.cipr.matrix.Vector v)


Copyright © 2008-2010 AstroGrid. All Rights Reserved.