GTM#

GTM Object#

class gtmx.GTMBase(s=2, l=0.001, map_shape=(16, 16), rbf_shape=(5, 5), pca=True)#

The original Generative Topographic Mapping (GTM) model by Bishop et al. 1998 Implemented with reference of GTM toolbox by Lain Strachan written in Matlab.

Parameters
  • s (int) – Scale factor of sigma

  • l (float) – Regulatory factor. Larger l can prevent singularity during training but decrease the model performance and may cause unexpected error.

  • map_shape (tuple) – The shape of latent space grid.

  • rbf_shape (tuple) – The shape of radial basis function grid.

  • pca (bool) – Flag for using PCA to initialize weights W.

_init_vars(x: ndarray)#

Initialize the hyperparameters related to training data.

Parameters

x (np.ndarray) – training data in shape (n_obs, dim)

_optimize() float#

A single optimizing step with the EM algorithm

calibrate()#

calibrate the R matrix after last optimize

fit(x, y=None, epoch=10, early_stopping=False, tol=10, verbose=True)#

train the model. y will not be used.

plot(mode='mode', label: None | np.ndarray = None, num_points=200)#

Label is for every point and in shape of (n_points, ) You might want to call np.repeat(label, n) to repeat every label n times

plot_llh()#

Plot the training log-likelihood figure

score(x)#

score the model performance using current log-likelihood

transform(x, y=None, mode='mode') ndarray#

Project the dataset into latent space.

Parameters
  • x (np.ndarray) – data vec with shape (n_obs, dim)

  • y (None) – placeholder

  • mode (str) – the posterior mode. It should be either ‘mode’ or ‘mean’

Returns

coors of points in shape (n, 2)

Return type

np.ndarray