| @@ 110-163 (lines=54) @@ | ||
| 107 | ||
| 108 | return optuna.samplers.QMCSampler(**optimizer_kwargs) |
|
| 109 | ||
| 110 | @classmethod |
|
| 111 | def get_test_params(cls, parameter_set="default"): |
|
| 112 | """Return testing parameter settings for the optimizer.""" |
|
| 113 | from sklearn.datasets import load_iris |
|
| 114 | from sklearn.linear_model import LogisticRegression |
|
| 115 | ||
| 116 | from hyperactive.experiment.integrations import SklearnCvExperiment |
|
| 117 | ||
| 118 | # Test case 1: Halton sequence without scrambling |
|
| 119 | params = super().get_test_params(parameter_set) |
|
| 120 | params[0].update( |
|
| 121 | { |
|
| 122 | "qmc_type": "halton", |
|
| 123 | "scramble": False, |
|
| 124 | } |
|
| 125 | ) |
|
| 126 | ||
| 127 | # Test case 2: Sobol sequence with scrambling |
|
| 128 | X, y = load_iris(return_X_y=True) |
|
| 129 | lr_exp = SklearnCvExperiment( |
|
| 130 | estimator=LogisticRegression(random_state=42, max_iter=1000), X=X, y=y |
|
| 131 | ) |
|
| 132 | ||
| 133 | mixed_param_space = { |
|
| 134 | "C": (0.01, 100), # Continuous |
|
| 135 | "penalty": [ |
|
| 136 | "l1", |
|
| 137 | "l2", |
|
| 138 | ], # Categorical - removed elasticnet to avoid solver conflicts |
|
| 139 | "solver": ["liblinear", "saga"], # Categorical |
|
| 140 | } |
|
| 141 | ||
| 142 | params.append( |
|
| 143 | { |
|
| 144 | "param_space": mixed_param_space, |
|
| 145 | "n_trials": 16, # Power of 2 for better QMC properties |
|
| 146 | "experiment": lr_exp, |
|
| 147 | "qmc_type": "sobol", # Different sequence type |
|
| 148 | "scramble": True, # With scrambling for randomization |
|
| 149 | } |
|
| 150 | ) |
|
| 151 | ||
| 152 | # Test case 3: Different sampler configuration with same experiment |
|
| 153 | params.append( |
|
| 154 | { |
|
| 155 | "param_space": mixed_param_space, |
|
| 156 | "n_trials": 8, # Power of 2, good for QMC |
|
| 157 | "experiment": lr_exp, |
|
| 158 | "qmc_type": "halton", # Different QMC type |
|
| 159 | "scramble": False, |
|
| 160 | } |
|
| 161 | ) |
|
| 162 | ||
| 163 | return params |
|
| 164 | ||
| @@ 115-158 (lines=44) @@ | ||
| 112 | ||
| 113 | return optuna.samplers.NSGAIISampler(**optimizer_kwargs) |
|
| 114 | ||
| 115 | @classmethod |
|
| 116 | def get_test_params(cls, parameter_set="default"): |
|
| 117 | """Return testing parameter settings for the optimizer.""" |
|
| 118 | from sklearn.datasets import load_iris |
|
| 119 | from sklearn.ensemble import RandomForestClassifier |
|
| 120 | ||
| 121 | from hyperactive.experiment.integrations import SklearnCvExperiment |
|
| 122 | ||
| 123 | # Test case 1: Basic single-objective (inherits from base) |
|
| 124 | params = super().get_test_params(parameter_set) |
|
| 125 | params[0].update( |
|
| 126 | { |
|
| 127 | "population_size": 20, |
|
| 128 | "mutation_prob": 0.2, |
|
| 129 | "crossover_prob": 0.8, |
|
| 130 | } |
|
| 131 | ) |
|
| 132 | ||
| 133 | # Test case 2: Multi-objective with mixed parameter types |
|
| 134 | X, y = load_iris(return_X_y=True) |
|
| 135 | rf_exp = SklearnCvExperiment( |
|
| 136 | estimator=RandomForestClassifier(random_state=42), X=X, y=y |
|
| 137 | ) |
|
| 138 | ||
| 139 | mixed_param_space = { |
|
| 140 | "n_estimators": (10, 50), # Continuous integer |
|
| 141 | "max_depth": [3, 5, 7, None], # Mixed discrete/None |
|
| 142 | "criterion": ["gini", "entropy"], # Categorical |
|
| 143 | "min_samples_split": (2, 10), # Continuous integer |
|
| 144 | "bootstrap": [True, False], # Boolean categorical |
|
| 145 | } |
|
| 146 | ||
| 147 | params.append( |
|
| 148 | { |
|
| 149 | "param_space": mixed_param_space, |
|
| 150 | "n_trials": 15, # Smaller for faster testing |
|
| 151 | "experiment": rf_exp, |
|
| 152 | "population_size": 8, # Smaller population for testing |
|
| 153 | "mutation_prob": 0.1, |
|
| 154 | "crossover_prob": 0.9, |
|
| 155 | } |
|
| 156 | ) |
|
| 157 | ||
| 158 | return params |
|
| 159 | ||