ó <¿CVc@s¥ddlmZmZyddlZWnek r9nXddlmZmZmZddl m Z e defd„ƒYƒZ d„Z e dkr¡e ƒndS( iÿÿÿÿ(tprint_functiontunicode_literalsN(tVectorSpaceClusterert Dendrogramtcosine_distance(tpython_2_unicode_compatiblet GAAClusterercBsqeZdZded d„Zeed„Zed„Zd„Z d„Z d„Z d„Z d „Z d „ZRS( uM The Group Average Agglomerative starts with each of the N vectors as singleton clusters. It then iteratively merges pairs of clusters which have the closest centroids. This continues until there is only one cluster. The order of merges gives rise to a dendrogram: a tree with the earlier merges lower than later merges. The membership of a given number of clusters c, 1 <= c <= N, can be found by cutting the dendrogram at depth c. This clusterer uses the cosine similarity metric only, which allows for efficient speed-up in the clustering process. icCs2tj|||ƒ||_d|_d|_dS(N(Rt__init__t _num_clusterstNonet _dendrogramt_groups_values(tselft num_clusterst normalisetsvd_dimensions((sc/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/cluster/gaac.pyRs  cCsGtg|D]}tj|tjƒ^q ƒ|_tj||||ƒS(N(Rtnumpytarraytfloat64R Rtcluster(R tvectorstassign_clustersttracetvector((sc/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/cluster/gaac.pyR%s.c Cs¾t|ƒ}dg|}|}tj|ƒ}||f}tj|dtjƒtj}xSt|ƒD]E} x<t| d|ƒD]'} t|| || ƒ|| | f(R(R ((sc/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/cluster/gaac.pyt__repr__‡sN(t__name__t __module__t__doc__tTrueR RtFalseRR.R#R%R;R<R R=(((sc/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/cluster/gaac.pyRs  &    cCs ddlm}gddgddgddgddgddgddggD]}tj|ƒ^qM}|dƒ}|j|tƒ}td|ƒtd |ƒtd |ƒtƒ|jƒjƒtjddgƒ}td |d d ƒt|j |ƒƒtƒdS(uO Non-interactive demonstration of the clusterers with simple 2-D data. iÿÿÿÿ(Riiiiiu Clusterer:u Clustered:uAs:u classify(%s):tendu N( t nltk.clusterRRRRRAR"R<tshowtclassify(RtfRt clustererR8R((sc/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/cluster/gaac.pytdemoŠsX    u__main__(t __future__RRRt ImportErrortnltk.cluster.utilRRRt nltk.compatRRRIR>(((sc/private/var/folders/cc/xm4nqn811x9b50x1q_zpkmvdjlphkp/T/pip-build-FUwmDn/nltk/nltk/cluster/gaac.pyts x