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
5a2cfe7e
"...git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "e3ddbe25edeadaa5afc3f8f5bb0d645098a8b26a"
Commit
5a2cfe7e
authored
Jan 10, 2015
by
Davis King
Browse files
Added a test for compute_lda_transform()
parent
298d3a4a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
0 deletions
+54
-0
dlib/test/statistics.cpp
dlib/test/statistics.cpp
+54
-0
No files found.
dlib/test/statistics.cpp
View file @
5a2cfe7e
...
@@ -733,6 +733,59 @@ namespace
...
@@ -733,6 +733,59 @@ namespace
}
}
void
test_lda
()
{
// This test makes sure we pick the right direction in a simple 2D -> 1D LDA
typedef
matrix
<
double
,
2
,
1
>
sample_type
;
std
::
vector
<
unsigned
long
>
labels
;
std
::
vector
<
sample_type
>
samples
;
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
sample_type
s
;
s
(
0
)
=
i
;
s
(
1
)
=
i
+
1
;
samples
.
push_back
(
s
);
labels
.
push_back
(
1
);
sample_type
s1
;
s1
(
0
)
=
i
+
1
;
s1
(
1
)
=
i
;
samples
.
push_back
(
s1
);
labels
.
push_back
(
2
);
}
matrix
<
double
>
X
;
X
.
set_size
(
8
,
2
);
for
(
int
i
=
0
;
i
<
8
;
i
++
){
X
(
i
,
0
)
=
samples
[
i
](
0
);
X
(
i
,
1
)
=
samples
[
i
](
1
);
}
matrix
<
double
,
0
,
1
>
mean
;
dlib
::
compute_lda_transform
(
X
,
mean
,
labels
,
1
);
std
::
vector
<
double
>
vals1
,
vals2
;
for
(
unsigned
long
i
=
0
;
i
<
samples
.
size
();
++
i
)
{
double
val
=
X
*
samples
[
i
]
-
mean
;
if
(
i
%
2
==
0
)
vals1
.
push_back
(
val
);
else
vals2
.
push_back
(
val
);
dlog
<<
LINFO
<<
"1D LDA output: "
<<
val
;
}
if
(
vals1
[
0
]
>
vals2
[
0
])
swap
(
vals1
,
vals2
);
const
double
err
=
equal_error_rate
(
vals1
,
vals2
).
first
;
dlog
<<
LINFO
<<
"LDA ERR: "
<<
err
;
DLIB_TEST
(
err
==
0
);
DLIB_TEST
(
equal_error_rate
(
vals2
,
vals1
).
first
==
1
);
}
void
perform_test
(
void
perform_test
(
)
)
{
{
...
@@ -753,6 +806,7 @@ namespace
...
@@ -753,6 +806,7 @@ namespace
test_randomize_samples2
();
test_randomize_samples2
();
another_test
();
another_test
();
test_average_precision
();
test_average_precision
();
test_lda
();
}
}
}
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