lnccbrown / HSSM

Development of HSSM package
Other
82 stars 11 forks source link

[Refactor] How parameters are represented in HSSM #590

Closed digicosmos86 closed 4 weeks ago

digicosmos86 commented 1 month ago

This PR introduces a refactored Param class to represent parameter specifications in HSSM.

Before the refactor, Param was a single class that both accepts user inputs and performs internal processing, such as merging with default values and truncating priors, which made the code in the class very messy. Some of the functionalities also bled into the HSSM class, which bloated the class as well. The refactor aims to separate the concerns of the old Param class into multiple classes, each taking one responsibility of the Param class. This completely moves the concerns out of the HSSM class, making the main class much less bloated (even though there is still room for improvement).

The improvements are:

  1. A user-facing UserParam class, which is exported as hssm.Param, for storing user input. (closes #564)
  2. An internal Param class that defines some common functionalities for the parameter representation. (closes #560)
  3. Inheriting the Param class is the SimpleParam class, which handles the situation where the parameter is not a regression. Its subclass DefaultParam handles the situation where the prior is not specified in the non-regression case (where we do not truncate the prior). (closes #561)
  4. The RegressionParam class for handling the regression case (closes #562)
  5. A dict-like Params class for creating these params both from user specification, or defaults, or both. It also takes away some of the responsibilities of the HSSM class (closes #559)

Tests for all these new classes are under tests/param directory.

The refactor also removes "hierarchical" argument to HSSM, adding global_formula instead. (closes #431, #432)

Some other changes to other code files are necessary for this gigantic refactor to work, but most of the changes are under src/hssm/param.