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
ec6be63e
Commit
ec6be63e
authored
Jun 15, 2013
by
Davis King
Browse files
Added tests and slight refinements
parent
a0797fd1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
1 deletion
+44
-1
dlib/statistics/statistics.h
dlib/statistics/statistics.h
+3
-1
dlib/statistics/statistics_abstract.h
dlib/statistics/statistics_abstract.h
+2
-0
dlib/test/statistics.cpp
dlib/test/statistics.cpp
+39
-0
No files found.
dlib/statistics/statistics.h
View file @
ec6be63e
...
@@ -824,7 +824,9 @@ namespace dlib
...
@@ -824,7 +824,9 @@ namespace dlib
{
{
// make sure requires clause is not broken
// make sure requires clause is not broken
DLIB_ASSERT
(
is_col_vector
(
x
)
&&
(
x_vector_size
()
==
0
||
x
.
size
()
==
x_vector_size
())
&&
DLIB_ASSERT
(
is_col_vector
(
x
)
&&
(
x_vector_size
()
==
0
||
x
.
size
()
==
x_vector_size
())
&&
is_col_vector
(
y
)
&&
(
y_vector_size
()
==
0
||
y
.
size
()
==
y_vector_size
()),
is_col_vector
(
y
)
&&
(
y_vector_size
()
==
0
||
y
.
size
()
==
y_vector_size
())
&&
x
.
size
()
!=
0
&&
y
.
size
()
!=
0
,
"
\t
void running_cross_covariance::add()"
"
\t
void running_cross_covariance::add()"
<<
"
\n\t
Invalid inputs were given to this function"
<<
"
\n\t
Invalid inputs were given to this function"
<<
"
\n\t
is_col_vector(x): "
<<
is_col_vector
(
x
)
<<
"
\n\t
is_col_vector(x): "
<<
is_col_vector
(
x
)
...
...
dlib/statistics/statistics_abstract.h
View file @
ec6be63e
...
@@ -602,6 +602,8 @@ namespace dlib
...
@@ -602,6 +602,8 @@ namespace dlib
requires
requires
- is_col_vector(x) == true
- is_col_vector(x) == true
- is_col_vector(y) == true
- is_col_vector(y) == true
- x.size() != 0
- y.size() != 0
- if (x_vector_size() != 0) then
- if (x_vector_size() != 0) then
- x.size() == x_vector_size()
- x.size() == x_vector_size()
- if (y_vector_size() != 0) then
- if (y_vector_size() != 0) then
...
...
dlib/test/statistics.cpp
View file @
ec6be63e
...
@@ -133,6 +133,44 @@ namespace
...
@@ -133,6 +133,44 @@ namespace
}
}
}
}
void
test_running_cross_covariance
()
{
running_cross_covariance
<
matrix
<
double
>
>
rcc1
,
rcc2
;
matrix
<
double
,
0
,
1
>
xm
,
ym
;
const
int
num
=
40
;
dlib
::
rand
rnd
;
for
(
int
i
=
0
;
i
<
num
;
++
i
)
{
matrix
<
double
,
0
,
1
>
x
=
randm
(
4
,
1
,
rnd
);
matrix
<
double
,
0
,
1
>
y
=
randm
(
4
,
1
,
rnd
);
xm
+=
x
/
num
;
ym
+=
y
/
num
;
if
(
i
<
15
)
rcc1
.
add
(
x
,
y
);
else
rcc2
.
add
(
x
,
y
);
}
rnd
.
clear
();
matrix
<
double
>
cov
;
for
(
int
i
=
0
;
i
<
num
;
++
i
)
{
matrix
<
double
,
0
,
1
>
x
=
randm
(
4
,
1
,
rnd
);
matrix
<
double
,
0
,
1
>
y
=
randm
(
4
,
1
,
rnd
);
cov
+=
(
x
-
xm
)
*
trans
(
y
-
ym
);
}
cov
/=
num
-
1
;
running_cross_covariance
<
matrix
<
double
>
>
rcc
=
rcc1
+
rcc2
;
DLIB_TEST
(
max
(
abs
(
rcc
.
covariance_xy
()
-
cov
))
<
1e-14
);
DLIB_TEST
(
max
(
abs
(
rcc
.
mean_x
()
-
xm
))
<
1e-14
);
DLIB_TEST
(
max
(
abs
(
rcc
.
mean_y
()
-
ym
))
<
1e-14
);
}
void
test_running_covariance
(
void
test_running_covariance
(
)
)
{
{
...
@@ -459,6 +497,7 @@ namespace
...
@@ -459,6 +497,7 @@ namespace
test_random_subset_selector
();
test_random_subset_selector
();
test_random_subset_selector2
();
test_random_subset_selector2
();
test_running_covariance
();
test_running_covariance
();
test_running_cross_covariance
();
test_running_stats
();
test_running_stats
();
test_skewness_and_kurtosis_1
();
test_skewness_and_kurtosis_1
();
test_skewness_and_kurtosis_2
();
test_skewness_and_kurtosis_2
();
...
...
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