1 /*-------------------------------------------------------------------------------------*/
2 /*  NOMAD - Nonlinear Optimization by Mesh Adaptive Direct search - version 3.7.2      */
3 /*                                                                                     */
4 /*  Copyright (C) 2001-2015  Mark Abramson        - the Boeing Company, Seattle        */
5 /*                           Charles Audet        - Ecole Polytechnique, Montreal      */
6 /*                           Gilles Couture       - Ecole Polytechnique, Montreal      */
7 /*                           John Dennis          - Rice University, Houston           */
8 /*                           Sebastien Le Digabel - Ecole Polytechnique, Montreal      */
9 /*                           Christophe Tribes    - Ecole Polytechnique, Montreal      */
10 /*                                                                                     */
11 /*  funded in part by AFOSR and Exxon Mobil                                            */
12 /*                                                                                     */
13 /*  Author: Sebastien Le Digabel                                                       */
14 /*                                                                                     */
15 /*  Contact information:                                                               */
16 /*    Ecole Polytechnique de Montreal - GERAD                                          */
17 /*    C.P. 6079, Succ. Centre-ville, Montreal (Quebec) H3C 3A7 Canada                  */
18 /*    e-mail: nomad@gerad.ca                                                           */
19 /*    phone : 1-514-340-6053 #6928                                                     */
20 /*    fax   : 1-514-340-5665                                                           */
21 /*                                                                                     */
22 /*  This program is free software: you can redistribute it and/or modify it under the  */
23 /*  terms of the GNU Lesser General Public License as published by the Free Software   */
24 /*  Foundation, either version 3 of the License, or (at your option) any later         */
25 /*  version.                                                                           */
26 /*                                                                                     */
27 /*  This program is distributed in the hope that it will be useful, but WITHOUT ANY    */
28 /*  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A    */
29 /*  PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.   */
30 /*                                                                                     */
31 /*  You should have received a copy of the GNU Lesser General Public License along     */
32 /*  with this program. If not, see <http://www.gnu.org/licenses/>.                     */
33 /*                                                                                     */
34 /*  You can find information on the NOMAD software at www.gerad.ca/nomad               */
35 /*-------------------------------------------------------------------------------------*/
36 /**
37   \file   TGP_Model_Search.hpp
38   \brief  TGP Model search (headers)
39   \author Sebastien Le Digabel
40   \date   2011-02-17
41   \see    TGP_Model_Search.cpp
42 */
43 #ifdef USE_TGP
44 
45 #ifndef __TGP_MODEL_SEARCH__
46 #define __TGP_MODEL_SEARCH__
47 
48 #include "LH_Search.hpp"
49 #include "TGP_Model_Evaluator.hpp"
50 
51 namespace NOMAD {
52 
53   /// Model search.
54   class TGP_Model_Search : public NOMAD::Search , private NOMAD::Uncopyable {
55 
56   private:
57 
58     NOMAD::TGP_Model * _model;
59 
60     NOMAD::Model_Stats _one_search_stats;   ///< Stats for one search.
61     NOMAD::Model_Stats _all_searches_stats; ///< Stats for all searches.
62 
63     /// Delete a list of points.
64     /**
65        \param pts The points -- \b IN/OUT.
66     */
67     static void clear_pts ( std::vector<NOMAD::Point *> & pts );
68 
69     /// Delete a list of evaluation points.
70     /**
71        \param pts The points -- \b IN/OUT.
72     */
73     static void clear_pts ( std::vector<NOMAD::Eval_Point *> & pts );
74 
75     /// Model construction.
76     /**
77        \param  cache          Cache of true evaluations                 -- \b IN.
78        \param  incumbent      The incumbent                             -- \b IN.
79        \param  delta_m        Mesh size parameter                       -- \b IN.
80        \param  out            The NOMAD::Display object                 -- \b IN.
81        \param  display_degree Display degree                            -- \b IN.
82        \param  display_lim    Max number of pts when sets are displayed -- \b IN.
83        \param  stats          Model search stats                        -- \b IN/OUT.
84        \param  compute_Ds2x   Flag to enable/disable Ds2x computation   -- \b OUT.
85        \param  XX             The set of prediction points              -- \b OUT.
86        \param  stop           Stop flag                                 -- \b OUT.
87        \param  stop_reason    Stop reason                               -- \b OUT.
88        \param  error_std      Error string                              -- \b OUT.
89        \return A boolean equal to \c true if the model has been constructed.
90     */
91     bool model_construction ( const NOMAD::Cache               & cache          ,
92 			      const NOMAD::Point               & incumbent      ,
93 			      const NOMAD::Point               & delta_m        ,
94 			      const NOMAD::Display             & out            ,
95 			      NOMAD::dd_type                     display_degree ,
96 			      int                                display_lim    ,
97 			      NOMAD::Stats                     & stats          ,
98 			      bool                             & compute_Ds2x   ,
99 			      std::vector<NOMAD::Eval_Point *> & XX             ,
100 			      bool                             & stop           ,
101 			      NOMAD::stop_type                 & stop_reason    ,
102 			      std::string                      & error_str        );
103 
104     /// Create a list of prediction points.
105     /**
106        \param  cache     Cache of true evaluations    -- \b IN.
107        \param  n         Number of variables          -- \b IN.
108        \param  m         Number of outputs            -- \b IN.
109        \param  incumbent The incumbent                -- \b IN.
110        \param  delta_m   Mesh size parameter          -- \b IN.
111        \param  XX        The set of prediction points -- \b OUT.
112     */
113     void set_XX ( const NOMAD::Cache               & cache     ,
114 		  int                                n         ,
115 		  int                                m         ,
116 		  const NOMAD::Point               & incumbent ,
117 		  const NOMAD::Point               & delta_m   ,
118 		  std::vector<NOMAD::Eval_Point *> & XX          ) const;
119 
120     /// Create the complete list of trial points (oracle + Ds2x + improv).
121     /**
122        \param oracle_pts     Oracle points              -- \b IN.
123        \param Ds2x_pts       Ds2x points                -- \b IN.
124        \param improv_pts     Improv points              -- \b IN.
125        \param incumbent      The incumbent              -- \b IN.
126        \param max_pts        Max number of trial points -- \b IN.
127        \param out            The NOMAD::Display object  -- \b IN.
128        \param display_degree Display degree             -- \b IN.
129        \param trial_pts      The list of trial points   -- \b OUT.
130      */
131     void create_trial_pts
132     ( const std::vector<NOMAD::Point *> & oracle_pts     ,
133       const std::vector<NOMAD::Point *> & Ds2x_pts       ,
134       const std::vector<NOMAD::Point *> & improv_pts     ,
135       const NOMAD::Point                & incumbent      ,
136       int                                 max_pts        ,
137       const NOMAD::Display              & out            ,
138       NOMAD::dd_type                      display_degree ,
139       std::vector<NOMAD::Point *>       & trial_pts        ) const;
140 
141     /// Create oracle points by optimizing the model.
142     /**
143        \param  cache          Cache of true evaluations                 -- \b IN.
144        \param  incumbent      The incumbent                             -- \b IN.
145        \param  delta_m        Mesh size parameter                       -- \b IN.
146        \param  out            The NOMAD::Display object                 -- \b IN.
147        \param  display_degree Display degree                            -- \b IN.
148        \param  display_lim    Max number of pts when sets are displayed -- \b IN.
149        \param  XX             The set of prediction points              -- \b IN.
150        \param  oracle_pts     Oracle candidates points                  -- \b OUT.
151        \param  stop           Stop flag                                 -- \b OUT.
152        \param  stop_reason    Stop reason                               -- \b OUT.
153        \return A boolean equal to \c true oracle points are proposed.
154     */
155     bool create_oracle_pts
156     ( const NOMAD::Cache                     & cache          ,
157       const NOMAD::Point                     & incumbent      ,
158       const NOMAD::Point                     & delta_m        ,
159       const NOMAD::Display                   & out            ,
160       NOMAD::dd_type                           display_degree ,
161       int                                      display_lim    ,
162       const std::vector<NOMAD::Eval_Point *> & XX             ,
163       std::vector<NOMAD::Point *>            & oracle_pts     ,
164       bool                                   & stop           ,
165       NOMAD::stop_type                       & stop_reason      );
166 
167     /// Model optimization.
168     /**
169        \param x0s            The three starting points -- \b IN.
170        \param out            The NOMAD::Display object -- \b IN.
171        \param display_degree Display degree            -- \b IN.
172        \param xf             Feasible solution \c xf   -- \b OUT.
173        \param xi             Infeasible solution \c xi -- \b OUT.
174        \param stop           Stop flag                 -- \b OUT.
175        \param stop_reason    Stop reason               -- \b OUT.
176     */
177     bool optimize_model ( const NOMAD::Eval_Point * x0s[3]         ,
178 			  const NOMAD::Display    & out            ,
179 			  NOMAD::dd_type            display_degree ,
180 			  NOMAD::Point           *& xf             ,
181 			  NOMAD::Point           *& xi             ,
182 			  bool                    & stop           ,
183 			  NOMAD::stop_type        & stop_reason      );
184 
185     /// Project and accept or reject an oracle trial point.
186     /**
187        \param  cache          Cache of true evaluations -- \b IN.
188        \param  incumbent      The incumbent             -- \b IN.
189        \param  delta_m        Mesh size parameter       -- \b IN.
190        \param  out            The NOMAD::Display object -- \b IN.
191        \param  display_degree Display degree            -- \b IN.
192        \param  x              The oracle point         -- \b IN/OUT.
193        \return A boolean equal to \c true if the point is accepted.
194     */
195     bool check_oracle_point
196     ( const NOMAD::Cache   & cache          ,
197       const NOMAD::Point   & incumbent      ,
198       const NOMAD::Point   & delta_m        ,
199       const NOMAD::Display & out            ,
200       NOMAD::dd_type         display_degree ,
201       NOMAD::Point         & x                );
202 
203     /// Insert a trial point in the evaluator control object.
204     /**
205        \param x              The point coordinates               -- \b IN.
206        \param signature      Signature                           -- \b IN.
207        \param incumbent      The incumbent                       -- \b IN.
208        \param display_degree Display degree                      -- \b IN.
209        \param ev_control     The NOMAD::Evaluator_Control object -- \b IN/OUT.
210     */
211     void register_point ( NOMAD::Point               x              ,
212 			  NOMAD::Signature         & signature      ,
213 			  const NOMAD::Point       & incumbent      ,,
214 			  NOMAD::dd_type             display_degree ,
215 			  NOMAD::Evaluator_Control & ev_control       ) const;
216 
217     /// Create the list of improv points.
218     /**
219        These points (from the set \c XX) maximize
220          the expected improvement of the objective.
221        Priority is given to predicted feasible points.
222        \param  XX            The set of prediction points              -- \b IN.
223        \param incumbent      The incumbent                             -- \b IN.
224        \param max_pts        Max number of points                      -- \b IN.
225        \param out            The NOMAD::Display object                 -- \b IN.
226        \param display_degree Display degree                            -- \b IN.
227        \param display_lim    Max number of pts when sets are displayed -- \b IN.
228        \param Ds2x_pts       The list of improv points                 -- \b OUT.
229     */
230     void create_improv_pts
231     ( const std::vector<NOMAD::Eval_Point *> & XX             ,
232       const NOMAD::Point                     & incumbent      ,
233       int                                      max_pts        ,
234       const NOMAD::Display                   & out            ,
235       NOMAD::dd_type                           display_degree ,
236       int                                      display_lim    ,
237       std::vector<NOMAD::Point *>            & improv_pts       ) const;
238 
239     /// Create the list of Ds2x points.
240     /**
241        These points (from the set \c XX) maximize the expected reduction in
242          predictive variance for each output.
243        \param  XX            The set of prediction points              -- \b IN.
244        \param out            The NOMAD::Display object                 -- \b IN.
245        \param display_degree Display degree                            -- \b IN.
246        \param display_lim    Max number of pts when sets are displayed -- \b IN.
247        \param Ds2x_pts       The list of Ds2x points                   -- \b OUT.
248     */
249     void create_Ds2x_pts
250     ( const std::vector<NOMAD::Eval_Point *> & XX             ,
251       const NOMAD::Display                   & out            ,
252       NOMAD::dd_type                           display_degree ,
253       int                                      display_lim    ,
254       std::vector<NOMAD::Point *>            & Ds2x_pts         ) const;
255 
256     /// Prediction at one point.
257     /**
258        \param  x The point     -- \b IN.
259        \param  h Value of \c h -- \b OUT.
260        \param  f Value of \c f -- \b OUT.
261        \return A boolean equal to \c true if the prediction was possible.
262     */
263     bool predict ( const NOMAD::Point & x ,
264 		   NOMAD::Double      & h ,
265 		   NOMAD::Double      & f   ) const;
266 
267     /// Display the prediction error for the evaluated points.
268     /**
269        \param evaluated_pts List of evaluated points  -- \b IN.
270        \param out           The NOMAD::Display object -- \b IN.
271     */
272     void display_eval_pred_errors
273     ( const std::list<const NOMAD::Eval_Point *> & evaluated_pts ,
274       const NOMAD::Display                       & out             );
275 
276     /*----------------------------------------------------------------------*/
277 
278   public:
279 
280     /// Constructor.
281     /**
282        \param p Parameters -- \b IN.
283     */
TGP_Model_Search(NOMAD::Parameters & p)284     TGP_Model_Search ( NOMAD::Parameters & p )
285       : NOMAD::Search ( p , NOMAD::MODEL_SEARCH ) , _model ( NULL ) {}
286 
287     /// Destructor.
~TGP_Model_Search(void)288     virtual ~TGP_Model_Search ( void ) { reset(); }
289 
290     /// Reset.
291     virtual void reset ( void );
292 
293     /// The TGP model search.
294     /**
295        Based on quadratic regression/MFN interpolation models.
296        \param mads           NOMAD::Mads object invoking this search -- \b IN/OUT.
297        \param nb_search_pts  Number of generated search points       -- \b OUT.
298        \param stop           Stop flag                               -- \b IN/OUT.
299        \param stop_reason    Stop reason                             -- \b OUT.
300        \param success        Type of success                         -- \b OUT.
301        \param count_search   Count or not the search                 -- \b OUT.
302        \param new_feas_inc   New feasible incumbent                  -- \b IN/OUT.
303        \param new_infeas_inc New infeasible incumbent                -- \b IN/OUT.
304     */
305     virtual void search ( NOMAD::Mads              & mads           ,
306 			  int                      & nb_search_pts  ,
307 			  bool                     & stop           ,
308 			  NOMAD::stop_type         & stop_reason    ,
309 			  NOMAD::success_type      & success        ,
310 			  bool                     & count_search   ,
311 			  const NOMAD::Eval_Point *& new_feas_inc   ,
312 			  const NOMAD::Eval_Point *& new_infeas_inc   );
313 
314     /// Access to the model.
315     /**
316        \return The model.
317     */
get_model(void) const318     NOMAD::TGP_Model * get_model ( void ) const { return _model; }
319 
320     //// Display stats.
321     /**
322        \param out The NOMAD::Display object -- \b IN.
323     */
display(const NOMAD::Display & out) const324     virtual void display ( const NOMAD::Display & out ) const
325     {
326       out << _all_searches_stats;
327     }
328   };
329 }
330 
331 #endif
332 #endif
333