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
55862aa0
Commit
55862aa0
authored
18 years ago
by
Saad Jbabdi
Browse files
Options
Downloads
Patches
Plain Diff
added a permutation function
parent
37678373
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
miscprob.cc
+29
-0
29 additions, 0 deletions
miscprob.cc
miscprob.h
+3
-0
3 additions, 0 deletions
miscprob.h
with
32 additions
and
0 deletions
miscprob.cc
+
29
−
0
View file @
55862aa0
...
...
@@ -145,4 +145,33 @@ ReturnMatrix mvnrnd(const RowVector& mu, const SymmetricMatrix& covar, int nsamp
return
mvn
.
next
(
nsamp
);
}
ReturnMatrix
perms
(
const
int
n
){
if
(
n
<=
1
){
Matrix
P
(
1
,
1
);
P
<<
n
;
P
.
Release
();
return
P
;
}
Matrix
Q
=
perms
(
n
-
1
);
// recursive calls
int
m
=
Q
.
Nrows
();
Matrix
P
(
n
*
m
,
n
);
for
(
int
i
=
1
;
i
<=
m
;
i
++
){
P
(
i
,
1
)
=
n
;
for
(
int
j
=
1
;
j
<=
Q
.
Ncols
();
j
++
)
P
(
i
,
j
+
1
)
=
Q
(
i
,
j
);
}
for
(
int
i
=
n
-
1
;
i
>=
1
;
i
--
){
int
jj
=
1
;
for
(
int
j
=
(
n
-
i
)
*
m
+
1
;
j
<=
(
n
-
i
+
1
)
*
m
;
j
++
){
P
(
j
,
1
)
=
i
;
for
(
int
k
=
1
;
k
<=
n
-
1
;
k
++
){
P
(
j
,
k
+
1
)
=
(
Q
(
jj
,
k
)
==
i
)
?
n
:
Q
(
jj
,
k
);
}
jj
++
;
}
}
P
.
Release
();
return
P
;
}
}
This diff is collapsed.
Click to expand it.
miscprob.h
+
3
−
0
View file @
55862aa0
...
...
@@ -41,6 +41,9 @@ namespace MISCMATHS {
ReturnMatrix
gammacdf
(
const
RowVector
&
vals
,
const
float
mu
=
0
,
const
float
var
=
1
);
// returns n! * n matrix of all possible permutations
ReturnMatrix
perms
(
const
int
n
);
class
Mvnormrandm
{
...
...
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