Пример #1
0
def visualizeEmbedding_2D_withCluster(ncluster=3):
    twoGraphEmbeds, twoGRids = retrieveCrossIntervalEmbeddings(
        "../miscs/taxi-deepwalk-CA-usespatial.vec", skipheader=0)

    gndTid, gndLabels = generate_AC_clusteringLabel(ncluster, "rac")
    #    gndTid, gndLabels = generatePOIClusteringlabel(ncluster)
    #    gndTid, gndLabels = generate_od_clusteringLabel(ncluster)
    clrs = ["b", "r", "g", "w", "c", "b"]
    print[len(np.argwhere(gndLabels == i)) for i in range(ncluster)]

    plt.figure(figsize=(40, 36))
    plt.suptitle("RAC count as ground truth {0} clusters".format(ncluster))
    for h in range(len(twoGRids)):
        plt.subplot(4, 6, h + 1)
        for cluster in range(ncluster):
            groupIds = gndTid[np.argwhere(gndLabels == cluster)]
            idx = np.in1d(twoGRids[h], groupIds)
            x = twoGraphEmbeds[h][idx, 0]
            y = twoGraphEmbeds[h][idx, 1]
            ids = twoGRids[h][idx]

            plt.scatter(x, y, c=clrs[cluster], hold=True)
            plt.xlim([-1.0, 1])
            plt.ylim([-1, 0.5])
            for i, e in enumerate(ids):
                plt.annotate(s=str(e),
                             xy=(x[i], y[i]),
                             xytext=(-5, 5),
                             textcoords="offset points")
            plt.title("2D visualization at {0}".format(h))
    plt.savefig("CA-RAC-{0}cluster.png".format(ncluster))
Пример #2
0
def getDeepwalkEmbeddingFeatures(Spatial):
    res = {}
    emptyEmbedding = np.zeros((8,))
    features, ids = retrieveCrossIntervalEmbeddings("../miscs/{0}/taxi-deepwalk-CA-{1}.vec".format(year, Spatial), skipheader=0)
    for h in range(24):
        sids = np.argsort(ids[h])
        res[h] = features[h][sids, :]
        
        if len(sids) != 77:
            print len(sids), h
            for i in range(1, 78):
                if i not in ids[h]:
                    res[h] = np.insert(res[h], i-1, emptyEmbedding, axis=0)
        assert res[h].shape == (77, 8)
    return res
Пример #3
0
def getDeepwalkEmbeddingFeatures(Spatial):
    with open("../miscs/POI_tract.pickle") as fin:
        ordKey = pickle.load(fin)
        tract_poi = pickle.load(fin)

    res = {}
    emptyEmbedding = np.zeros((20, ))
    features, ids = retrieveCrossIntervalEmbeddings(
        "../miscs/{0}/taxi-deepwalk-tract-{1}.vec".format(year, Spatial),
        skipheader=0)
    for h in range(8):
        sids = np.argsort(ids[h])
        res[h] = features[h][sids, :]

        if len(sids) != 801:
            print len(sids), h
            for i, k in enumerate(ordKey):
                if k not in ids[h]:
                    res[h] = np.insert(res[h], i, emptyEmbedding, axis=0)
        assert res[h].shape == (801, 20)
    return res
Пример #4
0
def visualizeEmbedding_2D():
    twoGraphEmbeds, twoGRids = retrieveCrossIntervalEmbeddings(
        "../miscs/taxi-deepwalk-CA-usespatial-2D.vec", skipheader=0)
    groups = [[13, 14, 15, 16], [8, 32, 33], [44, 45, 47, 48], [76]]
    #    groups = [[5,6,7,21,22], [8,32,33], [26,27,29,30]]
    clrs = ["b", "r", "g", "c", "w", "k"]

    plt.figure(figsize=(12, 6))
    for k, h in enumerate([7, 8, 9, 16, 17, 18, 21,
                           22]):  # enumerate(range(len(twoGRids))):
        f = plt.subplot(2, 4, k + 1)

        xr = 0
        yr = 0
        xo = 0
        yo = 0
        for i, group in enumerate(groups):
            idx = np.in1d(twoGRids[h], group)
            x = twoGraphEmbeds[h][idx, 0]
            y = twoGraphEmbeds[h][idx, 1]
            ids = twoGRids[h][idx]

            plt.scatter(x, y, s=40, c=clrs[i], hold=True)
            #            plt.xlim([-3.0, 0.6])
            #            plt.ylim([-2, 0.5])
            for j, e in enumerate(ids):
                if e in [76, 47]:
                    plt.annotate(s=str(e),
                                 xy=(x[j], y[j]),
                                 xytext=(-2, -15),
                                 textcoords="offset points",
                                 fontsize=14)
                elif e in [14, 15, 16]:
                    xr += x[j]
                    yr += y[j]
                elif e in [8, 32, 33]:
                    xo += x[j]
                    yo += y[j]
                else:
                    if k == 0:
                        if e == 13:
                            plt.annotate(s=str(e),
                                         xy=(x[j], y[j]),
                                         xytext=(-2, -15),
                                         textcoords="offset points",
                                         fontsize=14)
                        else:
                            plt.annotate(s=str(e),
                                         xy=(x[j], y[j]),
                                         xytext=(0, -15),
                                         textcoords="offset points",
                                         fontsize=14)

        if k == 0:
            plt.annotate(s="14,15,16",
                         xy=(xr / 3, yr / 3),
                         xytext=(5, 3),
                         textcoords="offset points",
                         fontsize=14)
            plt.annotate(s="8,32,33",
                         xy=(xo / 3, yo / 3),
                         xytext=(-50, 8),
                         textcoords="offset points",
                         fontsize=14)

        plt.title("{0}:00".format(h), fontsize=16)
        f.tick_params(axis="both", labelsize=10)

    plt.tight_layout()
    plt.savefig("CA-case-3region.pdf")