GENERATIVE REPLAY#
Classes#
- class models.lora_prototype_utils.generative_replay.GaussianMixture(n_components, n_features, covariance_type='full', eps=1e-06, init_params='kmeans', mu_init=None, var_init=None)[source]#
Bases:
Module
Fits a mixture of k=1,..,K Gaussians to the input data (K is supplied via n_components). Input tensors are expected to be flat with dimensions (n: number of samples, d: number of features). The model then extends them to (n, 1, d). The model parametrization (mu, sigma) is stored as (1, k, d), probabilities are shaped (n, k, 1) if they relate to an individual sample, or (1, k, 1) if they assign membership probabilities to one of the mixture components.
- bic(x)[source]#
Bayesian information criterion for a batch of samples. :param x: torch.Tensor (n, d) or (n, 1, d)
- Returns:
float
- Return type:
bic
- fit(x, delta=0.001, n_iter=100, warm_start=False)[source]#
Fits model to the data. :param x: torch.Tensor (n, d) or (n, k, d)
- options:
delta: float n_iter: int warm_start: bool
- get_kmeans_mu(x, n_centers, init_times=50, min_delta=0.001)[source]#
Find an initial value for the mean. Requires a threshold min_delta for the k-means algorithm to stop iterating. The algorithm is repeated init_times often, after which the best centerpoint is returned. :param x: torch.FloatTensor (n, d) or (n, 1, d) :param init_times: init :param min_delta: int
- predict(x, probs=False)[source]#
Assigns input data to one of the mixture components by evaluating the likelihood under each. If probs=True returns normalized probabilities of class membership. :param x: torch.Tensor (n, d) or (n, 1, d) :param probs: bool
- Returns:
torch.Tensor (n, k) (or) y: torch.LongTensor (n)
- Return type:
p_k
- predict_proba(x)[source]#
Returns normalized probabilities of class membership. :param x: torch.Tensor (n, d) or (n, 1, d)
- Returns:
torch.LongTensor (n)
- Return type:
y
Functions#
- models.lora_prototype_utils.generative_replay.calculate_matmul(mat_a, mat_b)[source]#
Calculate matrix product of two matrics with mat_a[0] >= mat_b[0]. Bypasses torch.matmul to reduce memory footprint. :param mat_a: torch.Tensor (n, k, 1, d) :param mat_b: torch.Tensor (n, k, d, 1)
- models.lora_prototype_utils.generative_replay.calculate_matmul_n_times(n_components, mat_a, mat_b)[source]#
Calculate matrix product of two matrics with mat_a[0] >= mat_b[0]. Bypasses torch.matmul to reduce memory footprint. :param mat_a: torch.Tensor (n, k, 1, d) :param mat_b: torch.Tensor (1, k, d, d)