1 /*  _______________________________________________________________________
2 
3     DAKOTA: Design Analysis Kit for Optimization and Terascale Applications
4     Copyright 2014-2020 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
5     This software is distributed under the GNU Lesser General Public License.
6     For more information, see the README file in the top Dakota directory.
7     _______________________________________________________________________ */
8 
9 //- Class:        PecosApproximation
10 //- Description:  Base Class for Pecos polynomial approximations
11 //-
12 //- Owner:        Mike Eldred
13 
14 #ifndef PECOS_APPROXIMATION_H
15 #define PECOS_APPROXIMATION_H
16 
17 #include "DakotaApproximation.hpp"
18 #include "DakotaVariables.hpp"
19 #include "RegressOrthogPolyApproximation.hpp"
20 
21 namespace Dakota {
22 
23 class SharedApproxData;
24 
25 
26 /// Derived approximation class for global basis polynomials.
27 
28 /** The PecosApproximation class provides a global approximation
29     based on basis polynomials.  This includes orthogonal polynomials
30     used for polynomial chaos expansions and interpolation polynomials
31     used for stochastic collocation. */
32 
33 class PecosApproximation: public Approximation
34 {
35 public:
36 
37   //
38   //- Heading: Constructor and destructor
39   //
40 
41   /// default constructor
42   PecosApproximation();
43   /// standard ProblemDescDB-driven constructor
44   PecosApproximation(ProblemDescDB& problem_db,
45 		     const SharedApproxData& shared_data,
46                      const String& approx_label);
47   /// alternate constructor
48   PecosApproximation(const SharedApproxData& shared_data);
49   /// destructor
50   ~PecosApproximation();
51 
52   //
53   //- Heading: Member functions
54   //
55 
56   /// set pecosBasisApprox.configOptions.expansionCoeffFlag
57   void expansion_coefficient_flag(bool coeff_flag);
58   /// get pecosBasisApprox.configOptions.expansionCoeffFlag
59   bool expansion_coefficient_flag() const;
60 
61   /// set pecosBasisApprox.configOptions.expansionGradFlag
62   void expansion_gradient_flag(bool grad_flag);
63   /// get pecosBasisApprox.configOptions.expansionGradFlag
64   bool expansion_gradient_flag() const;
65 
66   /// clear unused Sobol' indices
67   void clear_component_effects();
68   /// Performs global sensitivity analysis using Sobol' indices by
69   /// computing component (main and interaction) effects
70   void compute_component_effects();
71   /// Performs global sensitivity analysis using Sobol' indices by
72   /// computing total effects
73   void compute_total_effects();
74 
75   /// return polyApproxRep->sobolIndices
76   const Pecos::RealVector& sobol_indices() const;
77   /// return polyApproxRep->totalSobolIndices
78   const Pecos::RealVector& total_sobol_indices() const;
79 
80   /// return the number of non-zero coefficients for this QoI
81   size_t sparsity() const;
82   /// return RegressOrthogPolyApproximation::sparseSobolIndexMap
83   Pecos::ULongULongMap sparse_sobol_index_map() const;
84 
85   /// return OrthogPolyApproximation::decayRates
86   const Pecos::RealVector& dimension_decay_rates() const;
87 
88   /// invoke Pecos::PolynomialApproximation::allocate_arrays()
89   void allocate_arrays();
90 
91   /// initialize covariance accumulators with pointers to other QoI
92   void initialize_covariance(Approximation& approx_2);
93   /// clear covariance pointers to other QoI
94   void clear_covariance_pointers();
95   /// initialize covariance accumulators (also reinitialize after change
96   /// in stats type)
97   void initialize_products();
98   /// query whether product interpolants are defined (non-empty)
99   bool product_interpolants();
100 
101   /// return the mean of the expansion, where all active variables are random
102   Real mean();
103   /// return the mean of the expansion for a given parameter vector,
104   /// where a subset of the active variables are random
105   Real mean(const Pecos::RealVector& x);
106   /// return the mean of the combined expansion, treating all variables
107   /// as random
108   Real combined_mean();
109   /// return the mean of the combined expansion for a given parameter vector,
110   /// where a subset of the active variables are treated as random
111   Real combined_mean(const Pecos::RealVector& x);
112   /// return the gradient of the expansion mean for a given parameter
113   /// vector, where all active variables are random
114   const Pecos::RealVector& mean_gradient();
115   /// return the gradient of the expansion mean for a given parameter vector
116   /// and given DVV, where a subset of the active variables are random
117   const Pecos::RealVector& mean_gradient(const Pecos::RealVector& x,
118 					 const Pecos::SizetArray& dvv);
119 
120   /// return the variance of the expansion, where all active vars are random
121   Real variance();
122   /// return the variance of the expansion for a given parameter vector,
123   /// where a subset of the active variables are random
124   Real variance(const Pecos::RealVector& x);
125   /// return the gradient of the expansion variance for a given parameter
126   /// vector, where all active variables are random
127   const Pecos::RealVector& variance_gradient();
128   /// return the gradient of the expansion variance for a given parameter
129   /// vector and given DVV, where a subset of the active variables are random
130   const Pecos::RealVector& variance_gradient(const Pecos::RealVector& x,
131 					     const Pecos::SizetArray& dvv);
132 
133   /// return the covariance between two response expansions, treating
134   /// all variables as random
135   Real covariance(Approximation& approx_2);
136   /// return the covariance between two response expansions, treating
137   /// a subset of the variables as random
138   Real covariance(const Pecos::RealVector& x, Approximation& approx_2);
139   /// return the covariance between two combined response expansions,
140   /// where all active variables are random
141   Real combined_covariance(Approximation& approx_2);
142   /// return the covariance between two combined response expansions,
143   /// where a subset of the active variables are random
144   Real combined_covariance(const Pecos::RealVector& x,
145 			   Approximation& approx_2);
146 
147   /// return the reliability index (mapped from z_bar), where all active
148   /// variables are random
149   Real beta(bool cdf_flag, Real z_bar);
150   /// return the reliability index (mapped from z_bar), treating a subset of
151   /// variables as random
152   Real beta(const RealVector& x, bool cdf_flag, Real z_bar);
153   /// return the reliability index (mapped from z_bar), where all active
154   /// variables are random
155   Real combined_beta(bool cdf_flag, Real z_bar);
156   /// return the reliability index (mapped from z_bar), treating a subset of
157   /// variables as random
158   Real combined_beta(const RealVector& x, bool cdf_flag, Real z_bar);
159 
160   /// return the change in mean resulting from expansion refinement,
161   /// where all active variables are random
162   Real delta_mean();
163   /// return the change in mean resulting from expansion refinement,
164   /// treating a subset of variables as random
165   Real delta_mean(const RealVector& x);
166   /// return the change in mean resulting from combined expansion refinement,
167   /// where all active variables are random
168   Real delta_combined_mean();
169   /// return the change in mean resulting from combined expansion refinement,
170   /// treating a subset of variables as random
171   Real delta_combined_mean(const RealVector& x);
172 
173   /// return the change in standard deviation resulting from expansion
174   /// refinement, where all active variables are random
175   Real delta_std_deviation();
176   /// return the change in standard deviation resulting from expansion
177   /// refinement, treating a subset of variables as random
178   Real delta_std_deviation(const RealVector& x);
179   /// return the change in standard deviation resulting from combined
180   /// expansion refinement, where all active variables are random
181   Real delta_combined_std_deviation();
182   /// return the change in standard deviation resulting from combined
183   /// expansion refinement, treating a subset of variables as random
184   Real delta_combined_std_deviation(const RealVector& x);
185 
186   /// return the change in variance resulting from expansion
187   /// refinement, where all active variables are random
188   Real delta_variance();
189   /// return the change in variance resulting from expansion
190   /// refinement, treating a subset of variables as random
191   Real delta_variance(const RealVector& x);
192   /// return the change in variance resulting from combined
193   /// expansion refinement, where all active variables are random
194   Real delta_combined_variance();
195   /// return the change in variance resulting from combined
196   /// expansion refinement, treating a subset of variables as random
197   Real delta_combined_variance(const RealVector& x);
198 
199   /// return the change in covariance resulting from expansion refinement,
200   /// where all active variables are random
201   Real delta_covariance(Approximation& approx_2);
202   /// return the change in covariance resulting from expansion refinement,
203   /// where a subset of the active variables are random
204   Real delta_covariance(const Pecos::RealVector& x, Approximation& approx_2);
205   /// return the change in covariance resulting from expansion refinement,
206   /// where all active variables are random
207   Real delta_combined_covariance(Approximation& approx_2);
208   /// return the change in covariance resulting from expansion refinement,
209   /// where a subset of the active variables are random
210   Real delta_combined_covariance(const Pecos::RealVector& x,
211 				 Approximation& approx_2);
212 
213   /// return the change in reliability index (mapped from z_bar) resulting
214   /// from expansion refinement, where all active variables are random
215   Real delta_beta(bool cdf_flag, Real z_bar);
216   /// return the change in reliability index (mapped from z_bar) resulting
217   /// from expansion refinement, treating a subset of variables as random
218   Real delta_beta(const RealVector& x, bool cdf_flag, Real z_bar);
219   /// return the change in reliability index (mapped from z_bar) resulting
220   /// from expansion refinement, where all active variables are random
221   Real delta_combined_beta(bool cdf_flag, Real z_bar);
222   /// return the change in reliability index (mapped from z_bar) resulting
223   /// from expansion refinement, treating a subset of variables as random
224   Real delta_combined_beta(const RealVector& x, bool cdf_flag, Real z_bar);
225 
226   /// return the change in response level (mapped from beta_bar) resulting
227   /// from expansion refinement, where all active variables are random
228   Real delta_z(bool cdf_flag, Real beta_bar);
229   /// return the change in response level (mapped from beta_bar) resulting from
230   /// expansion refinement, where a subset of the active variables are random
231   Real delta_z(const RealVector& x, bool cdf_flag, Real beta_bar);
232   /// return the change in response level (mapped from beta_bar) resulting
233   /// from expansion refinement, where all active variables are random
234   Real delta_combined_z(bool cdf_flag, Real beta_bar);
235   /// return the change in response level (mapped from beta_bar) resulting from
236   /// expansion refinement, where a subset of the active variables are random
237   Real delta_combined_z(const RealVector& x, bool cdf_flag, Real beta_bar);
238 
239   /// compute moments up to the order supported by the Pecos
240   /// polynomial approximation
241   void compute_moments(bool full_stats = true, bool combined_stats = false);
242   /// compute moments in all-variables mode up to the order supported
243   /// by the Pecos polynomial approximation
244   void compute_moments(const Pecos::RealVector& x, bool full_stats = true,
245 		       bool combined_stats = false);
246 
247   /// return primary moments using Pecos::PolynomialApproximation::moments()
248   const RealVector& moments() const;
249   /// return expansion moments from Pecos::PolynomialApproximation
250   const RealVector& expansion_moments() const;
251   /// return numerical moments from Pecos::PolynomialApproximation
252   const RealVector& numerical_integration_moments() const;
253   /// return combined moments from multilevel-muktifidelity expansion roll-up
254   const RealVector& combined_moments() const;
255 
256   /// return primary moment using Pecos::PolynomialApproximation::moment(i)
257   Real moment(size_t i) const;
258   /// set primary moment using Pecos::PolynomialApproximation::moment(i)
259   void moment(Real mom, size_t i);
260   /// return Pecos::PolynomialApproximation::combinedMoments[i]
261   Real combined_moment(size_t i) const;
262   /// set Pecos::PolynomialApproximation::combinedMoments[i]
263   void combined_moment(Real mom, size_t i);
264 
265   /// clear tracking of computed moments, due to a change that invalidates
266   /// previous results
267   void clear_computed_bits();
268 
269   /// construct the Vandermonde matrix "A" for PCE regression for Ax = b
270   void build_linear_system(RealMatrix& A, const UShort2DArray& multi_index);
271   // add chain (allSamples): A size = num current+num chain by P,
272   // with current pts as 1st rows
273   void augment_linear_system(const RealVectorArray& samples, RealMatrix& A,
274 			     const UShort2DArray& multi_index);
275 
276   /// return pecosBasisApprox
277   Pecos::BasisApproximation& pecos_basis_approximation();
278 
279 protected:
280 
281   //
282   //- Heading: Virtual function redefinitions
283   //
284 
285   // redocumenting these since they use Pecos:: qualification
286 
287   /// retrieve the approximate function value for a given parameter vector
288   Real                        value(const Variables& vars);
289   /// retrieve the approximate function gradient for a given parameter vector
290   const Pecos::RealVector&    gradient(const Variables& vars);
291   /// retrieve the approximate function Hessian for a given parameter vector
292   const Pecos::RealSymMatrix& hessian(const Variables& vars);
293 
294   int min_coefficients() const;
295   //int num_constraints() const; // use default implementation
296 
297   void build();
298   void rebuild();
299   void pop_coefficients(bool save_data);
300   void push_coefficients();
301   void finalize_coefficients();
302   void combine_coefficients();
303   void combined_to_active_coefficients(bool clear_combined = true);
304   void clear_inactive_coefficients();
305 
306   void print_coefficients(std::ostream& s, bool normalized);
307 
308   /// return expansion coefficients in a form consistent with the
309   /// shared multi-index
310   RealVector approximation_coefficients(bool normalized) const;
311   /// set expansion coefficients in a form consistent with the shared
312   /// multi-index
313   void approximation_coefficients(const RealVector& approx_coeffs,
314 				  bool normalized);
315 
316   //void link_multilevel_surrogate_data();
317 
318   void coefficient_labels(std::vector<std::string>& coeff_labels) const;
319 
320   //
321   //- Heading: Data
322   //
323 
324 private:
325 
326   //
327   //- Heading: Convenience member functions
328   //
329 
330   /// utility to convert Dakota type string to Pecos type enumeration
331   void approx_type_to_basis_type(const String& approx_type, short& basis_type);
332 
333   //
334   //- Heading: Data
335   //
336 
337   /// the Pecos basis approximation, encompassing orthogonal and interpolation
338   /// polynomial approximations
339   Pecos::BasisApproximation pecosBasisApprox;
340   /// convenience pointer to representation of Pecos polynomial approximation
341   std::shared_ptr<Pecos::PolynomialApproximation> polyApproxRep;
342 
343   // convenience pointer to shared data representation
344   //SharedPecosApproxData* sharedPecosDataRep;
345 };
346 
347 
PecosApproximation()348 inline PecosApproximation::PecosApproximation()
349 { }
350 
351 
~PecosApproximation()352 inline PecosApproximation::~PecosApproximation()
353 { }
354 
355 
expansion_coefficient_flag(bool coeff_flag)356 inline void PecosApproximation::expansion_coefficient_flag(bool coeff_flag)
357 { polyApproxRep->expansion_coefficient_flag(coeff_flag); }
358 
359 
expansion_coefficient_flag() const360 inline bool PecosApproximation::expansion_coefficient_flag() const
361 { return polyApproxRep->expansion_coefficient_flag(); }
362 
363 
expansion_gradient_flag(bool grad_flag)364 inline void PecosApproximation::expansion_gradient_flag(bool grad_flag)
365 { polyApproxRep->expansion_coefficient_gradient_flag(grad_flag); }
366 
367 
expansion_gradient_flag() const368 inline bool PecosApproximation::expansion_gradient_flag() const
369 { return polyApproxRep->expansion_coefficient_gradient_flag(); }
370 
371 
clear_component_effects()372 inline void PecosApproximation::clear_component_effects()
373 { polyApproxRep->clear_component_sobol(); }
374 
375 
compute_component_effects()376 inline void PecosApproximation::compute_component_effects()
377 { polyApproxRep->compute_component_sobol(); }
378 
379 
compute_total_effects()380 inline void PecosApproximation::compute_total_effects()
381 { polyApproxRep->compute_total_sobol(); }
382 
383 
sobol_indices() const384 inline const Pecos::RealVector& PecosApproximation::sobol_indices() const
385 { return polyApproxRep->sobol_indices(); }
386 
387 
total_sobol_indices() const388 inline const Pecos::RealVector& PecosApproximation::total_sobol_indices() const
389 { return polyApproxRep->total_sobol_indices(); }
390 
391 
sparsity() const392 inline size_t PecosApproximation::sparsity() const
393 { return polyApproxRep->expansion_terms(); }
394 
395 
sparse_sobol_index_map() const396 inline Pecos::ULongULongMap PecosApproximation::sparse_sobol_index_map() const
397 { return polyApproxRep->sparse_sobol_index_map(); }
398 
399 
400 inline const Pecos::RealVector& PecosApproximation::
dimension_decay_rates() const401 dimension_decay_rates() const
402 {
403   return std::static_pointer_cast<Pecos::OrthogPolyApproximation>
404     (polyApproxRep)->dimension_decay_rates();
405 }
406 
407 
allocate_arrays()408 inline void PecosApproximation::allocate_arrays()
409 { polyApproxRep->allocate_arrays(); }
410 
411 
initialize_covariance(Approximation & approx_2)412 inline void PecosApproximation::initialize_covariance(Approximation& approx_2)
413 {
414   std::shared_ptr<PecosApproximation> pa_2 =
415     std::static_pointer_cast<PecosApproximation>(approx_2.approx_rep());
416   polyApproxRep->initialize_covariance(pa_2->polyApproxRep.get());
417 }
418 
419 
clear_covariance_pointers()420 inline void PecosApproximation::clear_covariance_pointers()
421 { polyApproxRep->clear_covariance_pointers(); }
422 
423 
initialize_products()424 inline void PecosApproximation::initialize_products()
425 { polyApproxRep->initialize_products(); }
426 
427 
product_interpolants()428 inline bool PecosApproximation::product_interpolants()
429 { return polyApproxRep->product_interpolants(); }
430 
431 
mean()432 inline Real PecosApproximation::mean()
433 { return polyApproxRep->mean(); }
434 
435 
mean(const Pecos::RealVector & x)436 inline Real PecosApproximation::mean(const Pecos::RealVector& x)
437 { return polyApproxRep->mean(x); }
438 
439 
combined_mean()440 inline Real PecosApproximation::combined_mean()
441 { return polyApproxRep->combined_mean(); }
442 
443 
combined_mean(const Pecos::RealVector & x)444 inline Real PecosApproximation::combined_mean(const Pecos::RealVector& x)
445 { return polyApproxRep->combined_mean(x); }
446 
447 
mean_gradient()448 inline const Pecos::RealVector& PecosApproximation::mean_gradient()
449 { return polyApproxRep->mean_gradient(); }
450 
451 
452 inline const Pecos::RealVector& PecosApproximation::
mean_gradient(const Pecos::RealVector & x,const Pecos::SizetArray & dvv)453 mean_gradient(const Pecos::RealVector& x, const Pecos::SizetArray& dvv)
454 { return polyApproxRep->mean_gradient(x, dvv); }
455 
456 
variance()457 inline Real PecosApproximation::variance()
458 { return polyApproxRep->variance(); }
459 
460 
variance(const Pecos::RealVector & x)461 inline Real PecosApproximation::variance(const Pecos::RealVector& x)
462 { return polyApproxRep->variance(x); }
463 
464 
variance_gradient()465 inline const Pecos::RealVector& PecosApproximation::variance_gradient()
466 { return polyApproxRep->variance_gradient(); }
467 
468 
469 inline const Pecos::RealVector& PecosApproximation::
variance_gradient(const Pecos::RealVector & x,const Pecos::SizetArray & dvv)470 variance_gradient(const Pecos::RealVector& x, const Pecos::SizetArray& dvv)
471 { return polyApproxRep->variance_gradient(x, dvv); }
472 
473 
covariance(Approximation & approx_2)474 inline Real PecosApproximation::covariance(Approximation& approx_2)
475 {
476   std::shared_ptr<PecosApproximation> pa_2 =
477     std::static_pointer_cast<PecosApproximation>(approx_2.approx_rep());
478   return polyApproxRep->covariance(pa_2->polyApproxRep.get());
479 }
480 
481 
482 inline Real PecosApproximation::
covariance(const Pecos::RealVector & x,Approximation & approx_2)483 covariance(const Pecos::RealVector& x, Approximation& approx_2)
484 {
485   std::shared_ptr<PecosApproximation> pa_2 =
486     std::static_pointer_cast<PecosApproximation>(approx_2.approx_rep());
487   return polyApproxRep->covariance(x, pa_2->polyApproxRep.get());
488 }
489 
490 
combined_covariance(Approximation & approx_2)491 inline Real PecosApproximation::combined_covariance(Approximation& approx_2)
492 {
493   std::shared_ptr<PecosApproximation> pa_2 =
494     std::static_pointer_cast<PecosApproximation>(approx_2.approx_rep());
495   return polyApproxRep->combined_covariance(pa_2->polyApproxRep.get());
496 }
497 
498 
499 inline Real PecosApproximation::
combined_covariance(const Pecos::RealVector & x,Approximation & approx_2)500 combined_covariance(const Pecos::RealVector& x, Approximation& approx_2)
501 {
502   std::shared_ptr<PecosApproximation> pa_2 =
503     std::static_pointer_cast<PecosApproximation>(approx_2.approx_rep());
504   return polyApproxRep->combined_covariance(x, pa_2->polyApproxRep.get());
505 }
506 
507 
beta(bool cdf_flag,Real z_bar)508 inline Real PecosApproximation::beta(bool cdf_flag, Real z_bar)
509 { return polyApproxRep->beta(cdf_flag, z_bar); }
510 
511 
512 inline Real PecosApproximation::
beta(const RealVector & x,bool cdf_flag,Real z_bar)513 beta(const RealVector& x, bool cdf_flag, Real z_bar)
514 { return polyApproxRep->beta(x, cdf_flag, z_bar); }
515 
516 
combined_beta(bool cdf_flag,Real z_bar)517 inline Real PecosApproximation::combined_beta(bool cdf_flag, Real z_bar)
518 { return polyApproxRep->combined_beta(cdf_flag, z_bar); }
519 
520 
521 inline Real PecosApproximation::
combined_beta(const RealVector & x,bool cdf_flag,Real z_bar)522 combined_beta(const RealVector& x, bool cdf_flag, Real z_bar)
523 { return polyApproxRep->combined_beta(x, cdf_flag, z_bar); }
524 
525 
delta_mean()526 inline Real PecosApproximation::delta_mean()
527 { return polyApproxRep->delta_mean(); }
528 
529 
delta_mean(const RealVector & x)530 inline Real PecosApproximation::delta_mean(const RealVector& x)
531 { return polyApproxRep->delta_mean(x); }
532 
533 
delta_combined_mean()534 inline Real PecosApproximation::delta_combined_mean()
535 { return polyApproxRep->delta_combined_mean(); }
536 
537 
delta_combined_mean(const RealVector & x)538 inline Real PecosApproximation::delta_combined_mean(const RealVector& x)
539 { return polyApproxRep->delta_combined_mean(x); }
540 
541 
delta_std_deviation()542 inline Real PecosApproximation::delta_std_deviation()
543 { return polyApproxRep->delta_std_deviation(); }
544 
545 
delta_std_deviation(const RealVector & x)546 inline Real PecosApproximation::delta_std_deviation(const RealVector& x)
547 { return polyApproxRep->delta_std_deviation(x); }
548 
549 
delta_combined_std_deviation()550 inline Real PecosApproximation::delta_combined_std_deviation()
551 { return polyApproxRep->delta_combined_std_deviation(); }
552 
553 
554 inline Real PecosApproximation::
delta_combined_std_deviation(const RealVector & x)555 delta_combined_std_deviation(const RealVector& x)
556 { return polyApproxRep->delta_combined_std_deviation(x); }
557 
558 
delta_variance()559 inline Real PecosApproximation::delta_variance()
560 { return polyApproxRep->delta_variance(); }
561 
562 
delta_variance(const RealVector & x)563 inline Real PecosApproximation::delta_variance(const RealVector& x)
564 { return polyApproxRep->delta_variance(x); }
565 
566 
delta_combined_variance()567 inline Real PecosApproximation::delta_combined_variance()
568 { return polyApproxRep->delta_combined_variance(); }
569 
570 
delta_combined_variance(const RealVector & x)571 inline Real PecosApproximation::delta_combined_variance(const RealVector& x)
572 { return polyApproxRep->delta_combined_variance(x); }
573 
574 
delta_covariance(Approximation & approx_2)575 inline Real PecosApproximation::delta_covariance(Approximation& approx_2)
576 {
577   std::shared_ptr<PecosApproximation> pa_2 =
578     std::static_pointer_cast<PecosApproximation>(approx_2.approx_rep());
579   return polyApproxRep->delta_covariance(pa_2->polyApproxRep.get());
580 }
581 
582 
583 inline Real PecosApproximation::
delta_covariance(const Pecos::RealVector & x,Approximation & approx_2)584 delta_covariance(const Pecos::RealVector& x, Approximation& approx_2)
585 {
586   std::shared_ptr<PecosApproximation> pa_2 =
587     std::static_pointer_cast<PecosApproximation>(approx_2.approx_rep());
588   return polyApproxRep->delta_covariance(x, pa_2->polyApproxRep.get());
589 }
590 
591 
592 inline Real PecosApproximation::
delta_combined_covariance(Approximation & approx_2)593 delta_combined_covariance(Approximation& approx_2)
594 {
595 std::shared_ptr<PecosApproximation> pa_2 =
596     std::static_pointer_cast<PecosApproximation>(approx_2.approx_rep());
597  return polyApproxRep->delta_combined_covariance(pa_2->polyApproxRep.get());
598 }
599 
600 
601 inline Real PecosApproximation::
delta_combined_covariance(const Pecos::RealVector & x,Approximation & approx_2)602 delta_combined_covariance(const Pecos::RealVector& x, Approximation& approx_2)
603 {
604   std::shared_ptr<PecosApproximation> pa_2 =
605     std::static_pointer_cast<PecosApproximation>(approx_2.approx_rep());
606   return polyApproxRep->delta_combined_covariance(x, pa_2->polyApproxRep.get());
607 }
608 
609 
delta_beta(bool cdf_flag,Real z_bar)610 inline Real PecosApproximation::delta_beta(bool cdf_flag, Real z_bar)
611 { return polyApproxRep->delta_beta(cdf_flag, z_bar); }
612 
613 
614 inline Real PecosApproximation::
delta_beta(const RealVector & x,bool cdf_flag,Real z_bar)615 delta_beta(const RealVector& x, bool cdf_flag, Real z_bar)
616 { return polyApproxRep->delta_beta(x, cdf_flag, z_bar); }
617 
618 
delta_combined_beta(bool cdf_flag,Real z_bar)619 inline Real PecosApproximation::delta_combined_beta(bool cdf_flag, Real z_bar)
620 { return polyApproxRep->delta_combined_beta(cdf_flag, z_bar); }
621 
622 
623 inline Real PecosApproximation::
delta_combined_beta(const RealVector & x,bool cdf_flag,Real z_bar)624 delta_combined_beta(const RealVector& x, bool cdf_flag, Real z_bar)
625 { return polyApproxRep->delta_combined_beta(x, cdf_flag, z_bar); }
626 
627 
delta_z(bool cdf_flag,Real beta_bar)628 inline Real PecosApproximation::delta_z(bool cdf_flag, Real beta_bar)
629 { return polyApproxRep->delta_z(cdf_flag, beta_bar); }
630 
631 
632 inline Real PecosApproximation::
delta_z(const RealVector & x,bool cdf_flag,Real beta_bar)633 delta_z(const RealVector& x, bool cdf_flag, Real beta_bar)
634 { return polyApproxRep->delta_z(x, cdf_flag, beta_bar); }
635 
636 
delta_combined_z(bool cdf_flag,Real beta_bar)637 inline Real PecosApproximation::delta_combined_z(bool cdf_flag, Real beta_bar)
638 { return polyApproxRep->delta_combined_z(cdf_flag, beta_bar); }
639 
640 
641 inline Real PecosApproximation::
delta_combined_z(const RealVector & x,bool cdf_flag,Real beta_bar)642 delta_combined_z(const RealVector& x, bool cdf_flag, Real beta_bar)
643 { return polyApproxRep->delta_combined_z(x, cdf_flag, beta_bar); }
644 
645 
646 inline void PecosApproximation::
compute_moments(bool full_stats,bool combined_stats)647 compute_moments(bool full_stats, bool combined_stats )
648 { polyApproxRep->compute_moments(full_stats, combined_stats); }
649 
650 
651 inline void PecosApproximation::
compute_moments(const Pecos::RealVector & x,bool full_stats,bool combined_stats)652 compute_moments(const Pecos::RealVector& x, bool full_stats,
653 		bool combined_stats)
654 { polyApproxRep->compute_moments(x, full_stats, combined_stats); }
655 
656 
moments() const657 inline const RealVector& PecosApproximation::moments() const
658 { return polyApproxRep->moments(); }
659 
660 
expansion_moments() const661 inline const RealVector& PecosApproximation::expansion_moments() const
662 { return polyApproxRep->expansion_moments(); }
663 
664 
665 inline const RealVector& PecosApproximation::
numerical_integration_moments() const666 numerical_integration_moments() const
667 { return polyApproxRep->numerical_integration_moments(); }
668 
669 
combined_moments() const670 inline const RealVector& PecosApproximation::combined_moments() const
671 { return polyApproxRep->combined_moments(); }
672 
673 
moment(size_t i) const674 inline Real PecosApproximation::moment(size_t i) const
675 { return polyApproxRep->moment(i); }
676 
677 
moment(Real mom,size_t i)678 inline void PecosApproximation::moment(Real mom, size_t i)
679 { polyApproxRep->moment(mom, i); }
680 
681 
combined_moment(size_t i) const682 inline Real PecosApproximation::combined_moment(size_t i) const
683 { return polyApproxRep->combined_moment(i); }
684 
685 
combined_moment(Real mom,size_t i)686 inline void PecosApproximation::combined_moment(Real mom, size_t i)
687 { polyApproxRep->combined_moment(mom, i); }
688 
689 
690 inline void PecosApproximation::
build_linear_system(RealMatrix & A,const UShort2DArray & multi_index)691 build_linear_system(RealMatrix& A, const UShort2DArray& multi_index)
692 {
693   std::static_pointer_cast<Pecos::RegressOrthogPolyApproximation>
694     (polyApproxRep)->build_linear_system(A, multi_index);
695 }
696 
697 
698 inline void PecosApproximation::
augment_linear_system(const RealVectorArray & samples,RealMatrix & A,const UShort2DArray & multi_index)699 augment_linear_system(const RealVectorArray& samples, RealMatrix& A,
700 		      const UShort2DArray& multi_index)
701 {
702   std::static_pointer_cast<Pecos::RegressOrthogPolyApproximation>
703     (polyApproxRep)->augment_linear_system(samples, A, multi_index);
704 }
705 
706 
707 inline Pecos::BasisApproximation& PecosApproximation::
pecos_basis_approximation()708 pecos_basis_approximation()
709 { return pecosBasisApprox; }
710 
711 
712 // ignore discrete variables for now
value(const Variables & vars)713 inline Real PecosApproximation::value(const Variables& vars)
714 { return pecosBasisApprox.value(vars.continuous_variables()); }
715 
716 
717 // ignore discrete variables for now
718 inline const Pecos::RealVector& PecosApproximation::
gradient(const Variables & vars)719 gradient(const Variables& vars)
720 {
721   //return pecosBasisApprox.gradient(x); // bypass this layer
722   return polyApproxRep->gradient_basis_variables(vars.continuous_variables());
723 }
724 
725 
726 // ignore discrete variables for now
727 inline const Pecos::RealSymMatrix& PecosApproximation::
hessian(const Variables & vars)728 hessian(const Variables& vars)
729 {
730   //return pecosBasisApprox.hessian(vars.continuous_variables()); // bypass
731   return polyApproxRep->hessian_basis_variables(vars.continuous_variables());
732 }
733 
734 
min_coefficients() const735 inline int PecosApproximation::min_coefficients() const
736 { return pecosBasisApprox.min_coefficients(); }
737 
738 
build()739 inline void PecosApproximation::build()
740 {
741   // base class implementation checks data set against min required
742   Approximation::build();
743 
744   // map to Pecos::BasisApproximation
745   pecosBasisApprox.compute_coefficients();
746 }
747 
748 
rebuild()749 inline void PecosApproximation::rebuild()
750 {
751   // TO DO: increment_coefficients() below covers current usage of
752   // append_approximation() in NonDExpansion.  For more general
753   // support of both update and append, need a mechanism to detect
754   // the +/- direction of discrepancy between data and coefficients.
755 
756   //size_t curr_pts  = data_rep->surrogate_data().points(),
757   //  curr_pecos_pts = polyApproxRep->data_size();
758   //if (curr_pts > curr_pecos_pts)
759     pecosBasisApprox.increment_coefficients();
760   //else if (curr_pts < curr_pecos_pts)
761   //  pecosBasisApprox.pop_coefficients();
762   //else: if number of points is consistent, leave as is
763 }
764 
765 
pop_coefficients(bool save_data)766 inline void PecosApproximation::pop_coefficients(bool save_data)
767 { pecosBasisApprox.pop_coefficients(save_data); }
768 
769 
push_coefficients()770 inline void PecosApproximation::push_coefficients()
771 { pecosBasisApprox.push_coefficients(); }
772 
773 
finalize_coefficients()774 inline void PecosApproximation::finalize_coefficients()
775 { pecosBasisApprox.finalize_coefficients(); }
776 
777 
combine_coefficients()778 inline void PecosApproximation::combine_coefficients()
779 { pecosBasisApprox.combine_coefficients(); }
780 
781 
782 inline void PecosApproximation::
combined_to_active_coefficients(bool clear_combined)783 combined_to_active_coefficients(bool clear_combined)
784 { pecosBasisApprox.combined_to_active(clear_combined); }
785 
786 
clear_computed_bits()787 inline void PecosApproximation::clear_computed_bits()
788 { polyApproxRep->clear_computed_bits(); }
789 
790 
clear_inactive_coefficients()791 inline void PecosApproximation::clear_inactive_coefficients()
792 { pecosBasisApprox.clear_inactive(); }
793 
794 
795 inline void PecosApproximation::
print_coefficients(std::ostream & s,bool normalized)796 print_coefficients(std::ostream& s, bool normalized)
797 { pecosBasisApprox.print_coefficients(s, normalized); }
798 
799 
800 inline RealVector PecosApproximation::
approximation_coefficients(bool normalized) const801 approximation_coefficients(bool normalized) const
802 { return pecosBasisApprox.approximation_coefficients(normalized); }
803 
804 
805 inline void PecosApproximation::
approximation_coefficients(const RealVector & approx_coeffs,bool normalized)806 approximation_coefficients(const RealVector& approx_coeffs, bool normalized)
807 { pecosBasisApprox.approximation_coefficients(approx_coeffs, normalized); }
808 
809 
810 inline void PecosApproximation::
coefficient_labels(std::vector<std::string> & coeff_labels) const811 coefficient_labels(std::vector<std::string>& coeff_labels) const
812 { polyApproxRep->coefficient_labels(coeff_labels); }
813 
814 } // namespace Dakota
815 
816 #endif
817