1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>FreeMat: PINV Moore-Penrose Pseudoinverse</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
$(document).ready(initResizable);
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td style="padding-left: 0.5em;">
<div id="projectname">FreeMat
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.1.1 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main Page</span></a></li>
<li class="current"><a href="pages.html"><span>Related Pages</span></a></li>
</ul>
</div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('array_pinv.html','');});
</script>
<div id="doc-content">
<div class="header">
<div class="headertitle">
<div class="title">PINV Moore-Penrose Pseudoinverse </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>Section: <a class="el" href="sec_array.html">Array Generation and Manipulations</a> </p>
<h1><a class="anchor" id="Usage"></a>
Usage</h1>
<p>Calculates the Moore-Penrose pseudoinverse of a matrix. The general syntax for its use is </p>
<pre class="fragment"> y = pinv(A,tol)
</pre><p> or for a default specification of the tolerance <code>tol</code>, </p>
<pre class="fragment"> y = pinv(A)
</pre><p> For any <code>m x n</code> matrix <code>A</code>, the Moore-Penrose pseudoinverse is the unique <code>n x m</code> matrix <code>B</code> that satisfies the following four conditions </p>
<ul>
<li>
<code>A B A = A</code> </li>
<li>
<code>B A B = B</code> </li>
<li>
<code>(A B)' = A B</code> </li>
<li>
<code>(B A)' = B A</code> </li>
</ul>
<p>Also, it is true that <code>B y</code> is the minimum norm, least squares solution to <code>A x = y</code>. The Moore-Penrose pseudoinverse is computed from the singular value decomposition of <code>A</code>, with singular values smaller than <code>tol</code> being treated as zeros. If <code>tol</code> is not specified then it is chosen as </p>
<pre class="fragment"> tol = max(size(A)) * norm(A) * teps(A).
</pre> <h1><a class="anchor" id="Function"></a>
Internals</h1>
<p>The calculation of the MP pseudo-inverse is almost trivial once the svd of the matrix is available. First, for a real, diagonal matrix with positive entries, the pseudo-inverse is simply </p>
<p class="formulaDsp">
<img class="formulaDsp" alt="\[ \left(\Sigma^{+}\right)_{ii} = \begin{cases} 1/\sigma_{ii} & \sigma_{ii} > 0 \\ 0 & \mathrm{else} \end{cases} \]" src="form_5.png"/>
</p>
<p> One can quickly verify that this choice of matrix satisfies the four properties of the pseudoinverse. Then, the pseudoinverse of a general matrix <code>A = U S V'</code> is defined as </p>
<p class="formulaDsp">
<img class="formulaDsp" alt="\[ A^{+} = V S^{+} U' \]" src="form_6.png"/>
</p>
<p> and again, using the facts that <code>U' U = I</code> and <code>V V' = I</code>, one can quickly verify that this choice of pseudoinverse satisfies the four defining properties of the MP pseudoinverse. Note that in practice, the diagonal pseudoinverse <code>S^{+}</code> is computed with a threshold (the <code>tol</code> argument to <code>pinv</code>) so that singular values smaller than <code>tol</code> are treated like zeros. </p>
<h1><a class="anchor" id="Examples"></a>
Examples</h1>
<p>Consider a simple <code>1 x 2</code> matrix example, and note the various Moore-Penrose conditions:</p>
<pre class="fragment">--> A = float(rand(1,2))
A =
0.4840 0.0187
--> B = pinv(A)
B =
2.0630
0.0796
--> A*B*A
ans =
0.4840 0.0187
--> B*A*B
ans =
2.0630
0.0796
--> A*B
ans =
1.0000
--> B*A
ans =
0.9985 0.0385
0.0385 0.0015
</pre><p>To demonstrate that <code>pinv</code> returns the least squares solution, consider the following very simple case</p>
<pre class="fragment">--> A = float([1;1;1;1])
A =
1
1
1
1
</pre><p>The least squares solution to <code>A x = b</code> is just <code>x = mean(b)</code>, and computing the <code>pinv</code> of <code>A</code> demonstrates this</p>
<pre class="fragment">--> pinv(A)
ans =
0.2500 0.2500 0.2500 0.2500
</pre><p>Similarly, we can demonstrate the minimum norm solution with the following simple case</p>
<pre class="fragment">--> A = float([1,1])
A =
1 1
</pre><p>The solutions of <code>A x = 5</code> are those <code>x_1</code> and <code>x_2</code> such that <code>x_1 + x_2 = 5</code>. The norm of <code>x</code> is <code>x_1^ + x_2^2</code>, which is <code>x_1^2 + (5-x_1)^2</code>, which is minimized for <code>x_1 = x_2 = 2.5</code>:</p>
<pre class="fragment">--> pinv(A) * 5.0
ans =
2.5000
2.5000
</pre> </div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="index.html">FreeMat Documentation</a></li><li class="navelem"><a class="el" href="sec_array.html">Array Generation and Manipulations</a></li>
<li class="footer">Generated on Thu Jul 25 2013 18:58:11 for FreeMat by
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.1.1 </li>
</ul>
</div>
</body>
</html>
|