Commit 7bf56fa6 authored by Miroslav Shaltev's avatar Miroslav Shaltev
Browse files

HybridSearch is producing something in 2D

parent 66fa3100
......@@ -2972,6 +2972,7 @@ INT4 FStatNomad::DoSearch(Display out,vector<ExPoint> &epv,INT4 fstatsearchtype,
SCHybridSearch *hybrid_search = new SCHybridSearch ( p );
hybrid_search->Tiling(tiling);
hybrid_search->NumberPoints(var_HybridSearchPoints);
hybrid_search->Directions(directions);
printf("SET HYBRID SEARCH\n");
mads.set_user_search ( hybrid_search );
}
......@@ -3018,6 +3019,16 @@ INT4 FStatNomad::DoSearch(Display out,vector<ExPoint> &epv,INT4 fstatsearchtype,
FCHybridSearch hybrid_search ( p );
mads.set_user_search ( &hybrid_search );
}
if (HybridSearch()){
FCHybridSearch *hybrid_search = new FCHybridSearch ( p );
hybrid_search->Tiling(tiling);
hybrid_search->NumberPoints(var_HybridSearchPoints);
hybrid_search->Directions(directions);
printf("SET HYBRID SEARCH\n");
mads.set_user_search ( hybrid_search );
}
mads.run();
CacheIn(&ec->get_cache());
......@@ -3331,7 +3342,7 @@ XLALGetDetectorIDs(
} /* XLALGetDetectorIDs() */
void SCHybridSearch::search( Mads & mads, int &nb_search_pts, bool &stop, stop_type &stop_reason, success_type &success, bool &count_search, const Eval_Point *& new_feas_inc, const Eval_Point *& new_infeas_inc){
printf("ENTER HYBRID SEARCH!\n");
// printf("ENTER HYBRID SEARCH!\n");
new_feas_inc = new_infeas_inc = NULL;
nb_search_pts = 0;
success = UNSUCCESSFUL;
......@@ -3396,49 +3407,52 @@ void SCHybridSearch::search( Mads & mads, int &nb_search_pts, bool &stop, stop_t
LatticeTilingLocator *tloc = XLALCreateLatticeTilingLocator(tiling);
const UINT8 total = XLALTotalLatticeTilingPoints( itr );
printf("TLOC CREATED, n=%d.\n",n);
// printf("TLOC CREATED, n=%d.\n",n);
gsl_matrix *points = gsl_matrix_calloc(n,1);
for (INT4 i = 0; i < n; i++){
printf("%d:%.16f\n",i,(*x)[i].value());
gsl_matrix_set(points,i,0,(*x)[i].value());
// printf("%d:%.16f\n",i,(*x)[i].value()/directions.at(i).scale);
gsl_matrix_set(points,i,0,(*x)[i].value()/directions.at(i).scale);
}
printf("MATRIX SET DONE.\n");
gsl_matrix **nearest_points = NULL;
// printf("MATRIX SET DONE.\n");
gsl_matrix *nearest_points = NULL;
gsl_matrix *GAMAT( nearest_points, n, total );
gsl_matrix *GAMAT( nearest_points, n, np );
/*
for (INT4 i = 0; i < total; i++){
gsl_vector *tpoint = gsl_vector_alloc (n);
INT4 r = XLALNextLatticeTilingPoint( itr, tpoint );
printf("r: %d\n",r);
for (INT4 j = 0; j < n; j++) {
printf("%.16f",gsl_vector_get(tpoint,j));
printf("%.16f\t",gsl_vector_get(tpoint,j));
}
printf("\n");
gsl_vector_free(tpoint);
}
*/
XLALNearestLatticeTilingPoints (tloc, points, nearest_points, NULL);
XLALNearestLatticeTilingPoints (tloc, points, &nearest_points, NULL);
printf("EXIT HYBRID SEARCH\n!");
Eval_Point * tk = new Eval_Point;
tk->set ( 1 , 1 );
tk->set_signature ( signature );
// printf("NEAREST POINTS\n");
// xk:
double xk = (*new_feas_inc)[0].value();
if ( xk < 0 )
return;
(*tk)[0] = static_cast<int>(ceil(1.0/xk)) * xk - 1.0;
Evaluator_Control & ev_control = mads.get_evaluator_control();
for (INT4 i = 0; i < nearest_points->size2; i++) {
gsl_vector *cv = gsl_vector_alloc(n);
gsl_matrix_get_col(cv,nearest_points,i);
Eval_Point * tk = new Eval_Point;
tk->set ( n , 1 );
tk->set_signature ( signature );
// Evaluator_Control:
Evaluator_Control & ev_control = mads.get_evaluator_control();
for (INT4 j = 0; j < n; j++) {
(*tk)[j] = (directions.at(j).scale * gsl_vector_get(cv,j));
// printf("%.16f\t",gsl_vector_get(cv,j));
}
// printf("\n");
// add the new point to the ordered list of search trial points:
ev_control.add_eval_point ( tk ,
_p.out().get_search_dd() ,
false ,
......@@ -3447,6 +3461,20 @@ Eval_Point * tk = new Eval_Point;
Double() ,
Double() );
gsl_vector_free(cv);
}
// printf("EXIT HYBRID SEARCH\n");
// Evaluator_Control:
// add the new point to the ordered list of search trial points:
nb_search_pts = 1;
// evaluation:
......@@ -3466,6 +3494,152 @@ Eval_Point * tk = new Eval_Point;
}
void FCHybridSearch::search ( Mads &mads, int &nb_search_pts, bool &stop, stop_type &stop_reason, success_type &success, bool &count_search , const Eval_Point *& new_feas_inc, const Eval_Point *& new_infeas_inc ) {
// printf("ENTER HYBRID SEARCH!\n");
new_feas_inc = new_infeas_inc = NULL;
nb_search_pts = 0;
success = UNSUCCESSFUL;
count_search = !stop;
if ( stop ) {
return;
}
// initial display:
const Display &out = _p.out();
dd_type display_degree = out.get_search_dd();
if ( display_degree == FULL_DISPLAY ){
std::ostringstream oss;
oss << USER_SEARCH;
out << std::endl << open_block ( oss.str() ) << std::endl;
}
// the barriers:
Barrier & true_barrier = mads.get_true_barrier();
Barrier & sgte_barrier = mads.get_sgte_barrier();
const Barrier & active_barrier = mads.get_active_barrier();
// point x:
Double best_f;
bool x_feas = true;
const Eval_Point * x = active_barrier.get_best_feasible();
if ( x ) {
best_f = x->get_f();
}
else {
x = active_barrier.get_best_infeasible();
x_feas = false;
}
if ( !x ) {
if ( display_degree == FULL_DISPLAY ) {
out.close_block ( "end of HybridSearch (no incumbent)" );
}
return;
}
// get the signature:
Signature * signature = x->get_signature();
if ( !signature )
{
if ( display_degree == FULL_DISPLAY )
out.close_block ( "end of HybridSearch (no signature)" );
return;
}
int n = signature->get_n();
if ( n != x->size() ){
if ( display_degree == FULL_DISPLAY )
out.close_block ( "end of HybridSearch (incompatible signature)" );
return;
}
// template bank
LatticeTilingIterator *itr = XLALCreateLatticeTilingIterator( tiling, n );
LatticeTilingLocator *tloc = XLALCreateLatticeTilingLocator(tiling);
const UINT8 total = XLALTotalLatticeTilingPoints( itr );
// printf("TLOC CREATED, n=%d.\n",n);
gsl_matrix *points = gsl_matrix_calloc(n,1);
for (INT4 i = 0; i < n; i++){
// printf("%d:%.16f\n",i,(*x)[i].value()/directions.at(i).scale);
gsl_matrix_set(points,i,0,(*x)[i].value()/directions.at(i).scale);
}
// printf("MATRIX SET DONE.\n");
gsl_matrix *nearest_points = NULL;
gsl_matrix *GAMAT( nearest_points, n, np );
/*
for (INT4 i = 0; i < total; i++){
gsl_vector *tpoint = gsl_vector_alloc (n);
INT4 r = XLALNextLatticeTilingPoint( itr, tpoint );
printf("r: %d\n",r);
for (INT4 j = 0; j < n; j++) {
printf("%.16f\t",gsl_vector_get(tpoint,j));
}
printf("\n");
gsl_vector_free(tpoint);
}
*/
XLALNearestLatticeTilingPoints (tloc, points, &nearest_points, NULL);
// printf("NEAREST POINTS\n");
Evaluator_Control & ev_control = mads.get_evaluator_control();
for (INT4 i = 0; i < nearest_points->size2; i++) {
gsl_vector *cv = gsl_vector_alloc(n);
gsl_matrix_get_col(cv,nearest_points,i);
Eval_Point * tk = new Eval_Point;
tk->set ( n , 1 );
tk->set_signature ( signature );
for (INT4 j = 0; j < n; j++) {
(*tk)[j] = (directions.at(j).scale * gsl_vector_get(cv,j));
// printf("%.16f\t",gsl_vector_get(cv,j));
}
// printf("\n");
ev_control.add_eval_point ( tk ,
_p.out().get_search_dd() ,
false ,
Double() ,
Double() ,
Double() ,
Double() );
gsl_vector_free(cv);
}
// printf("EXIT HYBRID SEARCH\n");
// Evaluator_Control:
// add the new point to the ordered list of search trial points:
nb_search_pts = 1;
// evaluation:
new_feas_inc = new_infeas_inc = NULL;
ev_control.eval_list_of_points ( _type ,
mads.get_true_barrier() ,
mads.get_sgte_barrier() ,
mads.get_pareto_front() ,
stop ,
stop_reason ,
new_feas_inc ,
new_infeas_inc ,
success );
}
......@@ -398,10 +398,17 @@ public:
void NumberPoints(INT4 v){
np = v;
}
void Directions(std::vector<tDirection> v){
directions = v;
}
private:
LatticeTiling *tiling;
INT4 np;
std::vector<tDirection> directions;
};
class FCHybridSearch : public NOMAD::Search {
......@@ -409,11 +416,23 @@ public:
FCHybridSearch ( NOMAD::Parameters & p ):NOMAD::Search ( p , NOMAD::USER_SEARCH ) {}
~FCHybridSearch ( void ) {}
void search ( NOMAD::Mads & mads, int &nb_search_pts, bool &stop, NOMAD::stop_type &stop_reason, NOMAD::success_type &success, bool &count_search, const NOMAD::Eval_Point *& new_feas_inc, const NOMAD::Eval_Point *& new_infeas_inc);
void Tiling(LatticeTiling *v){
tiling = v;
};
}
void NumberPoints(INT4 v){
np = v;
}
void Directions(std::vector<tDirection> v){
directions = v;
}
private:
LatticeTiling *tiling;
INT4 np;
std::vector<tDirection> directions;
};
class FStatNomad {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment