Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
d6012c41
Commit
d6012c41
authored
Dec 18, 2011
by
Davis King
Browse files
Added some simple normality tests for the new rand::get_random_gaussian() method.
parent
b436d840
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
0 deletions
+46
-0
dlib/test/rand.cpp
dlib/test/rand.cpp
+46
-0
No files found.
dlib/test/rand.cpp
View file @
d6012c41
...
@@ -200,6 +200,49 @@ namespace
...
@@ -200,6 +200,49 @@ namespace
}
}
template
<
typename
rand_type
>
void
test_normal_numbers
(
rand_type
&
rnd
)
{
dlog
<<
LINFO
<<
"test normality"
;
double
cnt1
=
0
;
// num <= -1.2
double
cnt2
=
0
;
// num <= -0.5
double
cnt3
=
0
;
// num <= 0
double
cnt4
=
0
;
// num <= 0.5
double
cnt5
=
0
;
// num <= 1.2
const
unsigned
long
total
=
1000000
;
for
(
unsigned
long
i
=
0
;
i
<
total
;
++
i
)
{
const
double
r
=
rnd
.
get_random_gaussian
();
if
(
r
<=
-
1.2
)
cnt1
+=
1
;
if
(
r
<=
-
0.5
)
cnt2
+=
1
;
if
(
r
<=
0
)
cnt3
+=
1
;
if
(
r
<=
0.5
)
cnt4
+=
1
;
if
(
r
<=
1.2
)
cnt5
+=
1
;
}
cnt1
/=
total
;
cnt2
/=
total
;
cnt3
/=
total
;
cnt4
/=
total
;
cnt5
/=
total
;
dlog
<<
LINFO
<<
"cnt1: "
<<
cnt1
;
dlog
<<
LINFO
<<
"cnt2: "
<<
cnt2
;
dlog
<<
LINFO
<<
"cnt3: "
<<
cnt3
;
dlog
<<
LINFO
<<
"cnt4: "
<<
cnt4
;
dlog
<<
LINFO
<<
"cnt5: "
<<
cnt5
;
DLIB_TEST
(
std
::
abs
(
cnt1
-
0.11507
)
<
0.001
);
DLIB_TEST
(
std
::
abs
(
cnt2
-
0.30854
)
<
0.001
);
DLIB_TEST
(
std
::
abs
(
cnt3
-
0.5
)
<
0.001
);
DLIB_TEST
(
std
::
abs
(
cnt4
-
0.69146
)
<
0.001
);
DLIB_TEST
(
std
::
abs
(
cnt5
-
0.88493
)
<
0.001
);
}
...
@@ -219,6 +262,9 @@ namespace
...
@@ -219,6 +262,9 @@ namespace
dlog
<<
LINFO
<<
"testing kernel_1a"
;
dlog
<<
LINFO
<<
"testing kernel_1a"
;
rand_test
<
dlib
::
rand
>
();
rand_test
<
dlib
::
rand
>
();
rand_test
<
dlib
::
rand
>
();
rand_test
<
dlib
::
rand
>
();
dlib
::
rand
rnd
;
test_normal_numbers
(
rnd
);
}
}
}
a
;
}
a
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment