Home | History | Annotate | Download | only in linear
      1 /*
      2  * Licensed to the Apache Software Foundation (ASF) under one or more
      3  * contributor license agreements.  See the NOTICE file distributed with
      4  * this work for additional information regarding copyright ownership.
      5  * The ASF licenses this file to You under the Apache License, Version 2.0
      6  * (the "License"); you may not use this file except in compliance with
      7  * the License.  You may obtain a copy of the License at
      8  *
      9  *      http://www.apache.org/licenses/LICENSE-2.0
     10  *
     11  * Unless required by applicable law or agreed to in writing, software
     12  * distributed under the License is distributed on an "AS IS" BASIS,
     13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14  * See the License for the specific language governing permissions and
     15  * limitations under the License.
     16  */
     17 
     18 package org.apache.commons.math.linear;
     19 
     20 
     21 
     22 /**
     23  * An interface to classes that implement an algorithm to calculate the
     24  * Singular Value Decomposition of a real matrix.
     25  * <p>
     26  * The Singular Value Decomposition of matrix A is a set of three matrices: U,
     27  * &Sigma; and V such that A = U &times; &Sigma; &times; V<sup>T</sup>. Let A be
     28  * a m &times; n matrix, then U is a m &times; p orthogonal matrix, &Sigma; is a
     29  * p &times; p diagonal matrix with positive or null elements, V is a p &times;
     30  * n orthogonal matrix (hence V<sup>T</sup> is also orthogonal) where
     31  * p=min(m,n).
     32  * </p>
     33  * <p>This interface is similar to the class with similar name from the
     34  * <a href="http://math.nist.gov/javanumerics/jama/">JAMA</a> library, with the
     35  * following changes:</p>
     36  * <ul>
     37  *   <li>the <code>norm2</code> method which has been renamed as {@link #getNorm()
     38  *   getNorm},</li>
     39  *   <li>the <code>cond</code> method which has been renamed as {@link
     40  *   #getConditionNumber() getConditionNumber},</li>
     41  *   <li>the <code>rank</code> method which has been renamed as {@link #getRank()
     42  *   getRank},</li>
     43  *   <li>a {@link #getUT() getUT} method has been added,</li>
     44  *   <li>a {@link #getVT() getVT} method has been added,</li>
     45  *   <li>a {@link #getSolver() getSolver} method has been added,</li>
     46  *   <li>a {@link #getCovariance(double) getCovariance} method has been added.</li>
     47  * </ul>
     48  * @see <a href="http://mathworld.wolfram.com/SingularValueDecomposition.html">MathWorld</a>
     49  * @see <a href="http://en.wikipedia.org/wiki/Singular_value_decomposition">Wikipedia</a>
     50  * @version $Revision: 928081 $ $Date: 2010-03-26 23:36:38 +0100 (ven. 26 mars 2010) $
     51  * @since 2.0
     52  */
     53 public interface SingularValueDecomposition {
     54 
     55     /**
     56      * Returns the matrix U of the decomposition.
     57      * <p>U is an orthogonal matrix, i.e. its transpose is also its inverse.</p>
     58      * @return the U matrix
     59      * @see #getUT()
     60      */
     61     RealMatrix getU();
     62 
     63     /**
     64      * Returns the transpose of the matrix U of the decomposition.
     65      * <p>U is an orthogonal matrix, i.e. its transpose is also its inverse.</p>
     66      * @return the U matrix (or null if decomposed matrix is singular)
     67      * @see #getU()
     68      */
     69     RealMatrix getUT();
     70 
     71     /**
     72      * Returns the diagonal matrix &Sigma; of the decomposition.
     73      * <p>&Sigma; is a diagonal matrix. The singular values are provided in
     74      * non-increasing order, for compatibility with Jama.</p>
     75      * @return the &Sigma; matrix
     76      */
     77     RealMatrix getS();
     78 
     79     /**
     80      * Returns the diagonal elements of the matrix &Sigma; of the decomposition.
     81      * <p>The singular values are provided in non-increasing order, for
     82      * compatibility with Jama.</p>
     83      * @return the diagonal elements of the &Sigma; matrix
     84      */
     85     double[] getSingularValues();
     86 
     87     /**
     88      * Returns the matrix V of the decomposition.
     89      * <p>V is an orthogonal matrix, i.e. its transpose is also its inverse.</p>
     90      * @return the V matrix (or null if decomposed matrix is singular)
     91      * @see #getVT()
     92      */
     93     RealMatrix getV();
     94 
     95     /**
     96      * Returns the transpose of the matrix V of the decomposition.
     97      * <p>V is an orthogonal matrix, i.e. its transpose is also its inverse.</p>
     98      * @return the V matrix (or null if decomposed matrix is singular)
     99      * @see #getV()
    100      */
    101     RealMatrix getVT();
    102 
    103     /**
    104      * Returns the n &times; n covariance matrix.
    105      * <p>The covariance matrix is V &times; J &times; V<sup>T</sup>
    106      * where J is the diagonal matrix of the inverse of the squares of
    107      * the singular values.</p>
    108      * @param minSingularValue value below which singular values are ignored
    109      * (a 0 or negative value implies all singular value will be used)
    110      * @return covariance matrix
    111      * @exception IllegalArgumentException if minSingularValue is larger than
    112      * the largest singular value, meaning all singular values are ignored
    113      */
    114     RealMatrix getCovariance(double minSingularValue) throws IllegalArgumentException;
    115 
    116     /**
    117      * Returns the L<sub>2</sub> norm of the matrix.
    118      * <p>The L<sub>2</sub> norm is max(|A &times; u|<sub>2</sub> /
    119      * |u|<sub>2</sub>), where |.|<sub>2</sub> denotes the vectorial 2-norm
    120      * (i.e. the traditional euclidian norm).</p>
    121      * @return norm
    122      */
    123     double getNorm();
    124 
    125     /**
    126      * Return the condition number of the matrix.
    127      * @return condition number of the matrix
    128      */
    129     double getConditionNumber();
    130 
    131     /**
    132      * Return the effective numerical matrix rank.
    133      * <p>The effective numerical rank is the number of non-negligible
    134      * singular values. The threshold used to identify non-negligible
    135      * terms is max(m,n) &times; ulp(s<sub>1</sub>) where ulp(s<sub>1</sub>)
    136      * is the least significant bit of the largest singular value.</p>
    137      * @return effective numerical matrix rank
    138      */
    139     int getRank();
    140 
    141     /**
    142      * Get a solver for finding the A &times; X = B solution in least square sense.
    143      * @return a solver
    144      */
    145     DecompositionSolver getSolver();
    146 
    147 }
    148