| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// Rapid Optimization Library (ROL) Package |
| 4 |
// |
| 5 |
// Copyright 2014 NTESS and the ROL contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#ifndef ROL_OED_FACTORS_HPP |
| 11 |
#define ROL_OED_FACTORS_HPP |
| 12 |
|
| 13 |
#include "ROL_Ptr.hpp" |
| 14 |
#include "ROL_SampleGenerator.hpp" |
| 15 |
#include "ROL_SampledVector.hpp" |
| 16 |
#include "ROL_SingletonVector.hpp" |
| 17 |
#include "ROL_ConstraintFromObjective.hpp" |
| 18 |
#include "ROL_Types.hpp" |
| 19 |
#include "ROL_OED_ProfiledClass.hpp" |
| 20 |
#include <vector> |
| 21 |
|
| 22 |
namespace ROL { |
| 23 |
namespace OED { |
| 24 |
|
| 25 |
template<typename Real> |
| 26 |
class Factors : public ProfiledClass<Real,std::string> { |
| 27 |
protected: |
| 28 |
const Ptr<Constraint<Real>> model_; |
| 29 |
const Ptr<Vector<Real>> theta_; |
| 30 |
const Ptr<Vector<Real>> obs_; |
| 31 |
const Ptr<Vector<Real>> obs0_; |
| 32 |
const Ptr<Vector<Real>> c_; |
| 33 |
const Ptr<SampleGenerator<Real>> sampler_; |
| 34 |
const bool storage_; |
| 35 |
const bool obs1d_; |
| 36 |
std::vector<Ptr<Vector<Real>>> X_; |
| 37 |
Ptr<SampledVector<Real>> g_storage_; |
| 38 |
|
| 39 |
using ProfiledClass<Real,std::string>::startTimer; |
| 40 |
using ProfiledClass<Real,std::string>::stopTimer; |
| 41 |
|
| 42 |
void evaluateModel(Vector<Real> &g, const std::vector<Real> ¶m) const; |
| 43 |
void setFactors(); |
| 44 |
|
| 45 |
public: |
| 46 |
Factors(const Ptr<Constraint<Real>> &model, |
| 47 |
const Ptr<Vector<Real>> &theta, |
| 48 |
const Ptr<Vector<Real>> &obs, |
| 49 |
const Ptr<SampleGenerator<Real>> &sampler, |
| 50 |
bool storage = true, |
| 51 |
const Ptr<Vector<Real>> &c = nullPtr); |
| 52 |
Factors(const Ptr<Objective<Real>> &model, |
| 53 |
const Ptr<Vector<Real>> &theta, |
| 54 |
const Ptr<SampleGenerator<Real>> &sampler, |
| 55 |
bool storage = true); |
| 56 |
|
| 57 |
void setPredictionVector(const Vector<Real> &c); |
| 58 |
void getPredictionVector(Vector<Real> &c) const; |
| 59 |
|
| 60 |
// Create a vector in the parameter space |
| 61 |
Ptr<Vector<Real>> createParameterVector(bool dual=false) const; |
| 62 |
|
| 63 |
// Create a vector in the observation space |
| 64 |
Ptr<Vector<Real>> createObservationVector(bool dual=false) const; |
| 65 |
|
| 66 |
// Compute c^T F[k] x |
| 67 |
Real apply(const Vector<Real> &x, int k) const; |
| 68 |
|
| 69 |
// Compute Fx = F[k] x |
| 70 |
void apply(Vector<Real> &Fx, const Vector<Real> &x, int k) const; |
| 71 |
|
| 72 |
// Compute Mx = F[k]^T R F[k] x |
| 73 |
void applyProduct(Vector<Real> &Mx, const Vector<Real> &x, int k) const; |
| 74 |
|
| 75 |
// Compute y^T F[k]^T R F[k] x |
| 76 |
Real applyProduct2(const Vector<Real> &x, const Vector<Real> &y, int k) const; |
| 77 |
|
| 78 |
// Get F[k]^T c |
| 79 |
const Ptr<const Vector<Real>> get(int k) const; |
| 80 |
|
| 81 |
// Compute F(param)^T c |
| 82 |
void evaluate(Vector<Real> &F, const std::vector<Real> ¶m) const; |
| 83 |
|
| 84 |
// void sumAll(Real *in, Real *out, int size) const; |
| 85 |
|
| 86 |
int numFactors() const; |
| 87 |
|
| 88 |
int numMySamples() const; |
| 89 |
|
| 90 |
std::vector<Real> getSample(int k) const; |
| 91 |
|
| 92 |
}; // class Factors |
| 93 |
|
| 94 |
} // End OED Namespace |
| 95 |
} // End ROL Namespace |
| 96 |
|
| 97 |
#include "ROL_OED_Factors_Def.hpp" |
| 98 |
|
| 99 |
#endif |