flatironinstitute / nemos

NEural MOdelS, a statistical modeling framework for neuroscience.
https://nemos.readthedocs.io/
MIT License
72 stars 7 forks source link

Adding keyword arg to GLM for solver/regularizer #180

Closed BalzaniEdoardo closed 1 month ago

BalzaniEdoardo commented 1 month ago

Solver name should be added as keyword argument to GLM.

Regularizer can be passed as a string, or as a class. Default is UnRegularized, standard GLM.

Default for solver should be None and choose the default appropriately. Provide a nice table with the defaults for each regularizer. Raise an error if solver and regularizer are incompatible. Consider adding a flag that bypass the compatibility check (force_solver or something like that).

BalzaniEdoardo commented 1 month ago

Something like:

class BaseRegressor(Base, abc.ABC):

 def __init__(
      self,
      regularizer: str | Regularizer = "unregularized",
      solver: str = None

):

parse the regularizer and solver options

      # I think the parsing should just do string matching, so maybe we should add a class attribute to each regularizer 
      # that is the string equivalent 
      if not isinstance(regularizer, str):
           self._parse_options(regularizer=regularizer.name, solver=solver)

           # if no error returned, instantiate the solver because regularizer is already done
           self.solver = solver 
      else:
          self._parse_options(regularizer=regularize, solver=solver)

          # if no error raised, continue instantiating regularizer and solver 
          self.solver = solver # store the solver name so that it can be dynamically changed 

          self.regularizer = Regularizer(*kwargs) # instantiate instance

 def _parse_options(self, regularizer: str, solver: str):
      pass

 def _create_solver(*kwargs):
       # create solver would also need to parse the options just in case something changed 
       # create solver would get called by glm_fit() every time just in case changes have been made to the regularizer or the solver method
          return solver_run, solver_update, solver_init 
clewis7 commented 1 month ago

BaseRegressor Changes

TODO:

BalzaniEdoardo commented 1 month ago

Solved in #183