MCPcopy Create free account
hub / github.com/davisking/dlib / set

Method set

dlib/global_optimization/global_function_search.cpp:616–662  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

614// ----------------------------------------------------------------------------------------
615
616 void function_evaluation_request::
617 set (
618 double y
619 )
620 {
621 DLIB_CASSERT(has_been_evaluated() == false);
622 std::lock_guard<std::mutex> lock(*info->m);
623
624 m_has_been_evaluated = true;
625
626
627 // move the evaluation from outstanding to complete
628 auto i = std::find(info->outstanding_evals.begin(), info->outstanding_evals.end(), req);
629 DLIB_CASSERT(i != info->outstanding_evals.end());
630 info->outstanding_evals.erase(i);
631 info->ub.add(function_evaluation(req.x,y));
632
633
634 // Now do trust region radius maintenance and keep track of the best objective
635 // values and all that.
636 if (req.was_trust_region_generated_request)
637 {
638 // Adjust trust region radius based on how good this evaluation
639 // was.
640 double measured_improvement = y-req.anchor_objective_value;
641 double rho = measured_improvement/std::abs(req.predicted_improvement);
642 //std::cout << "rho: "<< rho << std::endl;
643 //std::cout << "radius: "<< info->radius << std::endl;
644 if (rho < 0.25)
645 info->radius *= 0.5;
646 else if (rho > 0.75)
647 info->radius *= 2;
648 }
649
650 if (y > info->best_objective_value)
651 {
652 if (!req.was_trust_region_generated_request && length(req.x - info->best_x) > info->radius*1.001)
653 {
654 //std::cout << "reset radius because of big move, " << length(req.x - info->best_x) << " radius was " << info->radius << std::endl;
655 // reset trust region radius since we made a big move. Doing this will
656 // cause the radius to be reset to the size of the local region.
657 info->radius = 0;
658 }
659 info->best_objective_value = y;
660 info->best_x = req.x;
661 }
662 }
663
664// ----------------------------------------------------------------------------------------
665// ----------------------------------------------------------------------------------------

Callers

nothing calls this directly

Calls 7

absFunction · 0.85
eraseMethod · 0.80
function_evaluationClass · 0.70
lengthFunction · 0.50
beginMethod · 0.45
endMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected