Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RobotAPI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software
ArmarX
RobotAPI
Commits
7c8cd718
Commit
7c8cd718
authored
1 year ago
by
Joana Plewnia
Browse files
Options
Downloads
Patches
Plain Diff
added cosine classes for aron/similarity
parent
1e2656f8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!322
Feature/forgetting in wm and em
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
source/RobotAPI/libraries/aron/similarity/cosine.cpp
+72
-0
72 additions, 0 deletions
source/RobotAPI/libraries/aron/similarity/cosine.cpp
source/RobotAPI/libraries/aron/similarity/cosine.h
+13
-0
13 additions, 0 deletions
source/RobotAPI/libraries/aron/similarity/cosine.h
with
85 additions
and
0 deletions
source/RobotAPI/libraries/aron/similarity/cosine.cpp
0 → 100644
+
72
−
0
View file @
7c8cd718
#include
"cosine.h"
#include
<SimoxUtility/algorithm/string.h>
#include
<cmath>
namespace
armarx
::
aron
::
similarity
{
double
cosine
::
compute_similarity
(
const
aron
::
data
::
NDArrayPtr
p1
,
const
aron
::
data
::
NDArrayPtr
p2
)
{
//this does only work for RGB images not RGBDepth at the moment!
int
width
=
p1
->
getShape
().
at
(
0
);
int
height
=
p1
->
getShape
().
at
(
1
);
int
dimensions
=
p1
->
getShape
().
at
(
2
);
ARMARX_CHECK
(
dimensions
==
p2
->
getShape
().
at
(
2
));
if
(
dimensions
>
3
){
ARMARX_INFO
<<
"Trying to calculate cosine similarity for more than 3 channels, only first three channels will be looked at"
;
}
Eigen
::
MatrixXf
m1r
(
width
,
height
);
Eigen
::
MatrixXf
m2r
(
width
,
height
);
Eigen
::
MatrixXf
m1g
(
width
,
height
);
Eigen
::
MatrixXf
m2g
(
width
,
height
);
Eigen
::
MatrixXf
m1b
(
width
,
height
);
Eigen
::
MatrixXf
m2b
(
width
,
height
);
auto
image1
=
p1
->
getDataAsVector
();
auto
image2
=
p2
->
getDataAsVector
();
for
(
int
x
=
0
;
x
<
width
;
x
++
){
for
(
int
y
=
0
;
y
<
height
;
y
++
){
//R-value matices:
int
index
=
x
+
width
*
(
y
+
0
*
height
);
double
element1
=
image1
.
at
(
index
);
double
element2
=
image2
.
at
(
index
);
m1r
(
x
,
y
)
=
element1
;
m2r
(
x
,
y
)
=
element2
;
//G-value matices:
index
=
x
+
width
*
(
y
+
1
*
height
);
element1
=
image1
.
at
(
index
);
element2
=
image2
.
at
(
index
);
m1g
(
x
,
y
)
=
element1
;
m2g
(
x
,
y
)
=
element2
;
//B-value matices:
index
=
x
+
width
*
(
y
+
2
*
height
);
element1
=
image1
.
at
(
index
);
element2
=
image2
.
at
(
index
);
m1b
(
x
,
y
)
=
element1
;
m2b
(
x
,
y
)
=
element2
;
}
}
double
dotProductR
=
(
m1r
.
array
()
*
m2r
.
array
()).
sum
();
double
normProductR
=
m1r
.
norm
()
*
m2r
.
norm
();
double
cosineR
=
1.0
-
(
dotProductR
/
normProductR
);
//ARMARX_INFO << VAROUT(cosineR);
double
dotProductG
=
(
m1g
.
array
()
*
m2g
.
array
()).
sum
();
double
normProductG
=
m1g
.
norm
()
*
m2g
.
norm
();
double
cosineG
=
1.0
-
(
dotProductG
/
normProductG
);
//ARMARX_INFO << VAROUT(cosineG);
double
dotProductB
=
(
m1b
.
array
()
*
m2b
.
array
()).
sum
();
double
normProductB
=
m1b
.
norm
()
*
m2b
.
norm
();
double
cosineB
=
1.0
-
(
dotProductB
/
normProductB
);
//ARMARX_INFO << VAROUT(cosineB);
return
(
cosineR
+
cosineG
+
cosineB
)
/
3
;
}
}
This diff is collapsed.
Click to expand it.
source/RobotAPI/libraries/aron/similarity/cosine.h
0 → 100644
+
13
−
0
View file @
7c8cd718
#pragma once
#include
<algorithm>
#include
<map>
#include
<vector>
#include
<RobotAPI/libraries/aron/core/data/variant/All.h>
namespace
armarx
::
aron
::
similarity
::
cosine
{
double
compute_similarity
(
const
aron
::
data
::
NDArrayPtr
p1
,
const
aron
::
data
::
NDArrayPtr
p2
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment