Skip to content

Commit

Permalink
Update code comment for categorical values
Browse files Browse the repository at this point in the history
  • Loading branch information
Furkan-rgb authored Nov 4, 2024
1 parent 8a1411c commit 915bdf4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions package/samplers/catcma/catcma.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,16 @@ def sample_relative(

for t in solution_trials[:popsize]:
assert t.value is not None, "completed trials must have a value"
# Convert Optuna's representation to cmaes.CatCma's internal representation.

# Convert numerical parameters
x = trans.transform({k: t.params[k] for k in numerical_search_space.keys()})

# Initialize c with the correct shape

# Convert categorial values to one-hot vectors.
# Example:
# choices = ['a', 'b', 'c']
# value = 'b'
# one_hot_vec = [False, True, False]
c = np.zeros((num_categorical_vars, max_num_choices))

for idx, k in enumerate(categorical_search_space.keys()):
Expand All @@ -223,7 +228,7 @@ def sample_relative(
c[idx, index] = 1

y = t.value if study.direction == StudyDirection.MINIMIZE else -t.value
solutions.append(((x, c), y))
solutions.append(((x, c), y)) # type: ignore

optimizer.tell(solutions)

Expand Down

0 comments on commit 915bdf4

Please sign in to comment.