Example #1
0
def test_kmeanspp_six_samples_three_centers():
    X = np.array([[0.0, 1.0], [1.0, 0.0], [0.0, 0.0], [1.0, 1.0], [100.0, 0.0],
                  [0.0, 100.0]])
    centers = kmeansplusplus_initialization(X, 3, 0)
    assert_equal(len(centers), 3)
    assert_in(np.array([100.0, 0.0]), centers)
    assert_in(np.array([0.0, 100.0]), centers)
    assert_true(X[0] in centers or X[1] in centers or X[2] in centers
                or X[3] in centers)
Example #2
0
                           random_state=0)
X = X.transpose(2, 1, 0)
steps = X[:, :, 0].mean(axis=0)
expected_mean = X[:, :, 1].mean(axis=0)
expected_std = X[:, :, 1].std(axis=0)

n_demonstrations, n_steps, n_task_dims = X.shape
X_train = np.empty((n_demonstrations, n_steps, n_task_dims + 1))
X_train[:, :, 1:] = X
t = np.linspace(0, 1, n_steps)
X_train[:, :, 0] = t
X_train = X_train.reshape(n_demonstrations * n_steps, n_task_dims + 1)

random_state = check_random_state(0)
n_components = 4
initial_means = kmeansplusplus_initialization(X_train, n_components,
                                              random_state)
initial_covs = covariance_initialization(X_train, n_components)
bgmm = BayesianGaussianMixture(n_components=n_components,
                               max_iter=100).fit(X_train)
gmm = GMM(n_components=n_components,
          priors=bgmm.weights_,
          means=bgmm.means_,
          covariances=bgmm.covariances_,
          random_state=random_state)

plt.figure(figsize=(10, 5))
plt.subplot(121)
plt.title("Confidence Interval from GMM")

plt.plot(X[:, :, 0].T, X[:, :, 1].T, c="k", alpha=0.1)
Example #3
0
def test_kmeanspp_two_samples():
    X = np.array([[0.0, 1.0], [1.0, 0.0]])
    centers = kmeansplusplus_initialization(X, 1, 0)
    assert_in(centers[0], X)
Example #4
0
def test_kmeanspp_two_samples_two_centers():
    X = np.array([[0.0, 1.0], [1.0, 0.0]])
    centers = kmeansplusplus_initialization(X, 2, 0)
    assert_in(centers[0], X)
    assert_in(centers[1], X)
    assert_false(centers[0, 0] == centers[1, 0])
Example #5
0
def test_kmeanspp_one_sample():
    X = np.array([[0.0, 1.0]])
    centers = kmeansplusplus_initialization(X, 1, 0)
    assert_array_almost_equal(X, centers)