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
7f600c40
Commit
7f600c40
authored
Jan 14, 2015
by
Davis King
Browse files
merged
parents
47ed6f22
5a2cfe7e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
55 additions
and
1 deletion
+55
-1
dlib/statistics/lda.h
dlib/statistics/lda.h
+1
-1
dlib/test/statistics.cpp
dlib/test/statistics.cpp
+54
-0
No files found.
dlib/statistics/lda.h
View file @
7f600c40
...
...
@@ -120,7 +120,7 @@ namespace dlib
matrix
<
T
,
0
,
1
>
W
;
svd3
(
Sw
,
A
,
W
,
H
);
W
=
sqrt
(
W
);
W
=
reciprocal
(
round_zeros
(
W
,
max
(
W
)
*
1e-5
));
W
=
reciprocal
(
lowerbound
(
W
,
max
(
W
)
*
1e-5
));
A
=
trans
(
H
*
diagm
(
W
))
*
Sb
*
H
*
diagm
(
W
);
matrix
<
T
>
v
,
s
,
u
;
svd3
(
A
,
v
,
s
,
u
);
...
...
dlib/test/statistics.cpp
View file @
7f600c40
...
...
@@ -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
(
)
{
...
...
@@ -753,6 +806,7 @@ namespace
test_randomize_samples2
();
another_test
();
test_average_precision
();
test_lda
();
}
}
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