GTMTT#

GTMTT Object#

class gtmx.GTMTimeSeries(s=2, group_size=5, l=0.01, map_shape: tuple = (10, 10), rbf_shape: tuple = (4, 4))#

GTM model for time series or sequential data

_init_vars(x: ndarray)#

data: flattened data points with shape (n_obs * seq_length, dimension)

calc_gamma(forward_alpha, backward_beta) ndarray#

gamma_t(i) = P(q_t = S_i | O, lambda) : shape = (T*K) the probability of being in state S_i in time t, given observe seq O and the model lambda

calc_xi(forward_alpha, backward_beta) ndarray#

Xi_t(i, j): the prob that being in state i at time t and state j at time t+1

fit(x: np.ndarray, y: np.ndarray | None = None, tol=10, epoch=10, early_stopping=False, verbose=True)#

fit the GTM through time model x is in shape (n_obs, seq_length, dim) the EM process will stop if the change of loglikelihood < tolerance (tol)

forward(obs: np.ndarray) [np.ndarray, np.ndarray]#

Generate alpha_T(N) obs is a single time-series in shape of (length, dimension)

m_step() bool#

To update the GTM model parameters which is constant across time steps.

M-step should be called after all time series have been evaluated.

new_plot_sample(index=None)#

Randomly draw a new sample for plots or manually set the sample index

plot(mode='mode', labels: ndarray = array([], dtype=float64), quiver=False, **kwargs)#

Plot a random time series sample into the latent space. :param mode: :type mode: ‘mean’ or ‘mode’ for two kinds of posterior :param labels: :type labels: current not useful :param quiver: :type quiver: shows the trajectory of latent space

plot_llh()#

Plot the training log-likelihood figure

sample() ndarray#

sample a single sequence in data space from the model distribution using spherical gaussian distribution in data space

sample_states() ndarray#

get a state sequence sample from a trained GTMTT model states are numbered as [0, 1, 2, …, num_states-1]

Returns ndarray: [i, j, k, ….. ] where i j k are hidden states

score(x)#

score the model performance using current log-likelihood

single_sequence_opt(obs: ndarray)#

Steps:

1. calc DIST and B
2. forward-backward
3. gamma
4. xi
5. llh & sums

This function only go through a single sequence. You are expected to call this function T times, where T is the number of time-series you have. And pass in a single sequence each time you call this function. After all sequences have been gone through, a M-step call must be followed.

start_vis_server()#

If called before training, a browser will be started and a sample of time series projected into latent space will be displayed on that page.