void Energy::train() { try{ cout<<"A:\n"<<A<<endl; cout<<"b:\n"<<b<<endl; /*** linear least squares ***/ la::matrix<double> AT = la::trans(A); la::matrix<double> ATA = la::prod(AT,A); la::vector<double> ATb = la::prod(AT,b); la::permutation_matrix<int> pm(ATA.size1()); la::lu_factorize(ATA,pm); la::vector<double> c(ATb); lu_substitute(ATA, pm, c); la::vector<double> est = la::prod(A,c); /*** set coeffficients ***/ set_coefficients(c); /* cout<<"A:\n"<<print_matrix(A)<<endl; cout<<"b:\n"<<print_matrix(b)<<endl; cout<<"AT:\n"<<print_matrix(AT)<<endl; cout<<"ATA:\n"<<print_matrix(ATA)<<endl; cout<<"ATb:\n"<<print_matrix(ATb)<<endl; cout<<"ATA - after:\n"<<print_matrix(ATA)<<endl; cout<<"c:\n"<<print_matrix(c)<<endl; cout<<"est:\n"<<print_matrix(est)<<endl; */ cout<<"TRAINING DONE"<<endl; } catch(...) { cout<<"WARNING: Training fail, will stil write matices to octave file"<<endl; } cout<<"Done writting to octave file"<<endl; }
void MSC::train() { /*** linear least squares ***/ try{ la::matrix<double> AT = la::trans(A); la::matrix<double> ATA = la::prod(AT,A); la::vector<double> ATb = la::prod(AT,b); la::permutation_matrix<int> pm(ATA.size1()); la::lu_factorize(ATA,pm); la::vector<double> c(ATb); lu_substitute(ATA, pm, c); la::vector<double> est = la::prod(A,c); /*** set coeffficients ***/ set_coefficients(c); cout<<"A:\n"<<print_matrix(A)<<endl; cout<<"b:\n"<<print_matrix(b)<<endl; cout<<"AT:\n"<<print_matrix(AT)<<endl; cout<<"ATA:\n"<<print_matrix(ATA)<<endl; cout<<"ATb:\n"<<print_matrix(ATb)<<endl; cout<<"ATA - after:\n"<<print_matrix(ATA)<<endl; cout<<"c:\n"<<print_matrix(c)<<endl; cout<<"est:\n"<<print_matrix(est)<<endl; cout<<"TRAINING DONE"<<endl; } catch(...) { cout<<"WARNING: Training failed! Writting matrices to octave file\n"; } return; }
auto run_simulation(const wayverb::core::geo::box& boundary, const util::aligned::vector<glm::vec3>& receivers, const wayverb::waveguide::coefficients_canonical& coefficients) const { const auto scene_data = wayverb::core::geo::get_scene_data( boundary, wayverb::core::make_surface<wayverb::core::simulation_bands>( 0, 0)); auto mesh = wayverb::waveguide::compute_mesh( cc_, make_voxelised_scene_data( scene_data, 5, wayverb::waveguide::compute_adjusted_boundary( wayverb::core::geo::compute_aabb( scene_data.get_vertices()), source_position_, divisions_)), divisions_, speed_of_sound); mesh.set_coefficients({coefficients}); const auto source_index = compute_index(mesh.get_descriptor(), source_position_); const auto input = [&] { const util::aligned::vector<float> raw_input{1.0f}; auto ret = wayverb::waveguide::make_transparent( raw_input.data(), raw_input.data() + raw_input.size()); ret.resize(steps, 0); return ret; }(); auto prep = wayverb::waveguide::preprocessor::make_soft_source( source_index, input.begin(), input.end()); auto output_holders = util::map_to_vector( begin(receivers), end(receivers), [&](auto i) { const auto receiver_index{ compute_index(mesh.get_descriptor(), i)}; if (!wayverb::waveguide::is_inside(mesh, receiver_index)) { throw std::runtime_error{ "receiver is outside of mesh!"}; } return wayverb::core::callback_accumulator< wayverb::waveguide::postprocessor::node> { receiver_index }; }); util::progress_bar pb{}; wayverb::waveguide::run( cc_, mesh, prep, [&](auto& queue, const auto& buffer, auto step) { for (auto& i : output_holders) { i(queue, buffer, step); } set_progress(pb, step, steps); }, true); return util::map_to_vector( begin(output_holders), end(output_holders), [](const auto& i) { return i.get_output(); }); }