Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model configuration redesign #70

Open
zhengp0 opened this issue Feb 17, 2023 · 2 comments
Open

Model configuration redesign #70

zhengp0 opened this issue Feb 17, 2023 · 2 comments

Comments

@zhengp0
Copy link
Member

zhengp0 commented Feb 17, 2023

Main objectives

  • Reduce the number of classes user need to interact with
  • Provide simpler and more intuitive model specification process
    • Minimalist interface, user only need to specific details when necessary
    • Build model layer by layer

Bonus objective

Capability of saving/loading a model to/from a human readable configuration file (yaml).

Idea

Use dictionary as the data structure to store model specifications.

Pros:

  • The first main objective can be achieved, user will only need to pass in dictionary
  • The bonus objective can be achieved, dictionary can be saved as a yaml file

Cons:

  • Dictionary is very flexible and lack of structure, make the validation steps complicated
  • To achieve the second main objective, we need to handle "simplified form" and "comprehensive form" of configuration file

Requires

Design dictionary configuration data structure ("simplified form", "comprehensive form") for

  • Priors
  • Variables
  • Parameters

Challenges

  • Classes are composite of each other, Variable contains Prior and Parameter contains both Variable and Prior
  • Variable have different transformation, spline and factor
  • Prior have different types, linear or not, Gaussian or Uniform
  • "Liquid" vs "Solid" model specification, this refers to the situation where we don't have literal information of what the class configuration going to be yet. For example we want the spline knots to be a function of the data, or we want to specify spline monotonicity prior before we know the spline.

Validate the model configuration

Challenges

  • Where, when and how?
@zhengp0
Copy link
Member Author

zhengp0 commented Feb 17, 2023

Here is a simple concept sketch:

from abc import ABC, abstractstaticmethod
from typing import Optional


class Model(ABC):
    def __init__(
        self,
        obs: str,
        pconfigs: dict[str, list[str] | dict],
        weights: Optional[str] = None,
    ) -> None:
        self.obs = obs
        self._pconfigs = self._get_init_pconfigs(pconfigs)
        self.weights = weights

        self.params = None

   @abstractstaticmethod
    def _get_init_pconfigs(pconfigs: dict[str, list[str] | dict]) -> dict:
        ...

    def update_param(self, pname: str, **settings) -> None:
        ...

    def update_variable(self, pname: str, vname: str, **settings):
        ...

    def add_prior(self, pname: str, vname: Optional[str] = None, **settings):
        ...

class GaussianModel(Model):
    def __init__(self, obs: str, mu: list[str] | dict, weights):
        super().__init__(obs, {"mu": mu}, weights)

   def  _get_init_pconfigs(pconfigs: dict[str, list[str] | dict]) -> dict:
        ...

model = GaussianModel("obs", mu=["intercept", "sdi", "age_group_id"])
model.update_param("mu", transformation="exp")
model.update_variable("mu", "sdi", transformation="spline", knots=[0.0, 0.5, 1.0], degree=3)
model.update_variable("mu", "age_group_id", transformation="factor")

Here we use list[str] as the "simplified format" of the configuration data structure for Parameter.

@zhengp0
Copy link
Member Author

zhengp0 commented Apr 27, 2023

We should fix the way we build the model, otherwise it will be complication for both user and developer. We should stick with the "simplified format".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant