Skip to content

Commit

Permalink
set default inducing_size to 99 everywhere in GPClassificationModels (#…
Browse files Browse the repository at this point in the history
…412)

Summary:
Pull Request resolved: #412

Inducing sizes for GPClassification Models (and it's children) had different defaults, dependent on whether they were initialized via the from_config class method or a normal __init__.

This is changed to always be the same, respecting the default as defined in the __init__.

Additionally, GPClassificationModels now use a default inducing_size of 99. This is because when inducing_size>=100 and the n>=100, model fitting takes extremely long. We warn the user when inducing_size is above 100.

Reviewed By: crasanders

Differential Revision: D64728394

fbshipit-source-id: 63d149e33ee92e63b07d93bfba5d388dadd8ba5a
  • Loading branch information
JasonKChow authored and facebook-github-bot committed Oct 22, 2024
1 parent 6c74be2 commit ba43914
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
19 changes: 14 additions & 5 deletions aepsych/models/gp_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(
mean_module: Optional[gpytorch.means.Mean] = None,
covar_module: Optional[gpytorch.kernels.Kernel] = None,
likelihood: Optional[Likelihood] = None,
inducing_size: int = 100,
inducing_size: Optional[int] = None,
max_fit_time: Optional[float] = None,
inducing_point_method: str = "auto",
):
Expand All @@ -69,7 +69,7 @@ def __init__(
gamma prior.
likelihood (gpytorch.likelihood.Likelihood, optional): The likelihood function to use. If None defaults to
Bernouli likelihood.
inducing_size (int): Number of inducing points. Defaults to 100.
inducing_size (int, optional): Number of inducing points. Defaults to 99.
max_fit_time (float, optional): The maximum amount of time, in seconds, to spend fitting the model. If None,
there is no limit to the fitting time.
inducing_point_method (string): The method to use to select the inducing points. Defaults to "auto".
Expand All @@ -80,7 +80,16 @@ def __init__(
"""
self.lb, self.ub, self.dim = _process_bounds(lb, ub, dim)
self.max_fit_time = max_fit_time
self.inducing_size = inducing_size
self.inducing_size = inducing_size or 99

if self.inducing_size >= 100:
logger.warning(
(
"inducing_size in GPClassificationModel is >=100, more inducing points "
"can lead to better fits but slower performance in general. Performance "
"at >=100 inducing points is especially slow."
)
)

if likelihood is None:
likelihood = BernoulliLikelihood()
Expand Down Expand Up @@ -130,7 +139,7 @@ def from_config(cls, config: Config) -> GPClassificationModel:
"""

classname = cls.__name__
inducing_size = config.getint(classname, "inducing_size", fallback=10)
inducing_size = config.getint(classname, "inducing_size", fallback=None)

lb = config.gettensor(classname, "lb")
ub = config.gettensor(classname, "ub")
Expand Down Expand Up @@ -310,7 +319,7 @@ def __init__(
mean_module: Optional[gpytorch.means.Mean] = None,
covar_module: Optional[gpytorch.kernels.Kernel] = None,
likelihood: Optional[Likelihood] = None,
inducing_size: int = 100,
inducing_size: Optional[int] = None,
max_fit_time: Optional[float] = None,
inducing_point_method: str = "auto",
):
Expand Down
4 changes: 2 additions & 2 deletions aepsych/models/monotonic_projection_gp.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(
mean_module: Optional[gpytorch.means.Mean] = None,
covar_module: Optional[gpytorch.kernels.Kernel] = None,
likelihood: Optional[Likelihood] = None,
inducing_size: int = 100,
inducing_size: Optional[int] = None,
max_fit_time: Optional[float] = None,
inducing_point_method: str = "auto",
):
Expand Down Expand Up @@ -189,7 +189,7 @@ def from_config(cls, config: Config) -> MonotonicProjectionGP:
"""

classname = cls.__name__
inducing_size = config.getint(classname, "inducing_size", fallback=10)
inducing_size = config.getint(classname, "inducing_size", fallback=None)

lb = config.gettensor(classname, "lb")
ub = config.gettensor(classname, "ub")
Expand Down
12 changes: 6 additions & 6 deletions aepsych/models/semi_p.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def __init__(
covar_module: Optional[gpytorch.kernels.Kernel] = None,
likelihood: Optional[Any] = None,
slope_mean: float = 2,
inducing_size: int = 100,
inducing_size: Optional[int] = None,
max_fit_time: Optional[float] = None,
inducing_point_method: str = "auto",
):
Expand All @@ -199,7 +199,7 @@ def __init__(
gamma prior.
likelihood (gpytorch.likelihood.Likelihood, optional): The likelihood function to use. If None defaults to
linear-Bernouli likelihood with probit link.
inducing_size (int): Number of inducing points. Defaults to 100.
inducing_size (int): Number of inducing points. Defaults to 99.
max_fit_time (float, optional): The maximum amount of time, in seconds, to spend fitting the model. If None,
there is no limit to the fitting time.
inducing_point_method (string): The method to use to select the inducing points. Defaults to "auto".
Expand Down Expand Up @@ -264,7 +264,7 @@ def from_config(cls, config: Config) -> SemiParametricGPModel:
"""

classname = cls.__name__
inducing_size = config.getint(classname, "inducing_size", fallback=100)
inducing_size = config.getint(classname, "inducing_size", fallback=None)

lb = config.gettensor(classname, "lb")
ub = config.gettensor(classname, "ub")
Expand Down Expand Up @@ -428,7 +428,7 @@ def __init__(
offset_covar_module: Optional[gpytorch.kernels.Kernel] = None,
likelihood: Optional[Likelihood] = None,
slope_mean: float = 2,
inducing_size: int = 100,
inducing_size: Optional[int] = None,
max_fit_time: Optional[float] = None,
inducing_point_method: str = "auto",
):
Expand All @@ -445,7 +445,7 @@ def __init__(
offset_mean_module (gpytorch.means.Mean, optional): Mean module to use (default: constant mean) for offset.
offset_covar_module (gpytorch.kernels.Kernel, optional): Covariance kernel to use (default: scaled RBF) for offset.
likelihood (gpytorch.likelihood.Likelihood, optional)): defaults to bernoulli with logistic input and a floor of .5
inducing_size (int): Number of inducing points. Defaults to 100.
inducing_size (int): Number of inducing points. Defaults to 99.
max_fit_time (float, optional): The maximum amount of time, in seconds, to spend fitting the model. If None,
there is no limit to the fitting time.
inducing_point_method (string): The method to use to select the inducing points. Defaults to "auto".
Expand Down Expand Up @@ -554,7 +554,7 @@ def from_config(cls, config: Config) -> HadamardSemiPModel:
"""

classname = cls.__name__
inducing_size = config.getint(classname, "inducing_size", fallback=100)
inducing_size = config.getint(classname, "inducing_size", fallback=None)

lb = config.gettensor(classname, "lb")
ub = config.gettensor(classname, "ub")
Expand Down
4 changes: 3 additions & 1 deletion tests/models/test_gp_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,9 @@ def test_hyperparam_consistency(self):
self.assertTrue(name1 == name2)
self.assertTrue(isinstance(parent1, type(parent2)))
self.assertTrue(isinstance(prior1, type(prior2)))
# no obvious way to test paramtransform equivalence
# no obvious way to test paramtransform equivalence)

self.assertTrue(m1.inducing_size == m2.inducing_size)


if __name__ == "__main__":
Expand Down

0 comments on commit ba43914

Please sign in to comment.