Update main.py
Browse files
main.py
CHANGED
|
@@ -122,10 +122,10 @@ def run_optimizations_without_ml():
|
|
| 122 |
|
| 123 |
def run_genetic_algorithm():
|
| 124 |
print("Running Genetic Algorithm (GA)...")
|
| 125 |
-
population = [{k: random.choice(v) if isinstance(v, list) else random.uniform(*v) for k,v in OPTIMIZATION_SPACE.items()} for _ in range(
|
| 126 |
best_overall_individual = None
|
| 127 |
best_overall_fitness = -float('inf')
|
| 128 |
-
for _ in range(
|
| 129 |
fitnesses = [calculate_project_kpis(**ind)['irr'] for ind in population]
|
| 130 |
if max(fitnesses) > best_overall_fitness:
|
| 131 |
best_overall_fitness = max(fitnesses)
|
|
@@ -154,7 +154,7 @@ def run_bayesian_optimization():
|
|
| 154 |
@use_named_args(skopt_space)
|
| 155 |
def objective(**params):
|
| 156 |
return -calculate_project_kpis(**params)['irr']
|
| 157 |
-
res = gp_minimize(objective, skopt_space, n_calls=
|
| 158 |
best_params = {space.name: val for space, val in zip(skopt_space, res.x)}
|
| 159 |
kpis = calculate_project_kpis(**best_params)
|
| 160 |
return {"Method": "Bayesian Opt", **kpis, "Params": best_params}
|
|
@@ -171,7 +171,7 @@ def run_optuna_direct():
|
|
| 171 |
}
|
| 172 |
return calculate_project_kpis(**params)['irr']
|
| 173 |
study = optuna.create_study(direction="maximize")
|
| 174 |
-
study.optimize(objective, n_trials=
|
| 175 |
kpis = calculate_project_kpis(**study.best_params)
|
| 176 |
return {"Method": "Optuna (TPE - Direct)", **kpis, "Params": study.best_params}
|
| 177 |
|
|
|
|
| 122 |
|
| 123 |
def run_genetic_algorithm():
|
| 124 |
print("Running Genetic Algorithm (GA)...")
|
| 125 |
+
population = [{k: random.choice(v) if isinstance(v, list) else random.uniform(*v) for k,v in OPTIMIZATION_SPACE.items()} for _ in range(40)]
|
| 126 |
best_overall_individual = None
|
| 127 |
best_overall_fitness = -float('inf')
|
| 128 |
+
for _ in range(70):
|
| 129 |
fitnesses = [calculate_project_kpis(**ind)['irr'] for ind in population]
|
| 130 |
if max(fitnesses) > best_overall_fitness:
|
| 131 |
best_overall_fitness = max(fitnesses)
|
|
|
|
| 154 |
@use_named_args(skopt_space)
|
| 155 |
def objective(**params):
|
| 156 |
return -calculate_project_kpis(**params)['irr']
|
| 157 |
+
res = gp_minimize(objective, skopt_space, n_calls=80, random_state=42, n_initial_points=20)
|
| 158 |
best_params = {space.name: val for space, val in zip(skopt_space, res.x)}
|
| 159 |
kpis = calculate_project_kpis(**best_params)
|
| 160 |
return {"Method": "Bayesian Opt", **kpis, "Params": best_params}
|
|
|
|
| 171 |
}
|
| 172 |
return calculate_project_kpis(**params)['irr']
|
| 173 |
study = optuna.create_study(direction="maximize")
|
| 174 |
+
study.optimize(objective, n_trials=150, n_jobs=-1)
|
| 175 |
kpis = calculate_project_kpis(**study.best_params)
|
| 176 |
return {"Method": "Optuna (TPE - Direct)", **kpis, "Params": study.best_params}
|
| 177 |
|