コード例 #1
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()
コード例 #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]))

    # Find the optimal number of clustering
    mcmc.elbow_search(X, 1, 20)
    ncent = int(input("Enter the number of centroids: "))
    # Store the clusters, which will be candidate modes
    centroids, freq = mcmc.detailed_clustering(X, ncent, ban_U)
    freq = freq / 100.
    # 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], ban_U, ban_gradU, eta=0.001)):
            print("MODE FOUND: centroid number ", i)

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

    for i in range(d):
        plt.subplot(d, 1, i + 1)
        plt.scatter(centroids[:, i], freq, marker="*", color='green')
        plt.grid(True)