Exemplo n.º 1
0
def getMCN(trade, tradesmen, population):
    fig, ax = plt.subplots()
    neighbourhood = [x[trade] for n, x in tradesmen.items()]
    totalTradesmen = sum(neighbourhood)
    if(totalTradesmen > 20):
        perCapita = [n / p for n, p in zip(neighbourhood, population)]
        plt.title(Shared.getTradeName(trade))
        bimodal = analyze(fig, ax, trade, perCapita)
        return bimodal
    return -1
Exemplo n.º 2
0
                px = pixels[x, y]
                for i, n in enumerate(Shared.getNeighbourhoods().keys()):
                    g = int(n / 10)
                    b = n % 10
                    if px[0] == 0 and px[1] == g and px[2] == b:
                        pixels[x, y] = (int(values[i] * 255), 0, 0, 255)
        fm.save("results/trademap_" + str(trade) + ".png")
    return fm

def getMCN(trade, tradesmen, population):
    fig, ax = plt.subplots()
    neighbourhood = [x[trade] for n, x in tradesmen.items()]
    totalTradesmen = sum(neighbourhood)
    if(totalTradesmen > 20):
        perCapita = [n / p for n, p in zip(neighbourhood, population)]
        plt.title(Shared.getTradeName(trade))
        bimodal = analyze(fig, ax, trade, perCapita)
        return bimodal
    return -1

tradesmen, population, tradeWealth = Shared.getCatastoData()
centralized = []
decentralized = []
for trade in range(0,100):
    bimodal = getMCN(trade, tradesmen, population)
    if bimodal:
        centralized.append(Shared.getTradeName(trade))
    else:
        decentralized.append(Shared.getTradeName(trade))
print(centralized)
print(decentralized)
Exemplo n.º 3
0
ap = sklearn.cluster.AffinityPropagation(damping = 0.9 , affinity='precomputed')
#ap = sklearn.cluster.KMeans()
wmin = scipy.mean(c)
#ap = sklearn.cluster.MeanShift(bandwidth=100, cluster_all=False)
#ap.fit(c)
labels = ap.fit_predict(c)
print(labels)
tl = []
Gl = []
for label in range(min(labels), max(labels) +1):
    tl.append([])
    Gl.append(nx.Graph())
    for i in range(len(labels)):
        if(labels[i] == label):
            trade = validTrades[i]
            tl[label].append(Shared.getTradeName(trade))
            Gl[label].add_node(Shared.getTradeName(trade))

    weights = []
    for i in range(len(labels)):
        if(labels[i] == label):
            for j in range(len(labels)):
                if(labels[j] == label):
                    for x in range(1,4):
                        highTrade = np.argmax(c[i] == sorted(c[i], reverse = True)[x])
                        w = c[i][highTrade]
                        Gl[label - min(labels)].add_edge(Shared.getTradeName(i),Shared.getTradeName(highTrade),weight=w)
                       # if(highTrade > i):
                       #     weights.append(w)

    for node in Gl[label-min(labels)].nodes():