Skip to content

Commit 8b364f8

Browse files
committed
Allow user to specify if distributional parameters are initialized
1 parent 1989658 commit 8b364f8

29 files changed

Lines changed: 285 additions & 39 deletions

lightgbmlss/distributions/Beta.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,25 @@ class Beta(DistributionClass):
2929
Loss function. Options are "nll" (negative log-likelihood) or "crps" (continuous ranked probability score).
3030
Note that if "crps" is used, the Hessian is set to 1, as the current CRPS version is not twice differentiable.
3131
Hence, using the CRPS disregards any variation in the curvature of the loss function.
32+
initialize: bool
33+
Whether to initialize the distributional parameters with unconditional start values. Initialization can help
34+
to improve speed of convergence in some cases. However, it may also lead to early stopping or suboptimal
35+
solutions if the unconditional start values are far from the optimal values.
3236
"""
3337
def __init__(self,
3438
stabilization: str = "None",
3539
response_fn: str = "exp",
36-
loss_fn: str = "nll"
40+
loss_fn: str = "nll",
41+
initialize: bool = False,
3742
):
3843

3944
# Input Checks
4045
if stabilization not in ["None", "MAD", "L2"]:
4146
raise ValueError("Invalid stabilization method. Please choose from 'None', 'MAD' or 'L2'.")
4247
if loss_fn not in ["nll", "crps"]:
4348
raise ValueError("Invalid loss function. Please choose from 'nll' or 'crps'.")
49+
if not isinstance(initialize, bool):
50+
raise ValueError("Invalid initialize. Please choose from True or False.")
4451

4552
# Specify Response Functions
4653
response_functions = {"exp": exp_fn, "softplus": softplus_fn}
@@ -63,5 +70,6 @@ def __init__(self,
6370
stabilization=stabilization,
6471
param_dict=param_dict,
6572
distribution_arg_names=list(param_dict.keys()),
66-
loss_fn=loss_fn
73+
loss_fn=loss_fn,
74+
initialize=initialize,
6775
)

lightgbmlss/distributions/Cauchy.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,25 @@ class Cauchy(DistributionClass):
2929
Loss function. Options are "nll" (negative log-likelihood) or "crps" (continuous ranked probability score).
3030
Note that if "crps" is used, the Hessian is set to 1, as the current CRPS version is not twice differentiable.
3131
Hence, using the CRPS disregards any variation in the curvature of the loss function.
32+
initialize: bool
33+
Whether to initialize the distributional parameters with unconditional start values. Initialization can help
34+
to improve speed of convergence in some cases. However, it may also lead to early stopping or suboptimal
35+
solutions if the unconditional start values are far from the optimal values.
3236
"""
3337
def __init__(self,
3438
stabilization: str = "None",
3539
response_fn: str = "exp",
36-
loss_fn: str = "nll"
40+
loss_fn: str = "nll",
41+
initialize: bool = False,
3742
):
3843

3944
# Input Checks
4045
if stabilization not in ["None", "MAD", "L2"]:
4146
raise ValueError("Invalid stabilization method. Please choose from 'None', 'MAD' or 'L2'.")
4247
if loss_fn not in ["nll", "crps"]:
4348
raise ValueError("Invalid loss function. Please choose from 'nll' or 'crps'.")
49+
if not isinstance(initialize, bool):
50+
raise ValueError("Invalid initialize. Please choose from True or False.")
4451

4552
# Specify Response Functions
4653
response_functions = {"exp": exp_fn, "softplus": softplus_fn}
@@ -63,5 +70,6 @@ def __init__(self,
6370
stabilization=stabilization,
6471
param_dict=param_dict,
6572
distribution_arg_names=list(param_dict.keys()),
66-
loss_fn=loss_fn
73+
loss_fn=loss_fn,
74+
initialize=initialize,
6775
)

lightgbmlss/distributions/Expectile.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,16 @@ class Expectile(DistributionClass):
2525
List of expectiles in increasing order.
2626
penalize_crossing: bool
2727
Whether to include a penalty term to discourage crossing of expectiles.
28+
initialize: bool
29+
Whether to initialize the distributional parameters with unconditional start values. Initialization can help
30+
to improve speed of convergence in some cases. However, it may also lead to early stopping or suboptimal
31+
solutions if the unconditional start values are far from the optimal values.
2832
"""
2933
def __init__(self,
3034
stabilization: str = "None",
3135
expectiles: List = [0.1, 0.5, 0.9],
3236
penalize_crossing: bool = False,
37+
initialize: bool = False,
3338
):
3439

3540
# Input Checks
@@ -41,6 +46,8 @@ def __init__(self,
4146
raise ValueError("Expectiles must be between 0 and 1.")
4247
if not isinstance(penalize_crossing, bool):
4348
raise ValueError("penalize_crossing must be a boolean. Please choose from True or False.")
49+
if not isinstance(initialize, bool):
50+
raise ValueError("Invalid initialize. Please choose from True or False.")
4451

4552
# Set the parameters specific to the distribution
4653
distribution = Expectile_Torch
@@ -61,7 +68,8 @@ def __init__(self,
6168
distribution_arg_names=list(param_dict.keys()),
6269
loss_fn="nll",
6370
tau=torch.tensor(expectiles),
64-
penalize_crossing=penalize_crossing
71+
penalize_crossing=penalize_crossing,
72+
initialize=initialize,
6573
)
6674

6775

lightgbmlss/distributions/Gamma.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,25 @@ class Gamma(DistributionClass):
2929
Loss function. Options are "nll" (negative log-likelihood) or "crps" (continuous ranked probability score).
3030
Note that if "crps" is used, the Hessian is set to 1, as the current CRPS version is not twice differentiable.
3131
Hence, using the CRPS disregards any variation in the curvature of the loss function.
32+
initialize: bool
33+
Whether to initialize the distributional parameters with unconditional start values. Initialization can help
34+
to improve speed of convergence in some cases. However, it may also lead to early stopping or suboptimal
35+
solutions if the unconditional start values are far from the optimal values.
3236
"""
3337
def __init__(self,
3438
stabilization: str = "None",
3539
response_fn: str = "exp",
36-
loss_fn: str = "nll"
40+
loss_fn: str = "nll",
41+
initialize: bool = False,
3742
):
3843

3944
# Input Checks
4045
if stabilization not in ["None", "MAD", "L2"]:
4146
raise ValueError("Invalid stabilization method. Please choose from 'None', 'MAD' or 'L2'.")
4247
if loss_fn not in ["nll", "crps"]:
4348
raise ValueError("Invalid loss function. Please choose from 'nll' or 'crps'.")
49+
if not isinstance(initialize, bool):
50+
raise ValueError("Invalid initialize. Please choose from True or False.")
4451

4552
# Specify Response Functions
4653
response_functions = {"exp": exp_fn, "softplus": softplus_fn}
@@ -63,5 +70,6 @@ def __init__(self,
6370
stabilization=stabilization,
6471
param_dict=param_dict,
6572
distribution_arg_names=list(param_dict.keys()),
66-
loss_fn=loss_fn
73+
loss_fn=loss_fn,
74+
initialize=initialize,
6775
)

lightgbmlss/distributions/Gaussian.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,25 @@ class Gaussian(DistributionClass):
2929
Loss function. Options are "nll" (negative log-likelihood) or "crps" (continuous ranked probability score).
3030
Note that if "crps" is used, the Hessian is set to 1, as the current CRPS version is not twice differentiable.
3131
Hence, using the CRPS disregards any variation in the curvature of the loss function.
32+
initialize: bool
33+
Whether to initialize the distributional parameters with unconditional start values. Initialization can help
34+
to improve speed of convergence in some cases. However, it may also lead to early stopping or suboptimal
35+
solutions if the unconditional start values are far from the optimal values.
3236
"""
3337
def __init__(self,
3438
stabilization: str = "None",
3539
response_fn: str = "exp",
36-
loss_fn: str = "nll"
40+
loss_fn: str = "nll",
41+
initialize: bool = False,
3742
):
3843

3944
# Input Checks
4045
if stabilization not in ["None", "MAD", "L2"]:
4146
raise ValueError("Invalid stabilization method. Please choose from 'None', 'MAD' or 'L2'.")
4247
if loss_fn not in ["nll", "crps"]:
4348
raise ValueError("Invalid loss function. Please choose from 'nll' or 'crps'.")
49+
if not isinstance(initialize, bool):
50+
raise ValueError("Invalid initialize. Please choose from True or False.")
4451

4552
# Specify Response Functions
4653
response_functions = {"exp": exp_fn, "softplus": softplus_fn}
@@ -63,5 +70,6 @@ def __init__(self,
6370
stabilization=stabilization,
6471
param_dict=param_dict,
6572
distribution_arg_names=list(param_dict.keys()),
66-
loss_fn=loss_fn
73+
loss_fn=loss_fn,
74+
initialize=initialize,
6775
)

lightgbmlss/distributions/Gumbel.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,25 @@ class Gumbel(DistributionClass):
2929
Loss function. Options are "nll" (negative log-likelihood) or "crps" (continuous ranked probability score).
3030
Note that if "crps" is used, the Hessian is set to 1, as the current CRPS version is not twice differentiable.
3131
Hence, using the CRPS disregards any variation in the curvature of the loss function.
32+
initialize: bool
33+
Whether to initialize the distributional parameters with unconditional start values. Initialization can help
34+
to improve speed of convergence in some cases. However, it may also lead to early stopping or suboptimal
35+
solutions if the unconditional start values are far from the optimal values.
3236
"""
3337
def __init__(self,
3438
stabilization: str = "None",
3539
response_fn: str = "exp",
36-
loss_fn: str = "nll"
40+
loss_fn: str = "nll",
41+
initialize: bool = False,
3742
):
3843

3944
# Input Checks
4045
if stabilization not in ["None", "MAD", "L2"]:
4146
raise ValueError("Invalid stabilization method. Please choose from 'None', 'MAD' or 'L2'.")
4247
if loss_fn not in ["nll", "crps"]:
4348
raise ValueError("Invalid loss function. Please choose from 'nll' or 'crps'.")
49+
if not isinstance(initialize, bool):
50+
raise ValueError("Invalid initialize. Please choose from True or False.")
4451

4552
# Specify Response Functions
4653
response_functions = {"exp": exp_fn, "softplus": softplus_fn}
@@ -63,5 +70,6 @@ def __init__(self,
6370
stabilization=stabilization,
6471
param_dict=param_dict,
6572
distribution_arg_names=list(param_dict.keys()),
66-
loss_fn=loss_fn
73+
loss_fn=loss_fn,
74+
initialize=initialize,
6775
)

lightgbmlss/distributions/Laplace.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,25 @@ class Laplace(DistributionClass):
2929
Loss function. Options are "nll" (negative log-likelihood) or "crps" (continuous ranked probability score).
3030
Note that if "crps" is used, the Hessian is set to 1, as the current CRPS version is not twice differentiable.
3131
Hence, using the CRPS disregards any variation in the curvature of the loss function.
32+
initialize: bool
33+
Whether to initialize the distributional parameters with unconditional start values. Initialization can help
34+
to improve speed of convergence in some cases. However, it may also lead to early stopping or suboptimal
35+
solutions if the unconditional start values are far from the optimal values.
3236
"""
3337
def __init__(self,
3438
stabilization: str = "None",
3539
response_fn: str = "exp",
36-
loss_fn: str = "nll"
40+
loss_fn: str = "nll",
41+
initialize: bool = False,
3742
):
3843

3944
# Input Checks
4045
if stabilization not in ["None", "MAD", "L2"]:
4146
raise ValueError("Invalid stabilization method. Please choose from 'None', 'MAD' or 'L2'.")
4247
if loss_fn not in ["nll", "crps"]:
4348
raise ValueError("Invalid loss function. Please choose from 'nll' or 'crps'.")
49+
if not isinstance(initialize, bool):
50+
raise ValueError("Invalid initialize. Please choose from True or False.")
4451

4552
# Specify Response Functions
4653
response_functions = {"exp": exp_fn, "softplus": softplus_fn}
@@ -63,5 +70,6 @@ def __init__(self,
6370
stabilization=stabilization,
6471
param_dict=param_dict,
6572
distribution_arg_names=list(param_dict.keys()),
66-
loss_fn=loss_fn
73+
loss_fn=loss_fn,
74+
initialize=initialize,
6775
)

lightgbmlss/distributions/LogNormal.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,25 @@ class LogNormal(DistributionClass):
2929
Loss function. Options are "nll" (negative log-likelihood) or "crps" (continuous ranked probability score).
3030
Note that if "crps" is used, the Hessian is set to 1, as the current CRPS version is not twice differentiable.
3131
Hence, using the CRPS disregards any variation in the curvature of the loss function.
32+
initialize: bool
33+
Whether to initialize the distributional parameters with unconditional start values. Initialization can help
34+
to improve speed of convergence in some cases. However, it may also lead to early stopping or suboptimal
35+
solutions if the unconditional start values are far from the optimal values.
3236
"""
3337
def __init__(self,
3438
stabilization: str = "None",
3539
response_fn: str = "exp",
36-
loss_fn: str = "nll"
40+
loss_fn: str = "nll",
41+
initialize: bool = False,
3742
):
3843

3944
# Input Checks
4045
if stabilization not in ["None", "MAD", "L2"]:
4146
raise ValueError("Invalid stabilization method. Please choose from 'None', 'MAD' or 'L2'.")
4247
if loss_fn not in ["nll", "crps"]:
4348
raise ValueError("Invalid loss function. Please choose from 'nll' or 'crps'.")
49+
if not isinstance(initialize, bool):
50+
raise ValueError("Invalid initialize. Please choose from True or False.")
4451

4552
# Specify Response Functions
4653
response_functions = {"exp": exp_fn, "softplus": softplus_fn}
@@ -63,5 +70,6 @@ def __init__(self,
6370
stabilization=stabilization,
6471
param_dict=param_dict,
6572
distribution_arg_names=list(param_dict.keys()),
66-
loss_fn=loss_fn
73+
loss_fn=loss_fn,
74+
initialize=initialize,
6775
)

lightgbmlss/distributions/Mixture.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,18 @@ class Mixture(MixtureDistributionClass):
6060
approaches infty, the mixing probabilities become more uniform. For more information we refer to
6161
6262
Jang, E., Gu, Shixiang and Poole, B. "Categorical Reparameterization with Gumbel-Softmax", ICLR, 2017.
63+
64+
initialize: bool
65+
Whether to initialize the distributional parameters with unconditional start values. Initialization can help
66+
to improve speed of convergence in some cases. However, it may also lead to early stopping or suboptimal
67+
solutions if the unconditional start values are far from the optimal values.
6368
"""
6469
def __init__(self,
6570
component_distribution: torch.distributions.Distribution,
6671
M: int = 2,
6772
hessian_mode: str = "individual",
68-
tau: float = 1.0
73+
tau: float = 1.0,
74+
initialize: bool = False,
6975
):
7076

7177
# Input Checks
@@ -86,6 +92,8 @@ def __init__(self,
8692
raise ValueError("tau must be a float.")
8793
if tau <= 0:
8894
raise ValueError("tau must be greater than 0.")
95+
if not isinstance(initialize, bool):
96+
raise ValueError("Invalid initialize. Please choose from True or False.")
8997

9098
# Set the parameters specific to the distribution
9199
param_dict = component_distribution.param_dict
@@ -105,5 +113,6 @@ def __init__(self,
105113
stabilization=component_distribution.stabilization,
106114
param_dict=param_dict,
107115
distribution_arg_names=distribution_arg_names,
108-
loss_fn=component_distribution.loss_fn
116+
loss_fn=component_distribution.loss_fn,
117+
initialize=initialize,
109118
)

lightgbmlss/distributions/NegativeBinomial.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,26 @@ class NegativeBinomial(DistributionClass):
3232
"sigmoid" (sigmoid).
3333
loss_fn: str
3434
Loss function. Options are "nll" (negative log-likelihood).
35+
initialize: bool
36+
Whether to initialize the distributional parameters with unconditional start values. Initialization can help
37+
to improve speed of convergence in some cases. However, it may also lead to early stopping or suboptimal
38+
solutions if the unconditional start values are far from the optimal values.
3539
"""
3640
def __init__(self,
3741
stabilization: str = "None",
3842
response_fn_total_count: str = "relu",
3943
response_fn_probs: str = "sigmoid",
40-
loss_fn: str = "nll"
44+
loss_fn: str = "nll",
45+
initialize: bool = False,
4146
):
4247

4348
# Input Checks
4449
if stabilization not in ["None", "MAD", "L2"]:
4550
raise ValueError("Invalid stabilization method. Please choose from 'None', 'MAD' or 'L2'.")
4651
if loss_fn not in ["nll"]:
4752
raise ValueError("Invalid loss function. Please select 'nll'.")
53+
if not isinstance(initialize, bool):
54+
raise ValueError("Invalid initialize. Please choose from True or False.")
4855

4956
# Specify Response Functions for total_count
5057
response_functions_total_count = {"exp": exp_fn, "softplus": softplus_fn, "relu": relu_fn}
@@ -75,5 +82,6 @@ def __init__(self,
7582
stabilization=stabilization,
7683
param_dict=param_dict,
7784
distribution_arg_names=list(param_dict.keys()),
78-
loss_fn=loss_fn
85+
loss_fn=loss_fn,
86+
initialize=initialize,
7987
)

0 commit comments

Comments
 (0)