def __init__(self, *args, time_lag=10, **kwargs): super().__init__(*args, **kwargs) self.time_lag = time_lag if time_lag > 0: self.model = tICA(n_components=self.n_latent, lag_time=time_lag) elif time_lag == 0: self.model = FastICA(n_components=self.n_latent, random_state=self.random_state) else: raise ValueError( "Time delay parameter must be greater than or equal to zero.")
def train_tica(X, num_hidden=10, time_lag=10, random_seed=None): """ Instantiate and fit a tICA model, and return a function that embeds additional datasets Inputs: - X : ndarray with shape (n_timepoints, t_lag, n_features) - num_hidden : int, the number of embedding coordinates - time_lag : int, the time lag to use to construct the embedding - random_seed : ignored Returns: - embed_func : a function that takes additional coordinates and embeds them """ tica = tICA(n_components=num_hidden, lag_time=time_lag) tica.fit([np.reshape(X, (X.shape[0], -1))]) embed_func = lambda y: tica.transform([np.reshape(y, (y.shape[0], -1))])[0] return embed_func