Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cmda3634_materials
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
srigavili
cmda3634_materials
Commits
1fe36823
Commit
1fe36823
authored
1 year ago
by
Jason R Wilson
Browse files
Options
Downloads
Patches
Plain Diff
removing extra file
parent
6fb4c0f1
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
FSA04/k2center.py
+0
-44
0 additions, 44 deletions
FSA04/k2center.py
with
0 additions
and
44 deletions
FSA04/k2center.py
deleted
100644 → 0
+
0
−
44
View file @
6fb4c0f1
import
sys
import
numpy
as
np
import
time
# calculate the cost squared for centers with indices c1, c2
def
calc_cost_sq
(
data
,
c1
,
c2
):
cost_sq
=
0
;
n
=
len
(
data
)
for
i
in
range
(
n
):
ds1
=
np
.
inner
(
data
[
i
]
-
data
[
c1
],
data
[
i
]
-
data
[
c1
])
ds2
=
np
.
inner
(
data
[
i
]
-
data
[
c2
],
data
[
i
]
-
data
[
c2
])
min_dist_sq
=
min
([
ds1
,
ds2
])
cost_sq
=
max
([
cost_sq
,
min_dist_sq
])
return
cost_sq
# load the points
data
=
np
.
loadtxt
(
sys
.
stdin
,
skiprows
=
1
)
# start the timer
tic
=
time
.
process_time
()
# compute the minimal cost and an optimal solution
n
=
len
(
data
)
min_cost_sq
=
float
(
"
inf
"
)
tuples_checked
=
0
;
for
c1
in
range
(
0
,
n
-
1
):
for
c2
in
range
(
c1
+
1
,
n
):
tuples_checked
+=
1
cost_sq
=
calc_cost_sq
(
data
,
c1
,
c2
)
if
(
cost_sq
<
min_cost_sq
):
min_cost_sq
=
cost_sq
optimal_centers
=
np
.
array
([
c1
,
c2
])
# stop the timer
toc
=
time
.
process_time
()
elapsed
=
toc
-
tic
# print the results
print
(
'
number of points =
'
,
n
)
print
(
'
2-tuples checked =
'
,
tuples_checked
)
print
(
'
elapsed time =
'
,
round
(
elapsed
,
2
),
'
seconds
'
)
print
(
'
2-tuples checked per second =
'
,
int
(
tuples_checked
/
elapsed
))
print
(
'
minimum cost =
'
,
np
.
round
(
np
.
sqrt
(
min_cost_sq
),
2
))
print
(
'
optimal centers =
'
,
optimal_centers
)
This diff is collapsed.
Click to expand it.
Preview
0%
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