コード例 #1
0
            plt.title('W4[' + str(coeffi) + ',' + str(coeffj) + ']')
        plt.grid(True)
    plt.suptitle("1d projections of the appoximated 23d energy landscape;" + \
        " x: values, y: probabilities\nPeaks correspond to lower total cost")
    plt.show()

    # Now, let's start with clustering
    # Sometimes we want to skip the elbow search, debug purposes
    elbow = True
    if (elbow):
        # Find the optimal number of clusters
        mcmc.elbow_search(X, 3, 70)

    ncent = int(input("Enter the number of centroids: "))
    # Store the clusters, i.e. the points on which the distrobution concentrates
    centroids, freq = mcmc.detailed_clustering(X, ncent, auxiliary_tot_cost)

    # Plot the clustered empirical distribution
    for i in range(23):
        bb = 50  # Bins
        plt.subplot(5, 5, i + 1)
        # If 0 or 1, we are with parameter b2
        if (i < 2):
            plt.hist(centroids[:, i], bb, density=True, color='green')
            plt.title('b2[' + str(i + 1) + ']')
        elif (i < 5):
            plt.hist(centroids[:, i], bb, density=True, color='darkorange')
            plt.title('b3[' + str(i - 1) + ']')
        elif (i < 7):
            plt.hist(centroids[:, i], bb, density=True, color='magenta')
            plt.title('b4[' + str(i - 4) + ']')
コード例 #2
0
    X.append(np.array(x[0:-1].split(' ')).astype("float64"))
X = np.asanyarray(X)
samples_file.close()
print("Read", len(X), "samples of dimension", len(X[0]))

# Plot the sampling distribution
d = len(X[0])
for i in range(d):
    plt.subplot(d, 1, i + 1)
    plt.hist(X[:, i], 50, density=True)
plt.suptitle("Complete distribution")
plt.show()

# Find the optimal number of clustering
mcmc.elbow_search(X, 1, 10)
ncent = int(input("Enter the number of centroids: "))
# Store the clusters, which will be candidate modes
centroids, freq = mcmc.detailed_clustering(X, ncent, U)
# Perform gradient descent on each centroid to identify the modes
print("\nSearch for the modes: ")
for i in range(ncent):
    print("Gradient descent on candidate mode number", i)
    if (mcmc.simple_descent(centroids[i], U, gradU)):
        print("MODE FOUND: centroid number ", i)

for i in range(d):
    plt.subplot(d, 1, i + 1)
    plt.scatter(centroids[:, i], freq, marker="*")
plt.suptitle("Clustered distribution")
plt.show()