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
b9149a5e
Commit
b9149a5e
authored
Nov 06, 2011
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added the histogram intersection kernel for sparse and dense vectors.
parent
85db4e4e
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
248 additions
and
8 deletions
+248
-8
kernel.h
dlib/svm/kernel.h
+46
-0
kernel_abstract.h
dlib/svm/kernel_abstract.h
+65
-0
sparse_kernel.h
dlib/svm/sparse_kernel.h
+63
-0
sparse_kernel_abstract.h
dlib/svm/sparse_kernel_abstract.h
+74
-8
No files found.
dlib/svm/kernel.h
View file @
b9149a5e
...
...
@@ -400,6 +400,52 @@ namespace dlib
const
linear_kernel
<
T
>&
k
;
};
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
struct
histogram_intersection_kernel
{
typedef
typename
T
::
type
scalar_type
;
typedef
T
sample_type
;
typedef
typename
T
::
mem_manager_type
mem_manager_type
;
scalar_type
operator
()
(
const
sample_type
&
a
,
const
sample_type
&
b
)
const
{
scalar_type
temp
=
0
;
for
(
long
i
=
0
;
i
<
a
.
size
();
++
i
)
{
temp
+=
std
::
min
(
a
(
i
),
b
(
i
));
}
return
temp
;
}
bool
operator
==
(
const
histogram_intersection_kernel
&
)
const
{
return
true
;
}
};
template
<
typename
T
>
void
serialize
(
const
histogram_intersection_kernel
<
T
>&
,
std
::
ostream
&
){}
template
<
typename
T
>
void
deserialize
(
histogram_intersection_kernel
<
T
>&
,
std
::
istream
&
){}
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
...
...
dlib/svm/kernel_abstract.h
View file @
b9149a5e
...
...
@@ -422,6 +422,71 @@ namespace dlib
provides deserialization support for linear_kernel
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
struct
histogram_intersection_kernel
{
/*!
REQUIREMENTS ON T
T must be a dlib::matrix object
WHAT THIS OBJECT REPRESENTS
This object represents a histogram intersection kernel kernel
!*/
typedef
typename
T
::
type
scalar_type
;
typedef
T
sample_type
;
typedef
typename
T
::
mem_manager_type
mem_manager_type
;
scalar_type
operator
()
(
const
sample_type
&
a
,
const
sample_type
&
b
)
const
;
/*!
requires
- is_vector(a)
- is_vector(b)
- a.size() == b.size()
- min(a) >= 0
- min(b) >= 0
ensures
- returns sum over all i: std::min(a(i), b(i))
!*/
bool
operator
==
(
const
histogram_intersection_kernel
&
k
)
const
;
/*!
ensures
- returns true
!*/
};
template
<
typename
T
>
void
serialize
(
const
histogram_intersection_kernel
<
T
>&
item
,
std
::
ostream
&
out
);
/*!
provides serialization support for histogram_intersection_kernel
!*/
template
<
typename
T
>
void
deserialize
(
histogram_intersection_kernel
<
T
>&
item
,
std
::
istream
&
in
);
/*!
provides deserialization support for histogram_intersection_kernel
!*/
// ----------------------------------------------------------------------------------------
template
<
...
...
dlib/svm/sparse_kernel.h
View file @
b9149a5e
...
...
@@ -311,6 +311,69 @@ namespace dlib
std
::
istream
&
in
){}
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
struct
sparse_histogram_intersection_kernel
{
typedef
typename
T
::
value_type
::
second_type
scalar_type
;
typedef
T
sample_type
;
typedef
default_memory_manager
mem_manager_type
;
scalar_type
operator
()
(
const
sample_type
&
a
,
const
sample_type
&
b
)
const
{
typename
sample_type
::
const_iterator
ai
=
a
.
begin
();
typename
sample_type
::
const_iterator
bi
=
b
.
begin
();
scalar_type
sum
=
0
;
while
(
ai
!=
a
.
end
()
&&
bi
!=
b
.
end
())
{
if
(
ai
->
first
==
bi
->
first
)
{
sum
+=
std
::
min
(
ai
->
second
,
bi
->
second
);
++
ai
;
++
bi
;
}
else
if
(
ai
->
first
<
bi
->
first
)
{
++
ai
;
}
else
{
++
bi
;
}
}
return
sum
;
}
bool
operator
==
(
const
sparse_histogram_intersection_kernel
&
)
const
{
return
true
;
}
};
template
<
typename
T
>
void
serialize
(
const
sparse_histogram_intersection_kernel
<
T
>&
item
,
std
::
ostream
&
out
){}
template
<
typename
T
>
void
deserialize
(
sparse_histogram_intersection_kernel
<
T
>&
item
,
std
::
istream
&
in
){}
// ----------------------------------------------------------------------------------------
}
...
...
dlib/svm/sparse_kernel_abstract.h
View file @
b9149a5e
...
...
@@ -64,8 +64,8 @@ namespace dlib
)
const
;
/*!
requires
- a
contains a sorted range
- b
contains a sorted range
- a
is a sparse vector
- b
is a sparse vector
ensures
- returns exp(-gamma * sparse_vector::distance_squared(a,b))
!*/
...
...
@@ -170,8 +170,8 @@ namespace dlib
)
const
;
/*!
requires
- a
contains a sorted range
- b
contains a sorted range
- a
is a sparse vector
- b
is a sparse vector
ensures
- returns tanh(gamma * sparse_vector::dot(a,b) + coef)
!*/
...
...
@@ -282,8 +282,8 @@ namespace dlib
)
const
;
/*!
requires
- a
contains a sorted range
- b
contains a sorted range
- a
is a sparse vector
- b
is a sparse vector
ensures
- returns pow(gamma * sparse_vector::dot(a,b) + coef, degree)
!*/
...
...
@@ -359,8 +359,8 @@ namespace dlib
)
const
;
/*!
requires
- a
contains a sorted range
- b
contains a sorted range
- a
is a sparse vector
- b
is a sparse vector
ensures
- returns sparse_vector::dot(a,b)
!*/
...
...
@@ -396,6 +396,72 @@ namespace dlib
provides deserialization support for sparse_linear_kernel
!*/
// ----------------------------------------------------------------------------------------
template
<
typename
T
>
struct
sparse_histogram_intersection_kernel
{
/*!
REQUIREMENTS ON T
Must be a sparse vector as defined in dlib/svm/sparse_vector_abstract.h
WHAT THIS OBJECT REPRESENTS
This object represents a histogram intersection kernel
that works with sparse vectors.
!*/
typedef
typename
T
::
value_type
::
second_type
scalar_type
;
typedef
T
sample_type
;
typedef
default_memory_manager
mem_manager_type
;
scalar_type
operator
()
(
const
sample_type
&
a
,
const
sample_type
&
b
)
const
;
/*!
requires
- a is a sparse vector
- b is a sparse vector
- all the values in a and b are >= 0
ensures
- Let A(i) denote the value of the ith dimension of the a vector.
- Let B(i) denote the value of the ith dimension of the b vector.
- returns sum over all i: std::min(A(i), B(i))
!*/
bool
operator
==
(
const
sparse_histogram_intersection_kernel
&
k
)
const
;
/*!
ensures
- returns true
!*/
};
template
<
typename
T
>
void
serialize
(
const
sparse_histogram_intersection_kernel
<
T
>&
item
,
std
::
ostream
&
out
);
/*!
provides serialization support for sparse_histogram_intersection_kernel
!*/
template
<
typename
T
>
void
deserialize
(
sparse_histogram_intersection_kernel
<
T
>&
item
,
std
::
istream
&
in
);
/*!
provides deserialization support for sparse_histogram_intersection_kernel
!*/
// ----------------------------------------------------------------------------------------
}
...
...
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