You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pinv(M, rtol::Real) = pinv(M; rtol=rtol) # to be deprecated in Julia 2.0
1241
1242
1242
1243
Computes the Moore-Penrose pseudoinverse.
1243
1244
1244
1245
For matrices `M` with floating point elements, it is convenient to compute
1245
1246
the pseudoinverse by inverting only singular values greater than
1246
-
`rtol * maximum(svdvals(M))`.
1247
+
`max(atol, rtol*σ₁)` where `σ₁` is the largest singular value of `M`.
1247
1248
1248
-
The optimal choice of `rtol` varies both with the value of `M` and the intended application
1249
-
of the pseudoinverse. The default value of `rtol` is
1250
-
`eps(real(float(one(eltype(M)))))*minimum(size(M))`, which is essentially machine epsilon
1251
-
for the real part of a matrix element multiplied by the larger matrix dimension. For
1252
-
inverting dense ill-conditioned matrices in a least-squares sense,
1249
+
The optimal choice of absolute (`atol`) and relative tolerance (`rtol`) varies
1250
+
both with the value of `M` and the intended application of the pseudoinverse.
1251
+
The default relative tolerance is `n*ϵ`, where `n` is the size of the smallest
1252
+
dimension of `M`, and `ϵ` is the [`eps`](@ref) of the element type of `M`.
1253
+
1254
+
For inverting dense ill-conditioned matrices in a least-squares sense,
1253
1255
`rtol = sqrt(eps(real(float(one(eltype(M))))))` is recommended.
1254
1256
1255
1257
For more information, see [^issue8859], [^B96], [^S84], [^KY88].
@@ -1280,7 +1282,7 @@ julia> M * N
1280
1282
1281
1283
[^KY88]: Konstantinos Konstantinides and Kung Yao, "Statistical analysis of effective singular values in matrix rank determination", IEEE Transactions on Acoustics, Speech and Signal Processing, 36(5), 1988, 757-763. [doi:10.1109/29.1585](https://doi.org/10.1109/29.1585)
1282
1284
"""
1283
-
functionpinv(A::AbstractMatrix{T}, rtol::Real) where T
1285
+
functionpinv(A::AbstractMatrix{T}; atol::Real=0.0, rtol::Real= (eps(real(float(one(T))))*min(size(A)...))*iszero(atol)) where T
1284
1286
m, n =size(A)
1285
1287
Tout =typeof(zero(T)/sqrt(one(T) +one(T)))
1286
1288
if m ==0|| n ==0
@@ -1289,9 +1291,10 @@ function pinv(A::AbstractMatrix{T}, rtol::Real) where T
1289
1291
ifistril(A)
1290
1292
ifistriu(A)
1291
1293
maxabsA =maximum(abs.(diag(A)))
1294
+
tol =max(rtol*maxabsA, atol)
1292
1295
B =zeros(Tout, n, m)
1293
1296
for i =1:min(m, n)
1294
-
ifabs(A[i,i]) >rtol*maxabsA
1297
+
ifabs(A[i,i]) >tol
1295
1298
Aii =inv(A[i,i])
1296
1299
ifisfinite(Aii)
1297
1300
B[i,i] = Aii
@@ -1302,17 +1305,14 @@ function pinv(A::AbstractMatrix{T}, rtol::Real) where T
0 commit comments