Esempio n. 1
0
def dtree(dm, method='a'):
    """
    dm: DistMat(N), method: s ('a') -> Tree(N)

    calls PyCluster.treecluster(method=method, distancematrix=dm), except that
    dm is copied, to protect from PyClusters INSANE behaviour of modifying dm
    in place.

    """
    #warning: pycluster writes the dm by side effect!!!!!
    dm = dm.copy()
    return treecluster(method=str(method), distancematrix=dm)
Esempio n. 2
0
	def _guide_tree(self):
		"""
		Build a guide tree from the distance matrix

		:author: Woon Wai Keen
		:author: Vladimir Likic
		"""

		n = len(self.dist_matrix)

		print(f" -> Clustering {n * (n - 1):d} pairwise alignments.", end='')
		self.tree = treecluster(data=None, distancematrix=self.dist_matrix, method='a')
		print("Done")
Esempio n. 3
0
def vtree(dat, dist='e', method='a'):
    """
    dat: N,M-#, dist: s ('e'), method: s ('a') -> Tree(N)

    calls PyCluster.treecluster(dat, dist=dist, method=method),

    This require that dat contain data smaples in rows, and that the distance
    function is appropriate to use on the samples (e.g. the default dist='e' is
    the euclidean distance, and all PyCluster dist options are vector space
    distances).

    """
    #implicit transpose=0, aka samples are rows, and there is no mask or weight
    return treecluster(dat, dist=dist, method=str(method))
Esempio n. 4
0
    def _guide_tree(self, dist_matrix):
        """
        @summary: Build a guide tree from the distance matrix

        @param dist_matrix: The distance matrix
        @type dist_matrix: numpy.ndarray
        @return: Pycluster similarity tree
        @rtype: Pycluster.cluster.Tree

        @author: Woon Wai Keen
        @author: Vladimir Likic
        """

        n = len(dist_matrix)

        print " -> Clustering %d pairwise alignments." % (n * (n - 1)),
        tree = treecluster(distancematrix=dist_matrix, method='a')
        print "Done"

        return tree
Esempio n. 5
0
    def _guide_tree(self, dist_matrix):

        """
        @summary: Build a guide tree from the distance matrix

        @param dist_matrix: The distance matrix
        @type dist_matrix: numpy.ndarray
        @return: Pycluster similarity tree
        @rtype: Pycluster.cluster.Tree

        @author: Woon Wai Keen
        @author: Vladimir Likic
        """

        n = len(dist_matrix)

        print " -> Clustering %d pairwise alignments." % (n*(n-1)),
        tree = treecluster(distancematrix=dist_matrix, method='a')
        print "Done"

        return tree
Esempio n. 6
0
print os.getcwd()

im = Image.open(file)
im = im.convert("1")


# Ermittle Bildgroesse:
M = im.size[0]
N = im.size[1]

data = array(im.getdata())
data = data.reshape(im.size)

px1 = vstack([nonzero(data==0)[0],nonzero(data==0)[1]]).T

tree = treecluster(px1)

ho = tree.cut(4)

# Bestimme Zentren:
center = zeros([4,2])

for i in arange(4):
    tmp = px1[nonzero(ho==i)[0],:]
    center[i,0]=mean(tmp[:,0])
    center[i,1]=mean(tmp[:,1])
    tmp_ref = tmp-center[i,:]
    max_abs = max(sqrt((tmp_ref**2).sum(axis=1))) #bestimme den maximalen Abstand der zum Cluster zugehoerigen Pixel
    print max_abs
    
# Plotte die gefundenen Cluster
Esempio n. 7
0
 def compute_linkage(cls, conden_dist_mat):
     lower_dist_mat = cls.convert_condensed_to_lower(conden_dist_mat)
     tree = treecluster(distancematrix=lower_dist_mat, method='s')
     return cls.convert_tree_to_mat(tree)
#this method generates tree from PyCluster Tree
def generateTree(tree, wordlist):
  nodeList = []
  for i in range(len(tree)):
    parent = Tree()
    parent.name = str(-(i+1))
    for node in eval(str(tree[i]).split(':')[0]):
      if node >= 0:
        child = Tree()
        child.name = wordlist[node]
        parent.add_child(child)
      else:
        parent.add_child(nodeList[int(-node)-1])
    nodeList.append(parent)
  print nodeList[-1].get_ascii(show_internal=True)
  return nodeList[-1]
  

if __name__ == "__main__":
  db = db_connection['PW_test']
  #tree = buildCategoryForest("Travel")
  #calDistanceMatrix(wordlist1, tree)
  wordlist1 = generateWordList('Travel', 50)
  for speech in ['n', 'v']:
    d = simToDistMatrix(calSimMatrix2(wordlist1[speech], speech, 'Travel'))
    tree = treecluster(method = 'a', dist = 'e', distancematrix = d)
    generateTree(tree, wordlist1[speech])
    print tree
    for i in range(len(wordlist1[speech])):
      print i,wordlist1[speech][i]