Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tuhlbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
User expired
tuhlbox
Commits
978fa7bd
Commit
978fa7bd
authored
3 years ago
by
Benjamin Murauer
Browse files
Options
Downloads
Patches
Plain Diff
tiny refactor
parent
c2c4609e
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#53194
passed
3 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tuhlbox/stringkernels.py
+7
-11
7 additions, 11 deletions
tuhlbox/stringkernels.py
with
7 additions
and
11 deletions
tuhlbox/stringkernels.py
+
7
−
11
View file @
978fa7bd
...
...
@@ -86,19 +86,15 @@ def intersection_kernel(x: np.ndarray, y: np.ndarray) -> np.ndarray:
return
_multiset_kernel
(
x
,
y
,
lambda
xc
,
yc
:
sum
((
xc
&
yc
).
values
()))
def
pqgram_distance
(
xc
:
collections
.
Counter
,
yc
:
collections
.
Counter
)
->
float
:
# this is a bag-union, which is not the default union of counters in python
xc_union
:
collections
.
Counter
=
xc
.
copy
()
xc_union
.
update
(
yc
)
union
=
sum
(
xc_union
.
values
())
intersection
=
sum
((
xc
&
yc
).
values
())
# eq. (2) and (3) of Augsten et al. 2010
return
(
union
-
2
*
intersection
)
/
(
union
-
intersection
)
def
pqgram_kernel
(
x
:
np
.
ndarray
,
y
:
np
.
ndarray
)
->
np
.
ndarray
:
"""
Calculates a distance kernel based on the PQ-gram distance by Austen et al. 2010.
"""
def
pqgram_distance
(
xc
:
collections
.
Counter
,
yc
:
collections
.
Counter
)
->
float
:
union
=
sum
((
xc
+
yc
).
values
())
# bag union
intersection
=
sum
((
xc
&
yc
).
values
())
# eq. (2) and (3) of Augsten et al. 2010
return
(
union
-
2
*
intersection
)
/
(
union
-
intersection
)
return
_multiset_kernel
(
x
,
y
,
pqgram_distance
)
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