import numpy as np
import theano
import theano.tensor as T
theano.config.floatX = 'float32'

from utils import load_train_subjects, load_test_subjects

train_data, train_targets, train_labels = load_train_subjects([4])


rank = 2

all_subject_labels = train_labels

unique_subject_labels, label_associations = np.unique(
    all_subject_labels, return_inverse=True)

rng = np.random.RandomState(42)
init_time_components = (
    rng.rand(rank, train_data.shape[-1]) - 0.5
    ).astype(np.float32)[np.newaxis] * \
    np.ones([len(unique_subject_labels), 1, 1])

init_sensor_components = (
    rng.rand(rank, train_data.shape[1]) - 0.5
    ).astype(np.float32)[np.newaxis] * \
    np.ones([len(unique_subject_labels), 1, 1])

init_offsets = np.zeros(len(unique_subject_labels))

time_components = theano.shared(init_time_components,
Ejemplo n.º 2
0
from sklearn.externals.joblib import Memory
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score
from sklearn.pipeline import make_pipeline
from utils import load_train_subjects, load_test_subjects

import matplotlib.pyplot as plt



mem = Memory(cachedir="cache", verbose=10)
load_train_subjects = mem.cache(load_train_subjects)
load_test_subjects = mem.cache(load_test_subjects)

all_train_data, all_train_targets, all_train_labels = load_train_subjects()
all_test_data, all_test_labels = load_test_subjects()

val_idx = np.where(all_train_labels == 16)[0]
all_val_data = all_train_data[val_idx]
all_val_targets = all_train_targets[val_idx]
all_val_labels = all_train_labels[val_idx]

train_idx = np.where(all_train_labels < 15)[0]
all_train_data = all_train_data[train_idx]
all_train_targets = all_train_targets[train_idx]
all_train_labels = all_train_labels[train_idx]

X_train = all_train_data
y_train = all_train_targets
X_val = all_val_data