Exemplo n.º 1
0
def get_3d_bundle(curves_in_bundle=2, random_state=1):
    Xdata = np.load('tract_5.npy')
    n, T, N = np.shape(Xdata)
    num_samples = curves_in_bundle
    np.random.RandomState(random_state)
    perm = np.random.permutation(N)[:num_samples]
    Xdata = Xdata[:, :, perm]

    # Reformat Xdata
    qmean, pmean, pmean_scaled, reformatted_Xdata, qarr, alpha_t_arr, gamma_arr = get_data_mean(
        Xdata, subject_first=False)
    reformatted_Xdata = np.array(reformatted_Xdata)
    N, n, T = np.shape(reformatted_Xdata)

    # Form new_bundle
    new_bundle = np.zeros((N, n, T))
    for i in range(N):
        new_bundle[i:, :] = reformatted_Xdata[i]

    return new_bundle
Exemplo n.º 2
0
from pysrvf.tpca import tpca_from_mean
from pysrvf.main_mean import get_data_mean
import numpy as np
from pysrvf.geodesic_utils import geodesic_flow
from pysrvf.generic_utils import q_to_curve, batch_q_to_curve, curve_to_q, batch_curve_to_q
import matplotlib.pyplot as plt

Xdata = np.load('../data/3d/tract_5.npy')
n, T, N = np.shape(Xdata)
num_samples = 20
perm = np.random.permutation(N)[:num_samples]
Xdata = np.transpose(Xdata, (2, 0, 1))
Xdata = Xdata[perm, :, :]

# get_data_mean(Xdata, subject_first = True, num_iter=15)
qmean, pmean, pmean_scaled, Xdata, qarr, alpha_t_arr, gamma_arr = get_data_mean(
    Xdata, subject_first=True, num_iter=2)


def recon_shape_from_eigen(qmean, alpha_t_arr, covdata, num_eig):
    U = covdata['U']
    Xproj = covdata['Xproj']
    G = covdata['G']
    Xtemp = np.zeros(alpha_t_arr.shape)

    stp = 10
    for ii in range(Xproj.shape[0]):
        Xproj_trunc = np.matmul(Xproj, U[:, :num_eig])
        ghpi = 0
        for jj in range(num_eig):
            gphi = ghpi + Xproj_trunc[ii, jj] * U[:, jj].T
Exemplo n.º 3
0
# Xdata = np.load('../data/1d/two_bumps.npy')
# qmean, pmean, pmean_scaled, reformatted_Xdatam _ = get_data_mean(Xdata)

### ----- 2d examples ----- ###
# Dog curves
# Shape is (N x n x T)
Xdata = np.load('../data/3d/tract_5.npy')
n, T, N = np.shape(Xdata)
num_samples = 100
perm = np.random.permutation(N)[:num_samples]
Xdata = Xdata[:, :, perm]

# Set subject_first = True if shape of data is (N, n, T)
# Set subject_first = False if shape of data is (n, T, N)

qmean, pmean, pmean_scaled, reformatted_Xdata, qarr, alpha_t_arr = get_data_mean(
    Xdata, subject_first=False)  # This changed

qarr_array = np.array(qarr)
alpha_t_arr_array = np.array(alpha_t_arr)
reformatted_Xdata_array = np.array(reformatted_Xdata)

# 2d parametric curves
# Shape is (n x T x N)
# Xdata = np.load('../data/2d/misc.npy')
# t = time.time()
# # do stuff
# qmean, pmean, pmean_scaled, reformatted_Xdata, _ = get_data_mean(Xdata, subject_first = False)
# print(time.time() - t)

### ----- 3d examples ----- ###
# Xdata = np.load('../data/3d/sine_curves.npy')
Exemplo n.º 4
0
import numpy as np
from pysrvf.main_mean import get_data_mean
import time
# from scipy.io import savemat

### ----- 1d examples ----- ###
# Bumps
# Shape is (N x T)
# Xdata = np.load('../data/1d/two_bumps.npy')
# qmean, pmean, pmean_scaled, reformatted_Xdatam _ = get_data_mean(Xdata)

### ----- 2d examples ----- ###
# Dog curves
# Shape is (N x n x T)
Xdata = np.load('../data/3d/sine_curves.npy')
qmean, pmean, pmean_scaled, reformatted_Xdata, qarr, alpha_t_arr = get_data_mean(
    Xdata)

# 2d parametric curves
# Shape is (n x T x N)
# Xdata = np.load('../data/2d/misc.npy')
# t = time.time()
# # do stuff
# qmean, pmean, pmean_scaled, reformatted_Xdata, _ = get_data_mean(Xdata, subject_first = False)
# print(time.time() - t)

### ----- 3d examples ----- ###
# Xdata = np.load('../data/3d/sine_curves.npy')
# qmean, pmean, pmean_scaled, reformatted_Xdata, _ = get_data_mean(Xdata)

### Plot data and mean ###
import matplotlib.pyplot as plt
Exemplo n.º 5
0
def tpca_from_data(X, num_iter=15):
    qmean, pmean, pmean_scaled, Xdata, qarr, alpha_t_arr, gamma_arr = get_data_mean(
        X, num_iter=num_iter)
    covdata = tpca_from_mean(qmean, alpha_t_arr)
    covdata['gamma_array'] = gamma_arr
    return covdata