예제 #1
0
def standardize_all_data():
    # Standardize all data
    # Let data's mean = 0
    # standardard deviation = 1
    # If data are not loaded, this function will load data first
    # Once all data are standardized,
    # function get_trajectory will return standardized data
    if config.STANDARDIZED is True:
        return get_trajectory()
    if config.ALL_TRAJECTORY is None:
        # Load data set
        get_trajectory()

    data = config.ALL_TRAJECTORY
    mean = data_mean()
    std = data_std()

    for i in range(len(data)):
        data[i] = list(data[i])
        # First two elements are matadata, 3rd is data
        data[i][3] = (data[i][3] - mean) / std
        data[i] = tuple(data[i])

    config.ALL_TRAJECTORY = data
    config.STANDARDIZED = True

    return get_trajectory()
예제 #2
0
def fft_all_data():
    if config.ALL_COMPLEX_DATA is not None:
        return config.ALL_COMPLEX_DATA
    if config.TRIM_LENGTH is None:
        raise Exception("Trim length has not been setted up!")

    trimed = trim_data(get_trajectory())
    trimedf = fft_data(trimed)
    config.ALL_COMPLEX_DATA = trimedf

    return trimedf
예제 #3
0
def data_std():
    if config.DATA_STD is not None:
        return config.DATA_STD

    data = get_trajectory()

    data = np.concatenate(data, axis=0)
    std = data.std(axis=0)

    config.DATA_STD = std

    return std
예제 #4
0
def data_mean():
    if config.DATA_MEAN is not None:
        return config.DATA_MEAN

    data = get_trajectory()

    data = np.concatenate(data, axis=0)
    mean = data.mean(axis=0)

    config.DATA_MEAN = mean

    return mean
예제 #5
0
def get_random_example(n, trim_length, trimed=True, standardize=True):
    if standardize:
        data = standardize_all_data()
    else:
        data = get_trajectory()

    if trimed:
        data = trim_data(data, length=trim_length)

    examples = random.choices(data, k=n)

    return examples
예제 #6
0
def data_pca(n_cp=None):
    if config.PCA is not None:
        return config.PCA

    if config.STANDARDIZED is False:
        raise Exception("Standardize data before PCA!")

    data = get_trajectory()
    X = np.concatenate(data, axis=0)

    pca = PCA(n_components=n_cp)
    pca.fit(X)

    config.PCA = pca

    return pca
예제 #7
0

# %%
def autocorr(x):
    result = np.correlate(x, x, mode='full')
    return result[int(result.size / 2) - 10:]


def drawfft(y):
    yf = fft(y)
    x = fftfreq(len(y), 1 / 100)
    return x, yf


# %%
adam_e = get_trajectory(name='Adam', emotion='e')
adam_i = get_trajectory(name='Adam', emotion='i')
Bonn_e = get_trajectory(name='Bonn', emotion='e')
Bonn_i = get_trajectory(name='Bonn', emotion='i')

n = get_trajectory(emotion='n')
I = get_trajectory(emotion='i')
e = get_trajectory(emotion='e')

alll = get_trajectory()

# %%
plt.figure(figsize=(100, 10))
plt.plot(np.array(adam_e[0]['RVx']))

# %%