Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
9427dd23
Commit
9427dd23
authored
Oct 02, 2013
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Just renamed some variables to avoid a name conflict with a #define in vistual studio.
parent
6d7f25bf
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
44 deletions
+44
-44
vector_normalizer_frobmetric.h
dlib/statistics/vector_normalizer_frobmetric.h
+0
-0
vector_normalizer_frobmetric_abstract.h
dlib/statistics/vector_normalizer_frobmetric_abstract.h
+24
-24
statistics.cpp
dlib/test/statistics.cpp
+20
-20
No files found.
dlib/statistics/vector_normalizer_frobmetric.h
View file @
9427dd23
This diff is collapsed.
Click to expand it.
dlib/statistics/vector_normalizer_frobmetric_abstract.h
View file @
9427dd23
...
@@ -19,20 +19,20 @@ namespace dlib
...
@@ -19,20 +19,20 @@ namespace dlib
WHAT THIS OBJECT REPRESENTS
WHAT THIS OBJECT REPRESENTS
This object represents a training data sample for the
This object represents a training data sample for the
vector_normalizer_frobmetric object. It defines a set of training triplets
vector_normalizer_frobmetric object. It defines a set of training triplets
relative to a single anchor
vector. That is, it specifies that the learned
relative to a single anchor
_vect vector. That is, it specifies that the
distance metric should satisfy num_triples() constraints which are, for all
learned distance metric should satisfy num_triples() constraints which are,
valid i and j:
for all
valid i and j:
length(T*anchor
-T*near[i]) + 1 < length(T*anchor - T*far
[j])
length(T*anchor
_vect-T*near_vects[i]) + 1 < length(T*anchor_vect - T*far_vects
[j])
for some appropriate linear transformation T which will be learned by
for some appropriate linear transformation T which will be learned by
vector_normalizer_frobmetric.
vector_normalizer_frobmetric.
!*/
!*/
matrix_type
anchor
;
matrix_type
anchor
_vect
;
std
::
vector
<
matrix_type
>
near
;
std
::
vector
<
matrix_type
>
near
_vects
;
std
::
vector
<
matrix_type
>
far
;
std
::
vector
<
matrix_type
>
far
_vects
;
unsigned
long
num_triples
(
unsigned
long
num_triples
(
)
const
{
return
near
.
size
()
*
far
.
size
();
}
)
const
{
return
near
_vects
.
size
()
*
far_vects
.
size
();
}
/*!
/*!
ensures
ensures
- returns the number of training triplets defined by this object.
- returns the number of training triplets defined by this object.
...
@@ -41,8 +41,8 @@ namespace dlib
...
@@ -41,8 +41,8 @@ namespace dlib
void
clear
()
void
clear
()
/*!
/*!
ensures
ensures
- #near.size() == 0
- #near
_vects
.size() == 0
- #far.size() == 0
- #far
_vects
.size() == 0
!*/
!*/
};
};
...
@@ -73,13 +73,13 @@ namespace dlib
...
@@ -73,13 +73,13 @@ namespace dlib
By Chunhua Shen, Junae Kim, Lei Wang, in CVPR 2011
By Chunhua Shen, Junae Kim, Lei Wang, in CVPR 2011
Therefore, this object is a tool that takes as input training triplets
Therefore, this object is a tool that takes as input training triplets
(anchor, near, far) of vectors and attempts to learn a linear
(anchor
_vect
, near, far) of vectors and attempts to learn a linear
transformation T such that:
transformation T such that:
length(T*anchor
-T*near) + 1 < length(T*anchor
- T*far)
length(T*anchor
_vect-T*near) + 1 < length(T*anchor_vect
- T*far)
That is, you give a bunch of anchor
vectors and for each anchor vector you
That is, you give a bunch of anchor
_vect vectors and for each anchor_vect
specify some vectors which should be near to it and some that should be far
you specify some vectors which should be near to it and some that should be
f
orm it. This object then tries to find a transformation matrix that makes
f
ar form it. This object then tries to find a transformation matrix that
the "near" vectors close to their anchors while the "far" vectors are
makes
the "near" vectors close to their anchors while the "far" vectors are
farther away.
farther away.
THREAD SAFETY
THREAD SAFETY
...
@@ -182,7 +182,7 @@ namespace dlib
...
@@ -182,7 +182,7 @@ namespace dlib
/*!
/*!
requires
requires
- samples.size() != 0
- samples.size() != 0
- All matrices inside samples (i.e. anchors and elements of near
and far
)
- All matrices inside samples (i.e. anchors and elements of near
_vects and far_vects
)
are column vectors with the same non-zero dimension.
are column vectors with the same non-zero dimension.
- All the vectors in samples contain finite values.
- All the vectors in samples contain finite values.
- All elements of samples contain data, specifically, for all valid i:
- All elements of samples contain data, specifically, for all valid i:
...
@@ -193,13 +193,13 @@ namespace dlib
...
@@ -193,13 +193,13 @@ namespace dlib
according to the learned distance metric. In particular, we will have:
according to the learned distance metric. In particular, we will have:
- #transform() == The linear transformation learned by the FrobMetric
- #transform() == The linear transformation learned by the FrobMetric
learning procedure.
learning procedure.
- #in_vector_size() == samples[0].anchor.size()
- #in_vector_size() == samples[0].anchor
_vect
.size()
- You can call (*this)(x) to transform a vector according to the learned
- You can call (*this)(x) to transform a vector according to the learned
distance metric. That is, it should generally be the case that:
distance metric. That is, it should generally be the case that:
- length((*this)(anchor
) - (*this)(near)) + 1 < length((*this)(anchor
) - (*this)(far))
- length((*this)(anchor
_vect) - (*this)(near)) + 1 < length((*this)(anchor_vect
) - (*this)(far))
for the anchor, near, and far vectors in the training data.
for the anchor
_vect
, near, and far vectors in the training data.
- #transformed_means() == the mean of the input anchor
vectors after being
- #transformed_means() == the mean of the input anchor
_vect vectors
transformed by #transform()
after being
transformed by #transform()
!*/
!*/
long
in_vector_size
(
long
in_vector_size
(
...
@@ -230,8 +230,8 @@ namespace dlib
...
@@ -230,8 +230,8 @@ namespace dlib
- V.size() == in_vector_size()
- V.size() == in_vector_size()
- V is a vector such that subtracting it from transformed vectors
- V is a vector such that subtracting it from transformed vectors
results in them having an expected value of 0. Therefore, it is
results in them having an expected value of 0. Therefore, it is
equal to transform() times the mean of the input anchor
vectors given
equal to transform() times the mean of the input anchor
_vect vectors
to train().
given
to train().
!*/
!*/
const
matrix
<
scalar_type
,
0
,
0
,
mem_manager_type
>&
transform
(
const
matrix
<
scalar_type
,
0
,
0
,
mem_manager_type
>&
transform
(
...
...
dlib/test/statistics.cpp
View file @
9427dd23
...
@@ -378,7 +378,7 @@ namespace
...
@@ -378,7 +378,7 @@ namespace
}
}
// check the unbiased skewness and excess kurtosis of one million Gaussian
// check the unbiased skewness and excess kurtosis of one million Gaussian
// draws are both near zero.
// draws are both near
_vects
zero.
DLIB_TEST
(
abs
(
rs1
.
skewness
())
<
0.1
);
DLIB_TEST
(
abs
(
rs1
.
skewness
())
<
0.1
);
DLIB_TEST
(
abs
(
rs1
.
ex_kurtosis
())
<
0.1
);
DLIB_TEST
(
abs
(
rs1
.
ex_kurtosis
())
<
0.1
);
}
}
...
@@ -582,12 +582,12 @@ namespace
...
@@ -582,12 +582,12 @@ namespace
running_stats
<
double
>
rs
;
running_stats
<
double
>
rs
;
for
(
unsigned
long
i
=
0
;
i
<
samples
.
size
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
samples
.
size
();
++
i
)
{
{
for
(
unsigned
long
j
=
0
;
j
<
samples
[
i
].
near
.
size
();
++
j
)
for
(
unsigned
long
j
=
0
;
j
<
samples
[
i
].
near
_vects
.
size
();
++
j
)
{
{
const
double
d1
=
length_squared
(
samples
[
i
].
anchor
-
samples
[
i
].
near
[
j
]);
const
double
d1
=
length_squared
(
samples
[
i
].
anchor
_vect
-
samples
[
i
].
near_vects
[
j
]);
for
(
unsigned
long
k
=
0
;
k
<
samples
[
i
].
far
.
size
();
++
k
)
for
(
unsigned
long
k
=
0
;
k
<
samples
[
i
].
far
_vects
.
size
();
++
k
)
{
{
const
double
d2
=
length_squared
(
samples
[
i
].
anchor
-
samples
[
i
].
far
[
k
]);
const
double
d2
=
length_squared
(
samples
[
i
].
anchor
_vect
-
samples
[
i
].
far_vects
[
k
]);
rs
.
add
(
d2
-
d1
);
rs
.
add
(
d2
-
d1
);
}
}
}
}
...
@@ -620,17 +620,17 @@ namespace
...
@@ -620,17 +620,17 @@ namespace
for
(
int
i
=
0
;
i
<
50
;
++
i
)
for
(
int
i
=
0
;
i
<
50
;
++
i
)
{
{
samp
.
clear
();
samp
.
clear
();
samp
.
anchor
=
gaussian_randm
(
dims
,
1
,
k
++
);
samp
.
anchor
_vect
=
gaussian_randm
(
dims
,
1
,
k
++
);
if
(
samp
.
anchor
(
key
)
>
0
)
if
(
samp
.
anchor
_vect
(
key
)
>
0
)
samp
.
anchor
(
key
)
=
rnd
.
get_random_double
()
+
5
;
samp
.
anchor
_vect
(
key
)
=
rnd
.
get_random_double
()
+
5
;
else
else
samp
.
anchor
(
key
)
=
-
(
rnd
.
get_random_double
()
+
5
);
samp
.
anchor
_vect
(
key
)
=
-
(
rnd
.
get_random_double
()
+
5
);
matrix
<
double
,
0
,
1
>
temp
;
matrix
<
double
,
0
,
1
>
temp
;
for
(
int
j
=
0
;
j
<
5
;
++
j
)
for
(
int
j
=
0
;
j
<
5
;
++
j
)
{
{
// Don't always put an equal number of near
and far
vectors into the
// Don't always put an equal number of near
_vects and far_vects
vectors into the
// training samples.
// training samples.
const
int
numa
=
rnd
.
get_random_32bit_number
()
%
2
+
1
;
const
int
numa
=
rnd
.
get_random_32bit_number
()
%
2
+
1
;
const
int
numb
=
rnd
.
get_random_32bit_number
()
%
2
+
1
;
const
int
numb
=
rnd
.
get_random_32bit_number
()
%
2
+
1
;
...
@@ -639,16 +639,16 @@ namespace
...
@@ -639,16 +639,16 @@ namespace
{
{
temp
=
gaussian_randm
(
dims
,
1
,
k
++
);
temp
(
key
)
=
0.1
;
temp
=
gaussian_randm
(
dims
,
1
,
k
++
);
temp
(
key
)
=
0.1
;
//temp = gaussian_randm(dims,1,k++); temp(key) = std::abs(temp(key));
//temp = gaussian_randm(dims,1,k++); temp(key) = std::abs(temp(key));
if
(
samp
.
anchor
(
key
)
>
0
)
samp
.
near
.
push_back
(
temp
);
if
(
samp
.
anchor
_vect
(
key
)
>
0
)
samp
.
near_vects
.
push_back
(
temp
);
else
samp
.
far
.
push_back
(
temp
);
else
samp
.
far
_vects
.
push_back
(
temp
);
}
}
for
(
int
num
=
0
;
num
<
numb
;
++
num
)
for
(
int
num
=
0
;
num
<
numb
;
++
num
)
{
{
temp
=
gaussian_randm
(
dims
,
1
,
k
++
);
temp
(
key
)
=
-
0.1
;
temp
=
gaussian_randm
(
dims
,
1
,
k
++
);
temp
(
key
)
=
-
0.1
;
//temp = gaussian_randm(dims,1,k++); temp(key) = -std::abs(temp(key));
//temp = gaussian_randm(dims,1,k++); temp(key) = -std::abs(temp(key));
if
(
samp
.
anchor
(
key
)
<
0
)
samp
.
near
.
push_back
(
temp
);
if
(
samp
.
anchor
_vect
(
key
)
<
0
)
samp
.
near_vects
.
push_back
(
temp
);
else
samp
.
far
.
push_back
(
temp
);
else
samp
.
far
_vects
.
push_back
(
temp
);
}
}
}
}
samples
.
push_back
(
samp
);
samples
.
push_back
(
samp
);
...
@@ -665,12 +665,12 @@ namespace
...
@@ -665,12 +665,12 @@ namespace
for
(
unsigned
long
i
=
0
;
i
<
samples
.
size
();
++
i
)
for
(
unsigned
long
i
=
0
;
i
<
samples
.
size
();
++
i
)
{
{
samples
[
i
].
anchor
=
normalizer
(
samples
[
i
].
anchor
);
samples
[
i
].
anchor
_vect
=
normalizer
(
samples
[
i
].
anchor_vect
);
total
+=
samples
[
i
].
anchor
;
total
+=
samples
[
i
].
anchor
_vect
;
for
(
unsigned
long
j
=
0
;
j
<
samples
[
i
].
near
.
size
();
++
j
)
for
(
unsigned
long
j
=
0
;
j
<
samples
[
i
].
near
_vects
.
size
();
++
j
)
samples
[
i
].
near
[
j
]
=
normalizer
(
samples
[
i
].
near
[
j
]);
samples
[
i
].
near
_vects
[
j
]
=
normalizer
(
samples
[
i
].
near_vects
[
j
]);
for
(
unsigned
long
j
=
0
;
j
<
samples
[
i
].
far
.
size
();
++
j
)
for
(
unsigned
long
j
=
0
;
j
<
samples
[
i
].
far
_vects
.
size
();
++
j
)
samples
[
i
].
far
[
j
]
=
normalizer
(
samples
[
i
].
far
[
j
]);
samples
[
i
].
far
_vects
[
j
]
=
normalizer
(
samples
[
i
].
far_vects
[
j
]);
}
}
total
/=
samples
.
size
();
total
/=
samples
.
size
();
dlog
<<
LINFO
<<
"sample transformed means: "
<<
trans
(
total
);
dlog
<<
LINFO
<<
"sample transformed means: "
<<
trans
(
total
);
...
...
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