nemos.glm.GLM.initialize_params#

GLM.initialize_params(X, y, init_params=None)[source]#

Initialize the model parameters for the optimization process.

This method prepares the initializes model parameters if they are not provided. It is typically called before starting the optimization process to ensure that all necessary components and states are correctly configured.

Parameters:
  • X (Union[Array, FeaturePytree]) – The predictors used in the model fitting process. This can include feature matrices or other structures compatible with the model’s design.

  • y (Array) – The response variables or outputs corresponding to the predictors. Used to initialize parameters when they are not provided.

  • init_params (Optional[Tuple[Array, Array]]) – Initial parameters for the model. If not provided, they will be initialized based on the input data X and y.

Returns:

The initialized model parameters

Return type:

ModelParams

Raises:
  • ValueError – If params is not of length two.

  • ValueError – If dimensionality of init_params are not correct.

  • ValueError – If X is not two-dimensional.

  • ValueError – If y is not correct (1D for GLM, 2D for populationGLM).

  • TypeError – If params are not array-like when provided.

  • TypeError – If init_params[i] cannot be converted to jnp.ndarray for all i

Examples

>>> import numpy as np
>>> import nemos as nmo
>>> X, y = np.random.normal(size=(10, 2)), np.random.uniform(size=10)
>>> model = nmo.glm.GLM()
>>> params = model.initialize_params(X, y)
>>> opt_state = model.initialize_state(X, y, params)
>>> # Now ready to run optimization or update steps