Exemple #1
0
def main():

    # set program constants:
    K = 10  # max number of clusters
    B = 100  # number of null realisations created by gap test
    N = 100  # number of points in the input data cloud

    # generate clusters:
    n1, n2, n3 = 20, 20, 10
    n4 = N - n1 - n2 - n3
    cluster_vec = [
        sgt.genCluster((0.3, 0.7), 0.1, n1),
        sgt.genCluster((0.1, 0.3), 0.1, n2),
        sgt.genCluster((0.7, 0.5), 0.1, n3),
        sgt.genCluster((0.5, 0.1), 0.1, n4)
    ]

    # create data set:
    data_mat = np.concatenate(
        (cluster_vec[0], cluster_vec[1], cluster_vec[2], cluster_vec[3]),
        axis=0)
    data_mat = sgt.genPoisson(N)  # uniform point cloud

    # convert data to network:
    dist_mat = snt.getDistanceMatrix(data_mat)

    den_obj = sst.DendroTest(K).fit(dist_mat)

    # plot the top p levels of the dendrogram
    spt.plotDendroTest(data_mat, den_obj, fname='../media/dendro3.png')
Exemple #2
0
def main():

    # set program constants:
    K = 10  # max number of clusters
    B = 100  # number of null realisations created by gap test
    N = 100  # number of points in the input data cloud

    # generate clusters:
    n1, n2 = 30, 20
    n3 = N - n1 - n2
    cluster_vec = [
        sgt.genCluster((0.3, 0.7), 0.1, n1),
        sgt.genCluster((0.1, 0.3), 0.1, n2),
        sgt.genCluster((0.7, 0.5), 0.1, n3)
    ]

    # create data set:
    data_mat = np.concatenate((cluster_vec[0], cluster_vec[1], cluster_vec[2]),
                              axis=0)
    #data_mat = sgt.genPoisson(N)	# uniform point cloud

    # convert data to network:
    dist_mat = snt.getDistanceMatrix(data_mat)

    # perform gap test
    gap_obj = sst.GapTest(K, B).fit(dist_mat)
    spt.plotGapTest(data_mat, gap_obj, fname='../media/gap.png')
Exemple #3
0
def main():

    # generate clusters:
    data_mat = np.concatenate((sgt.genCluster(
        (0.2, 0.5), 0.15, 6), sgt.genCluster(
            (0.6, 0.7), 0.15, 5), sgt.genCluster((0.7, 0.2), 0.15, 3)),
                              axis=0)

    # convert data to network:
    dist_mat = snt.getDistanceMatrix(data_mat)
    #GX = snt.graphFromDistMatrix(DX)

    # perform clustering on the network:
    #clustering = AgglomerativeClustering(n_clusters=3).fit(X)	# with raw data
    clustering = AgglomerativeClustering(n_clusters=3,
                                         linkage='average',
                                         affinity='precomputed').fit(
                                             dist_mat)  # with distance matrix

    # plot it:
    #spt.plotData(X, annotate=True)
    #spt.plotData(X, labels=clustering.labels_)
    #spt.plotData(X, labels=clustering.labels_, fName='../media/clusters.pdf')
    #spt.plotGraph(GX)

    #spt.plotData(X, fName="../media/pointCloud.png")
    #spt.plotClustersGraph(clustering.labels_, fname='../media/clusters.graph.png')
    #spt.plotPointsGraph(X)

    spt.plotClustersAndGraph(data_mat,
                             clustering.labels_,
                             ffolder='../media/',
                             flabel=sys.argv[1])
Exemple #4
0
def main():

    N = 200
    K = 10
    B = 5

    # generate fake data
    data_mat = np.concatenate((sgt.genAnnulusCluster(
        (0.5, 0.5), 0.4, 0.3, N), sgt.genCluster((0.5, 0.5), 0.1, 100)),
                              axis=0)

    # get distance matrix:
    dist_mat = snt.getDistanceMatrix(data_mat)

    # cluster it
    clustering = AgglomerativeClustering(n_clusters=2,
                                         linkage='single',
                                         affinity='precomputed').fit(dist_mat)
    #elb_obj = sst.ElbowTest(K).fit(dist_mat, linkage='single')
    jump_obj = sst.JumpTest(K, B).fit(dist_mat, linkageMethod='single')

    # plot it:
    #spt.plotData(data_mat, labels=clustering.labels_, fname='../media/ring.singleLink1.png')
    #spt.plotElbowTest(data_mat, elb_obj)
    spt.plotJumpTest(data_mat, jump_obj, fname='../media/jumpRing.png')
Exemple #5
0
def main():

    # generate the data:
    data = np.concatenate((sgt.genCluster(
        (0.2, 0.2), 0.1, 20), sgt.genCluster(
            (0.6, 0.7), 0.1, 20), sgt.genCluster((0.8, 0.2), 0.1, 20)),
                          axis=0)

    #data = sgt.genPoisson(60)
    #spt.plotData(data)

    # compute distance matrix:
    dist = snt.getDistanceMatrix(data)

    # cluster the data:
    clustering = AgglomerativeClustering(linkage='average',
                                         affinity='precomputed',
                                         n_clusters=3).fit(dist)

    # for each cluster, print  cluster and shape histogram:
    #spt.plotData(data, labels=clustering.labels_)
    mpt.plotShapeHist(data, dist, labels=clustering.labels_)
Exemple #6
0
def main():

    K = 10  # max number of clusers

    # fix fake data parameters:
    n1, n2, n3 = 30, 20, 15  # number of points in each cluster
    R1, R2, R3 = 0.3, 0.1, 0.1  # max radius of each cluster

    # generate clusters:
    X1 = sgt.genCluster((0.3, 0.7), R1, n1)
    X2 = sgt.genCluster((0.1, 0.3), R2, n2)
    X3 = sgt.genCluster((0.7, 0.5), R3, n3)

    # create data set:
    n = n1 + n2 + n3  # number of points in fake data set
    X = np.concatenate((X1, X2, X3), axis=0)
    #X = sgt.genPoisson(n)	# uniform point cloud

    # convert data to network:
    dist_mat = snt.getDistanceMatrix(X)

    # perform elbow test:
    elbow_obj = sst.ElbowTest(K).fit(dist_mat)
    spt.plotElbowTest(X, elbow_obj, fname='../media/elbow.png')