From a11c5d7c391d939cb1459e82dc2de3cb93bf81e4 Mon Sep 17 00:00:00 2001 From: lisyarus Date: Sat, 16 Jan 2021 15:06:39 +0300 Subject: [PATCH] Neural animation tweaks --- examples/animation_2d.cpp | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/examples/animation_2d.cpp b/examples/animation_2d.cpp index cbff7c9e..a3571af7 100644 --- a/examples/animation_2d.cpp +++ b/examples/animation_2d.cpp @@ -682,7 +682,7 @@ struct animation_2d_app std::size_t train_iterations = 0; std::size_t const max_train_iterations = 1024*8; float const randomize_amplitude = 10.f; - static constexpr auto mutation_amplitude = [](float t){ return 10.f * geom::lerp(1.f, 0.01f, t); }; + static constexpr auto mutation_amplitude = [](float t){ return std::pow(10.f, 1.f + geom::lerp(0.f, -2.f, t)); }; float best_score = 0.f; bool const warm_start = false; @@ -1200,18 +1200,14 @@ void animation_2d_app::do_train() } std::vector> scores(population.size()); - std::atomic finished_count{0}; + std::vector> futures; for (std::size_t i = 0; i < population.size(); ++i) { - bg.dispatch([&, i, rng = rng]() mutable { + futures.push_back(bg.dispatch([&, i, rng = rng]() mutable { scores[i] = {eval_score(population[i], rng), i}; - ++finished_count; - }); + })); } - bg.wait(); - - if (finished_count.load() != population.size()) - throw std::runtime_error("bg.wait() didn't wait for all tasks to finish"); + bg.wait_all(futures.begin(), futures.end()).get(); std::sort(scores.begin(), scores.end(), [](auto const & p1, auto const & p2){ return p1.first > p2.first; });