Пример #1
0
def generate_templates_refactor(order=1, cov_list=None, **kwargs):
    kwargs['return_corrs'] = True

    T = kwargs['T']
    templates = []
    for n in range(order):
        print(n)

        if cov_list:
            kwargs['datagen'] = cov_list[n]

        _, next_template = tc.simulate_data(**kwargs)

        if n >= 1:
            expanded_corrmats_last = tc.vec2mat(templates[n - 1])
            expanded_corrmats_next = tc.vec2mat(next_template)

            K2 = expanded_corrmats_last.shape[0]**2

            next_template = np.zeros([K2, K2, T])

            for t in range(T):
                x_last = expanded_corrmats_last[:, :, t]
                x_next = expanded_corrmats_next[:, :, t]
                next_template[:, :, t] = np.kron(x_last, x_next)
            next_template = tc.mat2vec(next_template)

        templates.append(next_template)

    return templates
def generate_templates(order=1, **kwargs):
    kwargs['return_corrs'] = True
    _, next_template = tc.simulate_data(**kwargs)

    T = kwargs['T']
    templates = []
    for n in range(order - 1):
        templates.append(next_template)

        expanded_corrmats = tc.vec2mat(next_template)
        K2 = expanded_corrmats.shape[0]**2
        next_template = np.zeros([K2, K2, T])
        for t in range(T):
            x = np.atleast_2d(expanded_corrmats[:, :, t].ravel())
            next_template[:, :, t] = x * x.T
        next_template = tc.mat2vec(next_template)
    templates.append(next_template)
    return templates
Пример #3
0
"""
=============================
Simulate subject data
=============================

In this example, we simulate data

"""
# Code source: Lucy Owen
# License: MIT

# load timecorr
import timecorr as tc
import seaborn as sns

# simulate some data
data, corrs = tc.simulate_data(datagen='block', return_corrs=True, set_random_seed=True, S=1, T=100, K=10, B=5)

# calculate correlations  - returned squareformed
tc_vec_data = tc.timecorr(tc.simulate_data(), weights_function=tc.gaussian_weights, weights_params={'var': 5}, combine=tc.helpers.corrmean_combine)

# convert from vector to matrix format
tc_mat_data = tc.vec2mat(tc_vec_data)

# plot the 3 correlation matrices different timepoints

sns.heatmap(tc_mat_data[:, :, 48])
sns.heatmap(tc_mat_data[:, :, 50])
sns.heatmap(tc_mat_data[:, :, 52])

=============================

In this example, we calculate dynamic correlations

"""
# Code source: Lucy Owen
# License: MIT

# load timecorr and other packages
import timecorr as tc
import numpy as np


S = 1
T = 1000
K = 10
B = 5

# define your weights parameters
width = 100
laplace = {'name': 'Laplace', 'weights': tc.laplace_weights, 'params': {'scale': width}}

# calculate the dynamic correlation of the two datasets

subs_data_2 = tc.simulate_data(datagen='ramping', return_corrs=False, set_random_seed=1, S=S, T=T, K=K, B=B)

subs_data_1 = tc.simulate_data(datagen='ramping', return_corrs=False, set_random_seed=2, S=S, T=T, K=K, B=B)



wcorred_data = tc.wcorr(np.array(subs_data_1),  np.array(subs_data_2), weights=laplace['weights'](T))