-
Notifications
You must be signed in to change notification settings - Fork 1
/
optimize.py
44 lines (35 loc) · 1.09 KB
/
optimize.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
""" This is quick and dirty
Norallly one should give the kmean algorithm the proper
init parameters. When you don't do it, it chooses them
at random, giving varying results.
So, instead of looking at the best init params, I just
run kmeans dozens of time to find the best outcome.
That just brute force.
"""
import subprocess
import shutil
import os
def d(p):
if os.path.exists(p):
os.remove(p)
def s(p):
if os.path.exists(p):
r = os.stat(p).st_size
print("Size of {} is {}".format(p,r))
return r
else:
return 0
d("data.a.best")
d("cstripes.data.best")
NB_TRIALS = 200
for i in range(NB_TRIALS):
subprocess.run("python kmean.py")
print("-"*80 + " Run {}/{}".format(i, NB_TRIALS))
if s("cstripes.data") < (s("cstripes.data.best") or 100000000):
print("Best shot {}".format(s("cstripes.data")))
shutil.copyfile("data.a", "data.a.best")
shutil.copyfile("cstripes.data", "cstripes.data.best")
else:
print("Not better")
shutil.copyfile("data.a.best", "data.a")
shutil.copyfile("cstripes.data.best", "cstripes.data")