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
fb5779b2
Commit
fb5779b2
authored
17 years ago
by
Saad Jbabdi
Browse files
Options
Downloads
Patches
Plain Diff
added sampling from a distribution given a histogram
parent
239af29f
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
miscprob.cc
+20
-0
20 additions, 0 deletions
miscprob.cc
miscprob.h
+2
-0
2 additions, 0 deletions
miscprob.h
with
22 additions
and
0 deletions
miscprob.cc
+
20
−
0
View file @
fb5779b2
...
...
@@ -36,6 +36,26 @@ ReturnMatrix unifrnd(const int dim1, const int dim2, const float start, const fl
return
res
;
}
// SJ. Generates a sample from a distribution given the histogram
int
distribrnd
(
const
ColumnVector
&
histo
){
int
res
=
1
;
ColumnVector
cumsum
(
histo
.
Nrows
());
float
sum
=
0.0
;
for
(
int
k
=
1
;
k
<=
histo
.
Nrows
();
k
++
){
sum
+=
histo
(
k
);
cumsum
(
k
)
=
sum
;
}
float
U
=
rand
()
/
float
(
RAND_MAX
);
U
*=
sum
;
for
(
int
k
=
1
;
k
<=
histo
.
Nrows
();
k
++
){
if
(
U
<
cumsum
(
k
)){
res
=
k
;
break
;
}
}
return
res
;
}
ReturnMatrix
normrnd
(
const
int
dim1
,
const
int
dim2
,
const
float
mu
,
const
float
sigma
)
{
int
tdim
=
dim2
;
...
...
This diff is collapsed.
Click to expand it.
miscprob.h
+
2
−
0
View file @
fb5779b2
...
...
@@ -23,6 +23,8 @@ namespace MISCMATHS {
ReturnMatrix
unifrnd
(
const
int
dim1
=
1
,
const
int
dim2
=
-
1
,
const
float
start
=
0
,
const
float
end
=
1
);
int
distribrnd
(
const
ColumnVector
&
histo
);
ReturnMatrix
normrnd
(
const
int
dim1
=
1
,
const
int
dim2
=
-
1
,
const
float
mu
=
0
,
const
float
sigma
=
1
);
...
...
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