Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
CodeRed
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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
M-29
Software
CodeRed
Commits
2a4091d8
Commit
2a4091d8
authored
4 years ago
by
Kai Sellschopp
Browse files
Options
Downloads
Patches
Plain Diff
cleanup of the standalone fps method
parent
dc5fdb49
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
fps.py
+0
-49
0 additions, 49 deletions
fps.py
with
0 additions
and
49 deletions
fps.py
deleted
100644 → 0
+
0
−
49
View file @
dc5fdb49
import
numpy
as
np
from
itertools
import
combinations
def
greedy
(
k
,
dist_matrix
):
# initialize some arrays
indices
=
np
.
arange
(
len
(
dist_matrix
))
mask
=
np
.
ones
(
len
(
dist_matrix
),
dtype
=
'
bool
'
)
# select two indices with largest distance
select
=
np
.
array
(
np
.
unravel_index
(
np
.
argmax
(
dist_matrix
),
dist_matrix
.
shape
))
while
len
(
select
)
<
k
:
# mask selected indices
mask
[
select
]
=
False
# find the point with the largest minimum distance to already selected points
maxmin
=
np
.
argmax
(
np
.
amin
(
dist_matrix
[
select
][:,
mask
],
axis
=
0
))
index_maxmin
=
indices
[
mask
][
maxmin
]
# add the index to the selection
select
=
np
.
append
(
select
,
index_maxmin
)
# return resulting selection (approximate solution)
return
select
def
brute_force
(
k
,
dist_matrix
):
# initialize indices and selection
indices
=
np
.
arange
(
len
(
dist_matrix
))
select
=
np
.
arange
(
k
)
mask
=
np
.
logical_not
(
np
.
eye
(
k
,
dtype
=
'
bool
'
))
# ignore diagonal elements
mindist_select
=
np
.
amin
(
dist_matrix
[
select
][:,
select
][
mask
])
# iterate over all possible combinations
for
combo
in
combinations
(
indices
,
k
):
# convert to array
combo
=
np
.
array
(
combo
)
# calculate the minimal distance between points
mindist_combo
=
np
.
amin
(
dist_matrix
[
combo
][:,
combo
][
mask
])
# replace the selected combination if mindist is larger
if
mindist_combo
>
mindist_select
:
select
=
combo
mindist_select
=
mindist_combo
# return selection with maximum mindist (exact solution)
return
select
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