def run(self): wx.CallAfter(self.window.Log, "Creating Epanechnikov analyzer using factory method") ap = flow.create_analyzer("Epanechnikov", self.data, self.dim, self.n, self.k, self.h, 0.0) wx.CallAfter(self.window.Log, "Test find seeds") # min_sep = ap.calc_h() # print min_sep min_sep = 0.1 # seeds = ap.find_seeds(min_sep, 10, 100) seeds = ap.find_seeds_simple(self.inputs['seeds']) wx.CallAfter(self.window.Log, "num seeds:" + str(len(seeds))) wx.CallAfter(self.window.Log, "Test find modes") modes = ap.find_modes(seeds, 1e-4) wx.CallAfter(self.window.Log, "num modes:" + str(len(modes))) # for mode in modes: # print mode, modes[mode] wx.CallAfter(self.window.Log, "Test merge modes") min_merge_sep = 1.0 mmodes = ap.merge_modes(modes, min_merge_sep) wx.CallAfter(self.window.Log, "Test dip") dip_ratio = self.inputs['dip'] mmodes = ap.check_modes(mmodes, dip_ratio) wx.CallAfter(self.window.Log, "num dip modes:" + str(len(mmodes))) wx.CallAfter(self.window.Log, mmodes) # for mmode in mmodes: # print mmode, mmodes[mmode] # print ">>>", data_unscaled[mmodes[mmode][0]] wx.CallAfter(self.window.Log, "Test label seeds") # seed_labels = flow.label_seeds(mmodes) # for seed_label in seed_labels: # print seed_label, seed_labels[seed_label] wx.CallAfter(self.window.Log, "Test label points") # nbrs = 1+int(numpy.floor(len(mmodes)/5.0)) nbrs = 1 clusters = flow.label_points("Epanechnikov", self.data, mmodes, nbrs) #counts = {} #for k in clusters.values(): # counts[k] = counts.get(k, 0) + 1 #print counts z = [] for i in clusters.keys(): z.append(clusters[i]) # save modes in order of number of captured seeds items = [(k, len(v)) for k, v in mmodes.items() if len(v) > 1] items.sort(key = operator.itemgetter(1), reverse=True) wx.CallAfter(self.window.Log, "Modes found that pass dip and pop tests") wx.CallAfter(self.window.Log, items) mm = numpy.array([item[0] for item in items]) if mm.size == 0: wx.CallAfter(self.window.NoMM) else: wx.CallAfter(self.window.ThreadFinish, (z,mm))
def run(self): wx.CallAfter(self.window.Log, "Creating Epanechnikov analyzer using factory method") ap = flow.create_analyzer("Epanechnikov", self.data, self.dim, self.n, self.k, self.h, 0.0) wx.CallAfter(self.window.Log, "Test find seeds") min_sep = 0.1 seeds = ap.find_seeds_simple(self.inputs['seeds']) wx.CallAfter(self.window.Log, "num seeds:" + str(len(seeds))) wx.CallAfter(self.window.Log, "Test find modes") modes = ap.find_modes(seeds, 1e-4) wx.CallAfter(self.window.Log, "num modes:" + str(len(modes))) wx.CallAfter(self.window.Log, "Test merge modes") min_merge_sep = 1.0 print "Entering merge modes" print ap.merge_modes(modes, min_merge_sep) mmodes = ap.merge_modes(modes, min_merge_sep) print "Exiting merge modes" wx.CallAfter(self.window.Log, "Test dip") dip_ratio = self.inputs['dip'] mmodes = ap.check_modes(mmodes, dip_ratio) wx.CallAfter(self.window.Log, "num dip modes:" + str(len(mmodes))) wx.CallAfter(self.window.Log, mmodes) wx.CallAfter(self.window.Log, "Test label seeds") wx.CallAfter(self.window.Log, "Test label points") nbrs = 1 clusters = flow.label_points("Epanechnikov", self.data, mmodes, nbrs) z = [] for i in clusters.keys(): z.append(clusters[i]) # save modes in order of number of captured seeds items = [(k, len(v)) for k, v in mmodes.items() if len(v) > 1] items.sort(key = operator.itemgetter(1), reverse=True) wx.CallAfter(self.window.Log, "Modes found that pass dip and pop tests") wx.CallAfter(self.window.Log, items) mm = numpy.array([item[0] for item in items]) if mm.size == 0: wx.CallAfter(self.window.NoMM) else: wx.CallAfter(self.window.ThreadFinish, (z,mm))
# print min(x4), max(x4) # data_unscaled = numpy.transpose([x1, x2, x3, x4]) # #data = numpy.transpose([(x1-min(x1))/max(x1), (x2-min(x2))/max(x2), (x3-min(x3))/max(x3), (x4-min(x4))/max(x4)]) # data = data_unscaled # data = [map(float, line.strip().split(',')) for line in open('c_data.txt').readlines()] n, dim = numpy.shape(data) #print n #print dim k = n h = 0.25 alpha = 0.0 #print "Creating uniform analyzer using factory method" ap = flow.create_analyzer("Uniform", data, dim, n, k, h, alpha) #print "Test h functions" #print ap.get_h() #print "Test find seeds" # min_sep = ap.calc_h() # print min_sep min_sep = 0.1 # seeds = ap.find_seeds(min_sep, 10, 100) seeds = ap.find_seeds_simple(500) #print "num seeds:", len(seeds) #print "Test find modes" modes = ap.find_modes(seeds, 1e-4) #print "num modes:", len(modes)