29 namespace experimental {
37 Param* default_params)
override {
45 std::vector<std::string> param_names;
46 std::vector<double> init_vals;
47 std::vector<double> lower_bounds;
48 std::vector<double> upper_bounds;
50 if (opt_params->
params.empty()) {
52 "No optimization parameters were selected. Please check your "
53 "parameter configuration.");
56 for (
auto* el : opt_params->
params) {
60 "ParticleSwarm::operator()",
61 "Encountered non-ParticleSwarmParam type optimization parameter: ",
65 param_names.push_back(opt_param->GetParamName());
66 init_vals.push_back(opt_param->initial_value);
67 lower_bounds.push_back(opt_param->lower_bound);
68 upper_bounds.push_back(opt_param->upper_bound);
70 arma::vec inout(init_vals);
71 optim::algo_settings_t settings;
72 settings.vals_bound =
true;
73 settings.lower_bounds = arma::vec(lower_bounds);
74 settings.upper_bounds = arma::vec(upper_bounds);
77 auto max_it = settings.pso_n_gen;
86 auto fit = [=, &dispatch_experiment, &iteration, &prev_mse, &min_mse,
87 &best_params, &lock](
const arma::vec& free_params,
88 arma::vec* grad_out,
void* opt_data) {
89 Param new_param = *default_params;
91 std::cout <<
"iteration (" << iteration <<
"/" << max_it <<
")"
96 for (
auto& p : free_params) {
98 return prev_mse +
static_cast<real_t>(0.005);
106 std::cout <<
"FP: " << free_params << std::endl;
107 for (
auto* opt_param : opt_params->
params) {
108 j_patch[opt_param->GetGroupName()][opt_param->GetParamName()] =
113 std::cout << j_patch << std::endl;
118 std::cout <<
" MSE " << mse <<
" inout " << free_params << std::endl;
120 std::lock_guard<Spinlock> lock_guard(lock);
128 best_params = j_patch;
135 if (!optim::pso(inout, fit,
nullptr, settings)) {
136 Log::Fatal(
"",
"Optimization algorithm didn't complete successfully.");
139 std::cout <<
"Best params = " << best_params << std::endl;