.NET Matrix Library
PseudoInverse(Double) Method
See Also  Example Send Feedback



tolerance
A double specifying the value under which the singular values of the matrix are considered to be zero.
Returns the Moore-Penrose inverse (pseudoinverse) of the matrix.

Syntax

Visual Basic (Declaration) 
Public Overloads Function PseudoInverse( _
   ByVal tolerance As Double _
) As Matrix
Visual Basic (Usage)Copy Code
Dim instance As Matrix
Dim tolerance As Double
Dim value As Matrix
 
value = instance.PseudoInverse(tolerance)
C# 
public Matrix PseudoInverse( 
   double tolerance
)
C++/CLI 
public:
Matrix^ PseudoInverse( 
   double tolerance
) 

Parameters

tolerance
A double specifying the value under which the singular values of the matrix are considered to be zero.

Return Value

A Matrix object representing the Moore-Penrose inverse (pseudoinverse) of this matrix.

Example

The following example defines a matrix, it uses the PseudoInverse method to calculate its pseudoinverse and then verifies the four Moore-Penrose conditions.
Visual BasicCopy Code
Imports System
Imports Bluebit.MatrixLibrary

Class Test

    Public Shared Sub Main()

        'Declaring a random 4x3 Matrix
        Dim A, Ai, R As Matrix
        A = New Matrix(4, 3)
        A.FillRandom()

        Console.WriteLine("Matrix A")
        Console.WriteLine(A)

        'Calculating its Moore-Penrose inverse
        Ai = A.PseudoInverse
        Console.WriteLine("Matrix A+ (Pseudoinverse of matrix A)")
        Console.WriteLine(Ai)

        'Verify the four conditions for the Moore-Penrose inverse

        'Verify that A * A+ * A = A
        R = Matrix.Multiply(Matrix.Multiply(A, Ai), A)
        'Matrix R should be equal to A
        Console.WriteLine("A * A+ * A =")
        Console.WriteLine(R)
        Console.WriteLine(String.Format("The relation A * A+ * A = A is {0}", R.IsEqual(A)))
        Console.WriteLine()

        'Verify that A+ * A * A+ = A+
        R = Matrix.Multiply(Matrix.Multiply(Ai, A), Ai)
        'Matrix R should be equal to A+
        Console.WriteLine("A+ * A * A+ =")
        Console.WriteLine(R)
        Console.WriteLine(String.Format("The relation A+ * A * A+ = A+ is {0}", R.IsEqual(Ai)))
        Console.WriteLine()

        'Verify that (A * A+)T = A * A+ (the product A * A+ is a symmetric matrix)
        R = Matrix.Multiply(A, Ai)
        Console.WriteLine("A * A+ =")
        Console.WriteLine(R)
        Console.WriteLine(String.Format("Is A * A+  as symmetric matrix = {0}", R.IsSymmetric()))

        'Verify that (A+ * A)T = A+ * A (the product A+ * A is a symmetric matrix)
        R = Matrix.Multiply(Ai, A)
        Console.WriteLine("A+ * A =")
        Console.WriteLine(R)
        Console.WriteLine(String.Format("Is A+ * A  as symmetric matrix = {0}", R.IsSymmetric()))

        Console.Read()

    End Sub

End Class
C#Copy Code
using System;
using Bluebit.MatrixLibrary;

class Test
{
    static void Main(string[] args)
    {
        //Declaring a random 4x3 Matrix
        Matrix A, Ai, R;
        A = new Matrix(4, 3);
        A.FillRandom();

        Console.WriteLine("Matrix A");
        Console.WriteLine(A);

        //Calculating its Moore-Penrose inverse
        Ai = A.PseudoInverse();
        Console.WriteLine("Matrix A+ (Pseudoinverse of matrix A)");
        Console.WriteLine(Ai);

        //Verify the four conditions for the Moore-Penrose inverse

        //Verify that A * A+ * A = A
        //R = Matrix.Multiply(Matrix.Multiply(A, Ai), A);
        // C# allows the use of oveloaded operators
        R = A * Ai * A;
        //Matrix R should be equal to A
        Console.WriteLine("A * A+ * A =");
        Console.WriteLine(R);
        Console.WriteLine(String.Format("The relation A * A+ * A = A is {0}", R.IsEqual(A)));
        Console.WriteLine();

        //Verify that A+ * A * A+ = A+
        //R = Matrix.Multiply(Matrix.Multiply(Ai, A), Ai);
        // C# allows the use of oveloaded operators
        R = Ai * A * Ai;
        //Matrix R should be equal to A+
        Console.WriteLine("A+ * A * A+ =");
        Console.WriteLine(R);
        Console.WriteLine(String.Format("The relation A+ * A * A+ = A+ is {0}", R.IsEqual(Ai)));
        Console.WriteLine();

        //Verify that (A * A+)T = A * A+ (the product A * A+ is a symmetric matrix)
        //R = Matrix.Multiply(A, Ai);
        R = A * Ai;
        Console.WriteLine("A * A+ =");
        Console.WriteLine(R);
        Console.WriteLine(String.Format("Is A * A+  as symmetric matrix = {0}", R.IsSymmetric()));

        //Verify that (A+ * A)T = A+ * A (the product A+ * A is a symmetric matrix)
        //R = Matrix.Multiply(Ai, A);
        R = Ai * A;
        Console.WriteLine("A+ * A =");
        Console.WriteLine(R);
        Console.WriteLine(String.Format("Is A+ * A  as symmetric matrix = {0}", R.IsSymmetric()));

        Console.Read();
    }
}
C++Copy Code
#include "stdafx.h"

using namespace System;
using namespace Bluebit::MatrixLibrary;

int main(array<System::String ^> ^args) 
{
        //Declaring a random 4x3 Matrix
        Matrix  ^A, ^Ai, ^R;
        A = gcnew Matrix(4, 3);
        A->FillRandom();

        Console::WriteLine("Matrix A");
        Console::WriteLine(A);

        //Calculating its Moore-Penrose inverse
        Ai = A->PseudoInverse();
        Console::WriteLine("Matrix A+ (Pseudoinverse of matrix A)");
        Console::WriteLine(Ai);

        //Verify the four conditions for the Moore-Penrose inverse

        //Verify that A * A+ * A = A
        R = Matrix::Multiply(Matrix::Multiply(A, Ai), A);
        //Matrix R should be equal to A
        Console::WriteLine("A * A+ * A =");
        Console::WriteLine(R);
        Console::WriteLine(String::Format("The relation A * A+ * A = A is {0}", R->IsEqual(A) ));
        Console::WriteLine();

        //Verify that A+ * A * A+ = A+
        R = Matrix::Multiply(Matrix::Multiply(Ai, A), Ai);
        //Matrix R should be equal to A+
        Console::WriteLine("A+ * A * A+ =");
        Console::WriteLine(R);
        Console::WriteLine(String::Format("The relation A+ * A * A+ = A+ is {0}", R->IsEqual(Ai) ));
        Console::WriteLine();

        //Verify that (A * A+)T = A * A+ (the product A * A+ is a symmetric matrix)
        R = Matrix::Multiply(A, Ai);
        Console::WriteLine("A * A+ =");
        Console::WriteLine(R);
        Console::WriteLine(String::Format("Is A * A+  as symmetric matrix = {0}", R->IsSymmetric() ));

        //Verify that (A+ * A)T = A+ * A (the product A+ * A is a symmetric matrix)
        R = Matrix::Multiply(Ai, A);
        Console::WriteLine("A+ * A =");
        Console::WriteLine(R);
        Console::WriteLine(String::Format("Is A+ * A  as symmetric matrix = {0}", R->IsSymmetric() ));

        Console::Read();
    
	return 0;
}

Remarks

Singular value decomposition is used for the calculation of the pseudoinverse. Round-off errors can lead to a singular value not being exactly zero even if it should be. tolerance parameter places a threshold when comparing singular values with zero and improves the numerical stability of the method with singular or near-singular matrices.

If A+ is the Moore-Penrose inverse (pseudoinverse) of matrix A then it satisfies the following four conditions:

  • A*A+*A = A
  • A+*A*A+ = A+
  • (A*A+)T = A*A+
  • (A+*A)T = A+*A

Requirements

Target Platforms: Windows 2000, Windows XP, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7

See Also

.NET Matrix Library