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
dc9527be
Commit
dc9527be
authored
Jan 27, 2013
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added cosine_distance.
parent
b5f77a0c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
0 deletions
+51
-0
function_objects.h
dlib/graph_utils/function_objects.h
+19
-0
function_objects_abstract.h
dlib/graph_utils/function_objects_abstract.h
+32
-0
No files found.
dlib/graph_utils/function_objects.h
View file @
dc9527be
...
...
@@ -5,6 +5,7 @@
#include "function_objects_abstract.h"
#include "../matrix.h"
#include "../svm/sparse_vector.h"
#include <cmath>
#include <limits>
...
...
@@ -46,6 +47,24 @@ namespace dlib
}
};
// ----------------------------------------------------------------------------------------
struct
cosine_distance
{
template
<
typename
sample_type
>
double
operator
()
(
const
sample_type
&
a
,
const
sample_type
&
b
)
const
{
const
double
temp
=
length
(
a
)
*
length
(
b
);
if
(
temp
==
0
)
return
0
;
else
return
1
-
dot
(
a
,
b
)
/
temp
;
}
};
// ----------------------------------------------------------------------------------------
struct
use_weights_of_one
...
...
dlib/graph_utils/function_objects_abstract.h
View file @
dc9527be
...
...
@@ -5,6 +5,7 @@
#include "../matrix.h"
#include <cmath>
#include "../svm/sparse_vector_abstract.h"
namespace
dlib
{
...
...
@@ -57,6 +58,37 @@ namespace dlib
!*/
};
// ----------------------------------------------------------------------------------------
struct
cosine_distance
{
/*!
WHAT THIS OBJECT REPRESENTS
This is a simple function object that the cosine of the angle between
two vectors and returns 1 - this quantity. Moreover, this object
works for both sparse and dense vectors.
!*/
template
<
typename
sample_type
>
double
operator
()
(
const
sample_type
&
a
,
const
sample_type
&
b
)
const
;
/*!
requires
- sample_type is a dense vector (e.g. a dlib::matrix) or a sparse
vector as defined at the top of dlib/svm/sparse_vector_abstract.h
ensures
- let theta = the angle between a and b.
- returns 1 - cos(theta)
(e.g. this function returns 0 when a and b have an angle of 0 between
each other, 1 if they have a 90 degree angle, and a maximum of 2 if the
vectors have a 180 degree angle between each other).
- zero length vectors are considered to have angles of 0 between all other
vectors.
!*/
};
// ----------------------------------------------------------------------------------------
struct
use_weights_of_one
...
...
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