Exemplo n.º 1
0
def test_Kmeans_init():
    """Test Kmeans"""
    covset = generate_cov(20, 3)
    labels = np.array([0, 1]).repeat(10)

    # init
    km = Kmeans(2)

    # fit
    km.fit(covset)

    # fit with init
    km = Kmeans(2, init=covset[0:2])
    km.fit(covset)

    # fit with labels
    km.fit(covset, y=labels)

    # predict
    km.predict(covset)

    # transform
    km.transform(covset)

    # n_jobs
    km = Kmeans(2, n_jobs=2)
    km.fit(covset)
def test_Kmeans_transform():
    """Test transform of Kmeans"""
    covset = generate_cov(20, 3)
    km = Kmeans(2)
    km.fit(covset)
    km.transform(covset)
def test_Kmeans_fit_parallel():
    """Test Fit of Kmeans using paralell"""
    covset = generate_cov(20, 3)
    km = Kmeans(2, n_jobs=2)
    km.fit(covset)
def test_Kmeans_predict():
    """Test prediction of Kmeans"""
    covset = generate_cov(20, 3)
    km = Kmeans(2)
    km.fit(covset)
    km.predict(covset)
def test_Kmeans_fit_with_y():
    """Test Fit of Kmeans with a given y"""
    covset = generate_cov(20, 3)
    labels = np.array([0, 1]).repeat(10)
    km = Kmeans(2)
    km.fit(covset, y=labels)
def test_Kmeans_fit_with_init():
    """Test Fit of Kmeans wit matric initialization"""
    covset = generate_cov(20, 3)
    km = Kmeans(2, init=covset[0:2])
    km.fit(covset)
def test_Kmeans_fit():
    """Test Fit of Kmeans"""
    covset = generate_cov(20, 3)
    km = Kmeans(2)
    km.fit(covset)
def test_Kmeans_init():
    """Test init of Kmeans"""
    km = Kmeans(2)
Exemplo n.º 9
0
labels_base = copy.deepcopy(labels)
# Covariance Matrix transorm
off_cov_matrix = Covariances(estimator='lwf').transform(off_epochs_data)
# MDM model init and fit
mdm = MDM(metric=dict(mean='riemann', distance='riemann'))
mdm.fit(off_cov_matrix, labels)

# End of offline training

# EEG stream on the lab network
print("looking for an EEG stream...")
streams = resolve_stream('name', 'openvibeSignal')
# Create a new inlet to read from the stream
inlet = StreamInlet(streams[0])

kmeans = Kmeans(n_clusters=4)

time_window = timeWindowInit(inlet)
time_window_base = copy.deepcopy(time_window)
timeBase = time.time()

count = 0
time_array = []
while not keyboard.is_pressed('s'):
    time_window = copy.deepcopy(time_window_base)
    while time_window.shape[1] < 769:
        sample, timestamp = inlet.pull_sample()
        sample = np.array(sample)
        time_window = np.column_stack((time_window, sample))

    actualTime = time.time() - timeBase