src.core.utils module

src.core.utils.build_model(theta: list[Tensor], model, input_dim: int) Module[source]

Build a model instance from the provided parameters.

Parameters:
  • theta (list[torch.Tensor]) – List of model parameters.

  • model_cls (Callable[[int], nn.Module]) – Model class to be instantiated.

  • input_dim (int) – Input dimension of the model.

Returns:

Model instance with the provided parameters.

Return type:

nn.Module

src.core.utils.evaluate_model(name: str, model: Module, X_eval: ndarray, y_eval: ndarray) float[source]

Evaluate the model on the provided evaluation dataset.

Parameters:
  • model (nn.Module) – Model instance to be evaluated.

  • X_eval (np.ndarray) – Evaluation dataset features.

  • y_eval (np.ndarray) – Evaluation dataset labels.

Returns:

Accuracy of the model on the evaluation dataset.

Return type:

float

Raises:

ValueError – If the model is not in evaluation mode.

src.core.utils.exp_delay(num_workers: int, scale: float = 0.0001) None[source]
src.core.utils.l1_norm(w: ndarray) float[source]
src.core.utils.l2_norm(w: ndarray) float[source]
src.core.utils.parse_args()[source]

Parse command line arguments. User will have to choose the amount of overparametrization between 110%, 150% and 200%. :param overparam: Percentage of features vs samples. :return: Parsed arguments.

src.core.utils.set_seed(seed: int)[source]
src.core.utils.sgd_training(X_train, y_train, num_epochs=10000, criterion=MSELoss(), batch_size=10, lr=0.01, tol=1e-08)[source]
src.core.utils.sparsity_ratio(w: ndarray) float[source]

L1/L2 ratio: higher → more diffuse weights, lower → more concentrated.

src.core.utils.weight_kurtosis(w)[source]