Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
autosimilarity_segmentation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MARMORET Axel
autosimilarity_segmentation
Commits
49df6802
Commit
49df6802
authored
May 6, 2024
by
MARMORET Axel
Browse files
Options
Downloads
Patches
Plain Diff
From covariance to autocorrelation (TISMIR publication)
parent
7d3077ca
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
as_seg/autosimilarity_computation.py
+253
-245
253 additions, 245 deletions
as_seg/autosimilarity_computation.py
with
253 additions
and
245 deletions
as_seg/autosimilarity_computation.py
+
253
−
245
View file @
49df6802
...
...
@@ -11,6 +11,7 @@ import as_seg.model.errors as err
import
numpy
as
np
import
sklearn.metrics.pairwise
as
pairwise_distances
import
warnings
eps
=
1e-10
def
switch_autosimilarity
(
an_array
,
similarity_type
,
gamma
=
None
,
normalise
=
True
):
"""
...
...
@@ -59,8 +60,8 @@ def switch_autosimilarity(an_array, similarity_type, gamma = None, normalise = T
"""
if
similarity_type
.
lower
()
==
"
cosine
"
:
return
get_cosine_autosimilarity
(
an_array
)
#, normalise = normalise)
elif
similarity_type
.
lower
()
==
"
covariance
"
:
return
get_
covariance
_autosimilarity
(
an_array
,
normalise
=
normalise
)
elif
similarity_type
.
lower
()
==
"
autocorrelation
"
or
similarity_type
.
lower
()
==
"
covariance
"
:
return
get_
autocorrelation
_autosimilarity
(
an_array
,
normalise
=
normalise
)
elif
similarity_type
.
lower
()
==
"
rbf
"
:
return
get_rbf_autosimilarity
(
an_array
,
gamma
,
normalise
=
normalise
)
elif
similarity_type
.
lower
()
==
"
centered_rbf
"
:
...
...
@@ -85,11 +86,12 @@ def l2_normalise_barwise(an_array):
The normalised array.
"""
with
warnings
.
catch_warnings
():
warnings
.
filterwarnings
(
"
ignore
"
,
message
=
"
invalid value encountered in true_divide
"
)
# Avoiding to show the warning, as it's handled, not te confuse the user.
an_array_T
=
an_array
.
T
/
np
.
linalg
.
norm
(
an_array
,
axis
=
1
)
an_array_T
=
np
.
where
(
np
.
isnan
(
an_array_T
),
1e-10
,
an_array_T
)
# Replace null lines, avoiding future errors in handling values.
return
an_array_T
.
T
norm
=
np
.
linalg
.
norm
(
an_array
,
axis
=
1
)
an_array_T
=
np
.
transpose
(
an_array
)
out
=
np
.
inf
*
np
.
ones_like
(
an_array_T
)
np
.
divide
(
an_array_T
,
norm
,
out
=
out
,
where
=
norm
!=
0
)
an_array_T
=
np
.
where
(
np
.
isinf
(
out
),
eps
,
out
)
return
np
.
transpose
(
an_array_T
)
def
get_cosine_autosimilarity
(
an_array
):
#, normalise = True):
"""
...
...
@@ -121,9 +123,15 @@ def get_cosine_autosimilarity(an_array):#, normalise = True):
def
get_covariance_autosimilarity
(
an_array
,
normalise
=
True
):
"""
Computes the autosimilarity matrix, where the similarity function is the covariance.
Note: deprecated. The name of the matrix became
"
Autocorrelation
"
in the TISMIR version of the paper.
"""
return
get_autocorrelation_autosimilarity
(
an_array
,
normalise
=
normalise
)
def
get_autocorrelation_autosimilarity
(
an_array
,
normalise
=
True
):
"""
Computes the autosimilarity matrix, where the similarity function is the autocorrelation.
The
covariance
similarity function corresponds to the dot product of centered features:
The
autocorrelation
similarity function corresponds to the dot product of centered features:
.. math::
s_{x_i,x_j} = \langle x_i - \hat{x}, x_j - \hat{x}
\r
angle
...
...
@@ -139,7 +147,7 @@ def get_covariance_autosimilarity(an_array, normalise = True):
Returns
-------
numpy array
The
covariance
autosimilarity of this array.
The
autocorrelation
autosimilarity of this array.
"""
if
type
(
an_array
)
is
list
:
...
...
...
...
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
sign in
to comment