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

Add spline variable to var_builder #15

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

zhengp0
Copy link
Member

@zhengp0 zhengp0 commented Jun 21, 2024

Add spline, spline_gpriors and spline_upriors arguments to VariableBuilder class.

When spline is None, VariableBuilder will generate instance of Variable class. Otherwise it will generate instance of SplineVariable.

When spline is not None, user can also pass in spline_gpriors and spline_upriors as the configuration for SplineGaussianPrior and SplineUniformPrior.

Configuration

This feature can greatly reduce the complexity of the configuration file when working with splines.

Before, we need to manually create spline bases and use them as if they are independent covariates. We will need to pre-know how many spline bases there are to create the configuration file.

var_builders:
- lam:
    age_mid: 10.0
    super_region_id: 1.0
  name: spline_0
  space: super_region_id*age_mid
- lam:
    age_mid: 10.0
    super_region_id: 1.0
  name: spline_1
  space: super_region_id*age_mid
- lam:
    age_mid: 10.0
    super_region_id: 1.0
  name: spline_2
  space: super_region_id*age_mid
...

And now with this feature, we don't have to create the spline bases outside of spxmod, it will generate the design matrix with in the encode function and therefore greatly reduce the configuration complexity

var_builders:
- lam:
    age_mid: 10.0
    super_region_id: 1.0
  name: year_id
  space: super_region_id*age_mid
  spline:
    knots: [1950, 1974.33, 1998.67, 2023]
    degree: 2
    l_linear: true
    r_linear: true

And we allow to add priors to regularize each spline define within the space.

var_builders:
- lam:
    age_mid: 10.0
    super_region_id: 1.0
  name: year_id
  space: super_region_id*age_mid
  spline:
    knots: [1950, 1974.33, 1998.67, 2023]
    degree: 2
    l_linear: true
    r_linear: true
  spline_gpriors:
    - size: 2
      order: 1
      domain_lb: 1950.0
      domain_ub: 1974.33
      domain_type: abs
      mean: 0.0
      sd: 0.01

Miscellaneous

  • added SparseParameter as the child of regmod.parameter.Parameter to collect the sparse prior matrix.
  • changed the __init__ function of SparseRegmodModel to automatically parse the dictionary input, but assume all models to only have one parameter which Gaussian, Binomial and Poisson models are.

@@ -38,25 +48,109 @@ def msca_optimize(
return result.x


class SparseParameter(Parameter):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could there be any reason to add SparseParameter directly to regmod?

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

Successfully merging this pull request may close these issues.

None yet

2 participants