Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
miscmaths
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSL
miscmaths
Commits
38884acf
Commit
38884acf
authored
19 years ago
by
Stephen Smith
Browse files
Options
Downloads
Patches
Plain Diff
added rpinv (right pseudoinverse)
parent
74b6f07d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
miscmaths.cc
+17
-0
17 additions, 0 deletions
miscmaths.cc
miscmaths.h
+1
-0
1 addition, 0 deletions
miscmaths.h
with
18 additions
and
0 deletions
miscmaths.cc
+
17
−
0
View file @
38884acf
...
...
@@ -519,6 +519,23 @@ namespace MISCMATHS {
return
pinv
;
}
ReturnMatrix
rpinv
(
const
Matrix
&
mat
)
// note that mat must be a fat matrix (e.g. x.t() )
{
// calculates the right psuedo-inverse using SVD
Tracer
tr
(
"rpinv"
);
DiagonalMatrix
D
;
Matrix
U
,
V
;
SVD
(
mat
.
t
(),
D
,
U
,
V
);
// feed transpose of input into SVD
float
tol
;
tol
=
MaximumAbsoluteValue
(
D
)
*
Max
(
mat
.
Nrows
(),
mat
.
Ncols
())
*
1e-16
;
for
(
int
n
=
1
;
n
<=
D
.
Nrows
();
n
++
)
{
if
(
fabs
(
D
(
n
,
n
))
>
tol
)
D
(
n
,
n
)
=
1.0
/
D
(
n
,
n
);
}
Matrix
rpinv
=
U
*
D
*
V
.
t
();
rpinv
.
Release
();
return
rpinv
;
}
int
rank
(
const
Matrix
&
X
)
{
// calculates the rank of matrix X
...
...
This diff is collapsed.
Click to expand it.
miscmaths.h
+
1
−
0
View file @
38884acf
...
...
@@ -120,6 +120,7 @@ namespace MISCMATHS {
int
diag
(
DiagonalMatrix
&
m
,
const
ColumnVector
&
diagvals
);
ReturnMatrix
diag
(
const
Matrix
&
mat
);
ReturnMatrix
pinv
(
const
Matrix
&
mat
);
ReturnMatrix
rpinv
(
const
Matrix
&
mat
);
int
rank
(
const
Matrix
&
X
);
ReturnMatrix
sqrtaff
(
const
Matrix
&
mat
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment