MUQ  0.4.3
SumPiece.cpp
Go to the documentation of this file.
2 
3 using namespace muq::Modeling;
4 
5 
6 
7 SumPiece::SumPiece(unsigned int dim, unsigned int numInputs) : ModPiece(dim*Eigen::VectorXi::Ones(numInputs),
8  dim*Eigen::VectorXi::Ones(1))
9 {
10  assert(numInputs>1);
11 }
12 
13 
14 
16 {
17  outputs.resize(1);
18  outputs.at(0) = input.at(0).get();
19 
20  for(unsigned int i=1; i<input.size(); ++i)
21  outputs.at(0) += input.at(i).get();
22 }
23 
24 
25 void SumPiece::GradientImpl(unsigned int const outputDimWrt,
26  unsigned int const inputDimWrt,
27  ref_vector<Eigen::VectorXd> const& input,
28  Eigen::VectorXd const& sensitivity)
29 {
30  gradient = sensitivity;
31 }
32 
33 void SumPiece::JacobianImpl(unsigned int const outputDimWrt,
34  unsigned int const inputDimWrt,
35  ref_vector<Eigen::VectorXd> const& input)
36 {
37  jacobian = Eigen::MatrixXd::Identity(inputSizes(inputDimWrt),inputSizes(inputDimWrt));
38 }
39 
40 void SumPiece::ApplyJacobianImpl(unsigned int const outputDimWrt,
41  unsigned int const inputDimWrt,
42  ref_vector<Eigen::VectorXd> const& input,
43  Eigen::VectorXd const& vec)
44 {
45  jacobianAction = vec;
46 }
47 
48 void SumPiece::ApplyHessianImpl(unsigned int const outWrt,
49  unsigned int const inWrt1,
50  unsigned int const inWrt2,
51  ref_vector<Eigen::VectorXd> const& input,
52  Eigen::VectorXd const& sens,
53  Eigen::VectorXd const& vec)
54 {
55  hessAction = Eigen::VectorXd::Zero(vec.size());
56 }
Provides an abstract interface for defining vector-valued model components.
Definition: ModPiece.h:148
Eigen::MatrixXd jacobian
Definition: ModPiece.h:506
const Eigen::VectorXi inputSizes
Definition: ModPiece.h:469
std::vector< Eigen::VectorXd > outputs
Definition: ModPiece.h:503
Eigen::VectorXd gradient
Definition: ModPiece.h:504
Eigen::VectorXd hessAction
Definition: ModPiece.h:507
Eigen::VectorXd jacobianAction
Definition: ModPiece.h:505
virtual void GradientImpl(unsigned int const outputDimWrt, unsigned int const inputDimWrt, ref_vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &sensitivity) override
Definition: SumPiece.cpp:25
virtual void ApplyJacobianImpl(unsigned int const outputDimWrt, unsigned int const inputDimWrt, ref_vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &vec) override
Definition: SumPiece.cpp:40
SumPiece(unsigned int dim, unsigned int numInputs=2)
Definition: SumPiece.cpp:7
virtual void ApplyHessianImpl(unsigned int const outWrt, unsigned int const inWrt1, unsigned int const inWrt2, ref_vector< Eigen::VectorXd > const &input, Eigen::VectorXd const &sens, Eigen::VectorXd const &vec) override
Definition: SumPiece.cpp:48
virtual void EvaluateImpl(ref_vector< Eigen::VectorXd > const &input) override
Definition: SumPiece.cpp:15
virtual void JacobianImpl(unsigned int const outputDimWrt, unsigned int const inputDimWrt, ref_vector< Eigen::VectorXd > const &input) override
Definition: SumPiece.cpp:33
int numInputs
The number of inputs.
Definition: WorkPiece.h:501
std::vector< std::reference_wrapper< const T > > ref_vector
A vector of references to something ...
Definition: WorkPiece.h:37