<commit_before>#!/usr/bin/python

from numpy import *
from optparse import OptionParser
import kmeans
import iodata
import csv

# Command line parsin
parser = OptionParser()
parser.add_option("-d", "--data", metavar = "CSV",
                  dest = "finp", help = "data - required")
parser.add_option("-s", "--separator", type = "string",
                  dest = "sep", help = "separator - required")
parser.add_option("-c", "--cluster", type = "int",
                  dest = "k", help = "number of cluster - required")
parser.add_option("-i", "--iteration",  type = "str", dest = "nrip",
                  help = "number of iteration, default=None", default=None)
parser.add_option("-D", "--distance", type = "string",
                  dest = "met", help = "distance: dtw,ddtw,euclidean,pearson,default=ddtw", default="ddtw")
parser.add_option("-f", "--fast", action = "store_true", default = False,
                  dest = "fast", help = "Fast dtw, default = False")
parser.add_option("-r", "--radius", type = "int",
                  dest = "radius", help = "Accuracy of FastDtw, default=20", default=20)
parser.add_option("-S", "--Seed", type = "str",
                  dest = "seed", help = "Seed for function random, default = None", default=None)
parser.add_option("-t", "--tolerance", type = "float",
                  dest = "error", help = "tolerance of algorithm, default = 0.0001", default=0.0001)
parser.add_option("-o", "--output", metavar = "CSV",
                  dest = "foutp", help = "name file output - required")
parser.add_option("-p", "--processor", type = "str",
                  dest = "pu", help = "Use CPU/GPU, default = CPU", default="CPU")
(options, args) = parser.parse_args()

if not options.finp:
	parser.error("option -d (data) is required")
if not options.sep:
	parser.error("option -s (separator) is required")
if options.sep == "tab":
    options.sep = '\t'
if not options.k:
	parser.error("option -c (cluster) is required")
if not options.foutp:
	parser.error("option -o (output) is required")

if options.nrip == 'None':
    options.nrip = None
elif options.nrip:
    try:
        options.nrip = int(options.nrip)
    except ValueError:
        parser.error("option -i: invalid value")

if options.fast == 'True':
    options.fast = True
else:
    options.fast = False

if options.seed == 'None':
    options.seed = None
elif options.seed:
    try:
        options.seed = int(options.seed)
    except ValueError:
        parser.error("option -S: invalid value")

print "Parameters:"
print "separator ",options.sep
print "cluster ",options.k
print "iteration ",options.nrip
print "distance ",options.met
print "fast", options.fast
print "radius ",options.radius
print "Seed ",options.seed
print "tollerance ",options.error
print "Computing on", options.pu

x, mat, header, title = iodata.load_csv(options.finp, options.sep)
m = kmeans.Means(options.nrip,
                 options.met,
                 options.fast,
                 options.radius,
                 options.seed,
                 options.error,
                 pu=options.pu)

centroidsid, mini = m.compute(options.k, mat.T)

w = csv.writer(open(options.foutp, 'w'), delimiter='\t')
w.writerow(centroidsid)
w.writerow(mini)
<commit_msg>kmeans tool fix<commit_after>#!/usr/bin/python

from numpy import *
from optparse import OptionParser
import kmeans
import iodata
import csv

# Command line parsin
parser = OptionParser()
parser.add_option("-d", "--data", metavar = "CSV",
                  dest = "finp", help = "data - required")
parser.add_option("-s", "--separator", type = "string",
                  dest = "sep", help = "separator - required")
parser.add_option("-c", "--cluster", type = "int",
                  dest = "k", help = "number of cluster - required")
parser.add_option("-i", "--iteration",  type = "str", dest = "nrip",
                  help = "number of iteration, default=None", default=None)
parser.add_option("-D", "--distance", type = "string",
                  dest = "met", help = "distance: dtw,ddtw,euclidean,pearson,default=ddtw", default="ddtw")
parser.add_option("-f", "--fast", action = "store_true", default = False,
                  dest = "fast", help = "Fast dtw, default = False")
parser.add_option("-r", "--radius", type = "int",
                  dest = "radius", help = "Accuracy of FastDtw, default=20", default=20)
parser.add_option("-S", "--Seed", type = "str",
                  dest = "seed", help = "Seed for function random, default = None", default=None)
parser.add_option("-t", "--tolerance", type = "float",
                  dest = "error", help = "tolerance of algorithm, default = 0.0001", default=0.0001)
parser.add_option("-o", "--output", metavar = "CSV",
                  dest = "foutp", help = "name file output - required")
parser.add_option("-p", "--processor", type = "str",
                  dest = "pu", help = "Use CPU/GPU, default = CPU", default="CPU")
(options, args) = parser.parse_args()

if not options.finp:
	parser.error("option -d (data) is required")
if not options.sep:
	parser.error("option -s (separator) is required")
if options.sep == "tab":
    options.sep = '\t'
if not options.k:
	parser.error("option -c (cluster) is required")
if not options.foutp:
	parser.error("option -o (output) is required")

if options.nrip == 'None':
    options.nrip = None
elif options.nrip:
    try:
        options.nrip = int(options.nrip)
    except ValueError:
        parser.error("option -i: invalid value")

if options.fast == 'True':
    options.fast = True
else:
    options.fast = False

if options.seed == 'None':
    options.seed = None
elif options.seed:
    try:
        options.seed = int(options.seed)
    except ValueError:
        parser.error("option -S: invalid value")

print "Parameters:"
print "separator ",options.sep
print "cluster ",options.k
print "iteration ",options.nrip
print "distance ",options.met
print "fast", options.fast
print "radius ",options.radius
print "Seed ",options.seed
print "tollerance ",options.error
print "Computing on", options.pu

x, mat, header, title = iodata.load_csv(options.finp, options.sep)
m = kmeans.Means(options.nrip,
                 options.met,
                 options.fast,
                 options.radius,
                 options.seed,
                 options.error,
                 pu=options.pu)

centroidsid, mini = m.compute(options.k, mat.T)

w = csv.writer(open(options.foutp, 'w'), delimiter='\t')
w.writerow("")
w.writerow(mini)

{'fraction_non_alphanumeric': 0.161195869933734, 'fraction_numerical': 0.004314994606256742, 'mean_word_length': 2.8653960690887432, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4996095', 'n_tokens_mistral': 2059, 'n_tokens_neox': 2005, 'n_words': 560}