Skip to content

Commit

Permalink
added comments
Browse files Browse the repository at this point in the history
Signed-off-by: Shashank Mittal <shashank.mittal.mec22@itbhu.ac.in>
  • Loading branch information
shashank-iitbhu committed Oct 10, 2024
1 parent 748e4ba commit 14f30a5
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions pkg/suggestion/v1beta1/hyperopt/base_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ def create_hyperopt_domain(self):
for param in self.search_space.params:
if param.type in [INTEGER, DOUBLE]:
if param.distribution == api_pb2.UNIFORM or param.distribution is None:
# Uniform distribution: values are sampled between min and max.
# If step is defined, we use the quantized version quniform.
if param.step:
hyperopt_search_space[param.name] = hyperopt.hp.quniformint(
hyperopt_search_space[param.name] = hyperopt.hp.uniformint(
param.name,
float(param.min),
float(param.max),
Expand All @@ -82,6 +84,9 @@ def create_hyperopt_domain(self):
param.name, float(param.min), float(param.max)
)
elif param.distribution == api_pb2.LOG_UNIFORM:
# Log-uniform distribution: used for parameters that vary exponentially.
# We convert min and max to their logarithmic scale using math.log, because
# the log-uniform distribution is applied over the logarithmic range.
if param.step:
hyperopt_search_space[param.name] = hyperopt.hp.qloguniform(
param.name,
Expand All @@ -96,8 +101,11 @@ def create_hyperopt_domain(self):
math.log(float(param.max)),
)
elif param.distribution == api_pb2.NORMAL:
# Normal distribution: used when values are centered around the mean (mu)
# and spread out by sigma. We calculate mu as the midpoint between
# min and max, and sigma as (max - min) / 6. This is based on the assumption
# that 99.7% of the values in a normal distribution fall within ±3 sigma.
mu = (float(param.min) + float(param.max)) / 2
# We consider the normal distribution based on the range of ±3 sigma.
sigma = (float(param.max) - float(param.min)) / 6

if param.step:
Expand All @@ -114,10 +122,14 @@ def create_hyperopt_domain(self):
sigma,
)
elif param.distribution == api_pb2.LOG_NORMAL:
# Log-normal distribution: applies when the logarithm
# of the parameter follows a normal distribution.
# We convert min and max to logarithmic scale and calculate
# mu and sigma similarly to the normal distribution,
# but on the log-transformed values to ensure the distribution is correct.
log_min = math.log(float(param.min))
log_max = math.log(float(param.max))
mu = (log_min + log_max) / 2
# We consider the normal distribution based on the range of ±3 sigma.
sigma = (log_max - log_min) / 6

if param.step:
Expand Down

0 comments on commit 14f30a5

Please sign in to comment.