def Run(): features = datapre.Features() epsilons = [0.1560, 0.1556, 0.1555] number = [40, 60, 80, 100] for epsilon in epsilons: for n in number: start_time = time.time() profile1 = greedy.Greedy(n, features, datapre.CategoriesDistribution(), epsilon).SearchWithReplace() end_time = time.time() with open("GB%d_%.4f" % (n, epsilon), "wb") as f: f.write("cost %f s" % (end_time - start_time)) f.write("Attribute Representativeness is:") f.write(str(metric.AttributeRepresentative(features, profile1))) f.write("\n") for profile in profile1: f.write(profile + "\t") start_time = time.time() profile2 = kmedoids.KMedoids(n, features, datapre.CategoriesDistribution(), epsilon).Search() end_time = time.time() with open("kmedoids%d_%.4f" % (n, epsilon), "wb") as f: f.write("cost %f s" % (end_time - start_time)) f.write("Attribute Representativeness is:") f.write(str(metric.AttributeRepresentative(features, profile2))) f.write("\n") for profile in profile2: f.write(profile + "\t") start_time = time.time() profile3 = sa.SAalgo(n, features, datapre.CategoriesDistribution(), epsilon, 0.3, 10, 0.9).Search() end_time = time.time() with open("sa%d_%.4f" % (n, epsilon), "wb") as f: f.write("cost %f s" % (end_time - start_time)) f.write("Attribute Representativeness is:") f.write(str(metric.AttributeRepresentative(features, profile3))) f.write("\n") for profile in profile3: f.write(profile + "\t")
def test(): features = datapre.Features() to_run = [40, 60, 80, 100] for i in to_run: start_time = time.time() method = KMedoids(i, datapre.Features(), datapre.CategoriesDistribution(), 0.1555) profiles = method.Search() end_time = time.time() print metric.AttributeRepresentative(features, profiles) print profiles print "cost %f s" % (end_time - start_time) with open("%dclustering_result" % i, "wb") as f: f.write("cost %f s" % (end_time - start_time)) f.write("\n") f.write("Attribute Representativeness is:") f.write(str(metric.AttributeRepresentative(features, profiles))) f.write("\n") for profile in profiles: f.write(profile + "\t") # test()