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
* clarify pinv documentation
The `pinv` documentation falsely implied that it discarded singular values `σ > tol`, when in fact it discards `σ > tol max(σ)`. This PR corrects the docstring.
(`σ > tol max(σ)` is a good behavior! `tol` should be a dimensionless quantity that doesn't depend on the overall scaling/units of the matrix.)
* rename tol -> rtol
(cherry picked from commit 2996521)
For matrices `M` with floating point elements, it is convenient to compute
1227
-
the pseudoinverse by inverting only singular values above a given threshold,
1228
-
`tol`.
1227
+
the pseudoinverse by inverting only singular values greater than
1228
+
`rtol * maximum(svdvals(M))`.
1229
1229
1230
-
The optimal choice of `tol` varies both with the value of `M` and the intended application
1231
-
of the pseudoinverse. The default value of `tol` is
1230
+
The optimal choice of `rtol` varies both with the value of `M` and the intended application
1231
+
of the pseudoinverse. The default value of `rtol` is
1232
1232
`eps(real(float(one(eltype(M)))))*minimum(size(M))`, which is essentially machine epsilon
1233
1233
for the real part of a matrix element multiplied by the larger matrix dimension. For
1234
1234
inverting dense ill-conditioned matrices in a least-squares sense,
1235
-
`tol = sqrt(eps(real(float(one(eltype(M))))))` is recommended.
1235
+
`rtol = sqrt(eps(real(float(one(eltype(M))))))` is recommended.
1236
1236
1237
1237
For more information, see [^issue8859], [^B96], [^S84], [^KY88].
1238
1238
@@ -1262,7 +1262,7 @@ julia> M * N
1262
1262
1263
1263
[^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)
1264
1264
"""
1265
-
functionpinv(A::StridedMatrix{T}, tol::Real) where T
1265
+
functionpinv(A::StridedMatrix{T}, rtol::Real) where T
1266
1266
m, n =size(A)
1267
1267
Tout =typeof(zero(T)/sqrt(one(T) +one(T)))
1268
1268
if m ==0|| n ==0
@@ -1273,7 +1273,7 @@ function pinv(A::StridedMatrix{T}, tol::Real) where T
1273
1273
maxabsA =maximum(abs.(diag(A)))
1274
1274
B =zeros(Tout, n, m)
1275
1275
for i =1:min(m, n)
1276
-
ifabs(A[i,i]) >tol*maxabsA
1276
+
ifabs(A[i,i]) >rtol*maxabsA
1277
1277
Aii =inv(A[i,i])
1278
1278
ifisfinite(Aii)
1279
1279
B[i,i] = Aii
@@ -1286,14 +1286,14 @@ function pinv(A::StridedMatrix{T}, tol::Real) where T
1286
1286
SVD =svd(A, full =false)
1287
1287
Stype =eltype(SVD.S)
1288
1288
Sinv =zeros(Stype, length(SVD.S))
1289
-
index = SVD.S .>tol*maximum(SVD.S)
1289
+
index = SVD.S .>rtol*maximum(SVD.S)
1290
1290
Sinv[index] =one(Stype) ./ SVD.S[index]
1291
1291
Sinv[findall(.!isfinite.(Sinv))] .=zero(Stype)
1292
1292
return SVD.Vt'* (Diagonal(Sinv) * SVD.U')
1293
1293
end
1294
1294
functionpinv(A::StridedMatrix{T}) where T
1295
-
tol=eps(real(float(one(T))))*min(size(A)...)
1296
-
returnpinv(A, tol)
1295
+
rtol=eps(real(float(one(T))))*min(size(A)...)
1296
+
returnpinv(A, rtol)
1297
1297
end
1298
1298
functionpinv(x::Number)
1299
1299
xi =inv(x)
@@ -1303,12 +1303,12 @@ end
1303
1303
## Basis for null space
1304
1304
1305
1305
"""
1306
-
nullspace(M[, tol::Real])
1306
+
nullspace(M[, rtol::Real])
1307
1307
1308
1308
Computes a basis for the nullspace of `M` by including the singular
1309
-
vectors of A whose singular have magnitude are greater than `tol*σ₁`,
1309
+
vectors of A whose singular have magnitude are greater than `rtol*σ₁`,
1310
1310
where `σ₁` is `A`'s largest singular values. By default, the value of
1311
-
`tol` is the smallest dimension of `A` multiplied by the [`eps`](@ref)
1311
+
`rtol` is the smallest dimension of `A` multiplied by the [`eps`](@ref)
0 commit comments